Fix de l'utilisation de la BDD, reste à revoir le fonctionnement du parrainage et des référents

pull/3/head
Clement FERRERE 3 years ago
parent 1071204c1b
commit 209760275b
  1. 6
      Collaborateur_Epa_Back/espacecollab.backend.api/Startup.cs
  2. 4
      Collaborateur_Epa_Back/espacecollab.backend.api/appsettings.json
  3. 20
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/MainDbContext.cs
  4. 5
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/GenericSqlRepository.cs
  5. 16
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/db/db_1_0_0.sql
  6. 8
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/espacecollab.backend.infrastructure.sql.csproj

@ -1,4 +1,5 @@
using espacecollab.backend.infrastructure.sql.Options; using espacecollab.backend.infrastructure.sql.Options;
using System.Text.Json.Serialization;
namespace espacecollab.backend.api namespace espacecollab.backend.api
{ {
@ -17,7 +18,10 @@ namespace espacecollab.backend.api
services.Configure<SqlOption>(sqlSection); services.Configure<SqlOption>(sqlSection);
SqlOption sqlOptions = sqlSection.Get<SqlOption>(); SqlOption sqlOptions = sqlSection.Get<SqlOption>();
services.AddControllers(); services.AddControllers().AddJsonOptions(opt =>
{
opt.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
}); ;
services.AddRouting(options => options.LowercaseUrls = true); services.AddRouting(options => options.LowercaseUrls = true);
services.AddEndpointsApiExplorer(); services.AddEndpointsApiExplorer();

@ -7,7 +7,7 @@
}, },
"AllowedHosts": "*", "AllowedHosts": "*",
"Sql": { "Sql": {
"LoadFake": true, "LoadFake": false,
"ConnectionString": "server=127.0.0.1;uid=root;pwd=root;database=collaborateur_epa" "ConnectionString": "server=localhost;user=root;password=root;database=collaborateur_epa"
} }
} }

@ -1,4 +1,5 @@
using espacecollab.backend.infrastructure.sql.Options; using espacecollab.backend.infrastructure.sql.dtos;
using espacecollab.backend.infrastructure.sql.Options;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
namespace espacecollab.backend.infrastructure.sql namespace espacecollab.backend.infrastructure.sql
@ -6,6 +7,7 @@ namespace espacecollab.backend.infrastructure.sql
public class MainDbContext : DbContext public class MainDbContext : DbContext
{ {
private IOptions<SqlOption> SqlSettings { get; } private IOptions<SqlOption> SqlSettings { get; }
private DbSet<CollaborateurSqlDto>? collaborateur { get; set; }
public MainDbContext(IOptions<SqlOption> sqlSettings) public MainDbContext(IOptions<SqlOption> sqlSettings)
{ {
@ -14,10 +16,20 @@ namespace espacecollab.backend.infrastructure.sql
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{ {
optionsBuilder.UseSqlServer(SqlSettings.Value.ConnectionString, builder => optionsBuilder.UseMySql(SqlSettings.Value.ConnectionString,
ServerVersion.AutoDetect(SqlSettings.Value.ConnectionString));
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{ {
builder.EnableRetryOnFailure(5, TimeSpan.FromSeconds(10), null); modelBuilder
}); .Entity<CollaborateurSqlDto>()
.Property(e => e.Gender)
.HasConversion<string>();
modelBuilder
.Entity<CollaborateurSqlDto>()
.Property(e => e.Status)
.HasConversion<string>();
} }
} }
} }

@ -14,7 +14,10 @@ namespace espacecollab.backend.infrastructure.sql.Repository
public virtual T? Add(T entity) public virtual T? Add(T entity)
{ {
return Context.Set<T>().Add(entity) as T; T? addedEntity = Context.Set<T>().Add(entity) as T;
Context.SaveChanges();
return addedEntity;
} }
public virtual bool Delete(int entityId) public virtual bool Delete(int entityId)

@ -59,15 +59,17 @@ CREATE TABLE IF NOT EXISTS Collaborateur(
Name varchar(100) NOT NULL, Name varchar(100) NOT NULL,
FirstName varchar(100) NOT NULL, FirstName varchar(100) NOT NULL,
BirthDate date NOT NULL, BirthDate date NOT NULL,
Gender ENUM('MASCULIN','FEMININ','AUTRE') NOT NULL, Gender ENUM('masculin','feminin','autre') NOT NULL DEFAULT 'masculin',
Status ENUM('CADRE','NONCADRE','ALTERNANT','STAGIAIRE') NOT NULL, Status ENUM('cadre','noncadre','alternant','stagiaire') NOT NULL DEFAULT 'noncadre',
ChildrenNumber smallint NOT NULL, ChildrenNumber smallint NOT NULL,
Address varchar(200) NOT NULL, Address varchar(200) NOT NULL,
Telephone varchar(15) NOT NULL, Telephone varchar(15) NOT NULL,
PersonalMail varchar(100) NOT NULL, PersonalMail varchar(100) NOT NULL,
ApsideMail varchar(100) NOT NULL, ApsideMail varchar(100) NOT NULL,
ResignationDate date NOT NULL, ResignationDate date,
ReferrerId int NOT NULL, BusinessUnitId int NOT NUll,
ReferrerId int,
CONSTRAINT FK_COLLABORATEUR_BUSINESSUNIT FOREIGN KEY (BusinessUnitId) REFERENCES BusinessUnit(Id),
CONSTRAINT FK_COLLABORATEUR_PARRAIN FOREIGN KEY (ReferrerId) REFERENCES Collaborateur(Id), CONSTRAINT FK_COLLABORATEUR_PARRAIN FOREIGN KEY (ReferrerId) REFERENCES Collaborateur(Id),
PRIMARY KEY (Id) PRIMARY KEY (Id)
); );
@ -151,3 +153,9 @@ CREATE TABLE IF NOT EXISTS CollaborateurCollaboreProjet(
CONSTRAINT FK_COLLABORATEUR_COLLABORE_PROJET FOREIGN KEY (CollaborateurId) REFERENCES Collaborateur(Id), CONSTRAINT FK_COLLABORATEUR_COLLABORE_PROJET FOREIGN KEY (CollaborateurId) REFERENCES Collaborateur(Id),
CONSTRAINT FK_PROJET_COLLABORE_COLLABORATEUR FOREIGN KEY (ProjetId) REFERENCES Projet(Id) CONSTRAINT FK_PROJET_COLLABORE_COLLABORATEUR FOREIGN KEY (ProjetId) REFERENCES Projet(Id)
); );
INSERT INTO Agence(Id, Name) VALUES (1,'Agence1');
INSERT INTO BusinessUnit(Id, Name, AgenceId) VALUES (1,'BusinessUnit1',1);
INSERT INTO Collaborateur(Id, Name, FirstName, BirthDate, Gender, Status, ChildrenNumber, Address, Telephone, PersonalMail,
ApsideMail, ResignationDate, BusinessUnitId, ReferrerId)
VALUES (1,'Collab1','Collab1','2000-30-08','masculin','cadre',0,'adresse','tel','pmail','amail',NULL,1,NULL);

@ -7,13 +7,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" /> <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MySql.EntityFrameworkCore" Version="5.0.8" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

Loading…
Cancel
Save