Merge pull request 'FixUtilisationBdd Merge into develop' (#3) from FixUtilisationBdd into develop

Reviewed-on: Clement.Ferrere/Collaborateur_Epa_Back#3
pull/7/head
Alexandre Ruiz 3 years ago
commit 09f21deee3
  1. 2
      Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/BaseController.cs
  2. 1
      Collaborateur_Epa_Back/espacecollab.backend.api/Register.cs
  3. 10
      Collaborateur_Epa_Back/espacecollab.backend.api/Startup.cs
  4. 4
      Collaborateur_Epa_Back/espacecollab.backend.api/appsettings.json
  5. 3
      Collaborateur_Epa_Back/espacecollab.backend.api/espacecollab.backend.api.csproj
  6. 4
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs
  7. 9
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/CollaborateurApiDtoMapper.cs
  8. 4
      Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs
  9. 2
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurSqlDto.cs
  10. 24
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/MainDbContext.cs
  11. 7
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/GenericSqlRepository.cs
  12. 16
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/db/db_1_0_0.sql
  13. 8
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/espacecollab.backend.infrastructure.sql.csproj

@ -51,7 +51,7 @@ namespace espacecollab.backend.api.Controllers
return Ok();
}
[HttpPut("{collaborateurId:int:min(1)}")]
[HttpPut("{id:int:min(1)}")]
public ActionResult<TO> Update(uint id, TO apiDto)
{
if (apiDto.Id != id)

@ -11,6 +11,7 @@ internal static class Register
{
public static void InjectDependencies(IServiceCollection services, SqlOption contextOptions)
{
services.AddCors();
services.AddScoped<CollaborateursServices>();
services.AddScoped<AgenceService>();

@ -1,4 +1,5 @@
using espacecollab.backend.infrastructure.sql.Options;
using System.Text.Json.Serialization;
namespace espacecollab.backend.api
{
@ -17,7 +18,10 @@ namespace espacecollab.backend.api
services.Configure<SqlOption>(sqlSection);
SqlOption sqlOptions = sqlSection.Get<SqlOption>();
services.AddControllers();
services.AddControllers().AddJsonOptions(opt =>
{
opt.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
}); ;
services.AddRouting(options => options.LowercaseUrls = true);
services.AddEndpointsApiExplorer();
@ -33,7 +37,9 @@ namespace espacecollab.backend.api
{
app.UseDeveloperExceptionPage();
}
app.UseCors(
options => options.WithOrigins("http://localhost:4200").AllowAnyMethod().AllowAnyHeader()
);
app.UseSwagger();
app.UseSwaggerUI();

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

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
@ -7,6 +7,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Cors" Version="2.2.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>

@ -2,8 +2,8 @@
namespace espacecollab.backend.appservices.dtos
{
public record CollaborateurApiDto(uint Id, string Name, string FirstName, DateTime BirthDate, EnumGenreApi Gender, EnumStatutApi Status, int ChildrenNumber, string Address,
string Telephone, string PersonalMail, string ApsideMail, DateTime ResignationDate, int ReferrerId, int BusinessUnitId) : IGenericIdApiDto
public record CollaborateurApiDto(uint Id, string Name, string FirstName, string BirthDate, EnumGenreApi Gender, EnumStatutApi Status, int ChildrenNumber, string Address,
string Telephone, string PersonalMail, string ApsideMail, string ResignationDate, int ReferrerId, int BusinessUnitId) : IGenericIdApiDto
{
public uint Id { get; set; } = Id;
}

@ -1,4 +1,5 @@
using espacecollab.backend.infrastructure.sql.dtos;
using System.Globalization;
namespace espacecollab.backend.appservices.dtos.Mappers
{
@ -7,17 +8,17 @@ namespace espacecollab.backend.appservices.dtos.Mappers
public static CollaborateurApiDto ToApi(this CollaborateurSqlDto collaborateurSql)
{
return new CollaborateurApiDto((uint)collaborateurSql.Id, collaborateurSql.Name, collaborateurSql.FirstName,
collaborateurSql.BirthDate, collaborateurSql.Gender.ToEnumGenreApi(), collaborateurSql.Status.ToEnumStatutApi(), collaborateurSql.ChildrenNumber,
collaborateurSql.BirthDate.ToShortDateString(), collaborateurSql.Gender.ToEnumGenreApi(), collaborateurSql.Status.ToEnumStatutApi(), collaborateurSql.ChildrenNumber,
collaborateurSql.Address, collaborateurSql.Telephone, collaborateurSql.PersonalMail, collaborateurSql.ApsideMail,
collaborateurSql.ResignationDate, collaborateurSql.ReferrerId, collaborateurSql.BusinessUnitId);
collaborateurSql.ResignationDate.ToShortDateString(), collaborateurSql.ReferrerId, collaborateurSql.BusinessUnitId);
}
public static CollaborateurSqlDto ToSql(this CollaborateurApiDto collaborateurApi)
{
return new CollaborateurSqlDto((int)collaborateurApi.Id, collaborateurApi.Name, collaborateurApi.FirstName,
collaborateurApi.BirthDate, collaborateurApi.Gender.ToEnumGenreSql(), collaborateurApi.Status.ToEnumStatutSql(), collaborateurApi.ChildrenNumber,
DateTime.ParseExact(collaborateurApi.BirthDate,"dd/MM/yyyy",CultureInfo.InvariantCulture), collaborateurApi.Gender.ToEnumGenreSql(), collaborateurApi.Status.ToEnumStatutSql(), collaborateurApi.ChildrenNumber,
collaborateurApi.Address, collaborateurApi.Telephone, collaborateurApi.PersonalMail, collaborateurApi.ApsideMail,
collaborateurApi.ResignationDate, collaborateurApi.ReferrerId, collaborateurApi.BusinessUnitId);
DateTime.ParseExact(collaborateurApi.ResignationDate, "dd/MM/yyyy", CultureInfo.InvariantCulture), collaborateurApi.ReferrerId, collaborateurApi.BusinessUnitId);
}
}
}

@ -47,10 +47,6 @@ namespace espacecollab.backend.appservices
public TO? Update(TO apiDto)
{
if (GetById(apiDto.Id) == null)
{
return null;
}
T sqlDto = MapperToSqlDto(apiDto);
T? sqlDtoValidation = GenericRepository.Update(sqlDto);

@ -1,11 +1,13 @@
using espacecollab.backend.infrastructure.sql.dtos.Values;
using System.Diagnostics.CodeAnalysis;
using espacecollab.backend.infrastructure.sql.dtos.Interfaces;
using System.ComponentModel.DataAnnotations;
namespace espacecollab.backend.infrastructure.sql.dtos
{
public class CollaborateurSqlDto : IGenericIdSqlDto
{
[Key]
public int Id { get; set; }
public string Name { get; set; }
public string FirstName { get; set; }

@ -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.Extensions.Options;
namespace espacecollab.backend.infrastructure.sql
@ -6,6 +7,7 @@ namespace espacecollab.backend.infrastructure.sql
public class MainDbContext : DbContext
{
private IOptions<SqlOption> SqlSettings { get; }
private DbSet<CollaborateurSqlDto>? Collaborateur { get; set; }
public MainDbContext(IOptions<SqlOption> sqlSettings)
{
@ -14,10 +16,22 @@ namespace espacecollab.backend.infrastructure.sql
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(SqlSettings.Value.ConnectionString, builder =>
{
builder.EnableRetryOnFailure(5, TimeSpan.FromSeconds(10), null);
});
optionsBuilder.UseMySql(SqlSettings.Value.ConnectionString,
ServerVersion.AutoDetect(SqlSettings.Value.ConnectionString))
.EnableSensitiveDataLogging();
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<CollaborateurSqlDto>().Property(p=> p.Id).UseMySqlIdentityColumn();
modelBuilder
.Entity<CollaborateurSqlDto>()
.Property(e => e.Gender)
.HasConversion<string>();
modelBuilder
.Entity<CollaborateurSqlDto>()
.Property(e => e.Status)
.HasConversion<string>();
}
}
}

@ -1,5 +1,6 @@
using espacecollab.backend.infrastructure.interfaces;
using espacecollab.backend.infrastructure.sql.dtos.Interfaces;
using Microsoft.EntityFrameworkCore;
namespace espacecollab.backend.infrastructure.sql.Repository
{
@ -14,7 +15,10 @@ namespace espacecollab.backend.infrastructure.sql.Repository
public virtual T? Add(T entity)
{
return Context.Set<T>().Add(entity) as T;
Context.Set<T>().Add(entity);
Context.SaveChanges();
return entity;
}
public virtual bool Delete(int entityId)
@ -40,7 +44,6 @@ namespace espacecollab.backend.infrastructure.sql.Repository
{
Context.Set<T>().Update(entity);
Context.SaveChanges();
return Context.Set<T>().FirstOrDefault(e => e.Id == entity.Id);
}
}

@ -59,15 +59,17 @@ CREATE TABLE IF NOT EXISTS Collaborateur(
Name varchar(100) NOT NULL,
FirstName varchar(100) NOT NULL,
BirthDate date NOT NULL,
Gender ENUM('MASCULIN','FEMININ','AUTRE') NOT NULL,
Status ENUM('CADRE','NONCADRE','ALTERNANT','STAGIAIRE') NOT NULL,
Gender ENUM('masculin','feminin','autre') NOT NULL DEFAULT 'masculin',
Status ENUM('cadre','noncadre','alternant','stagiaire') NOT NULL DEFAULT 'noncadre',
ChildrenNumber smallint NOT NULL,
Address varchar(200) NOT NULL,
Telephone varchar(15) NOT NULL,
PersonalMail varchar(100) NOT NULL,
ApsideMail varchar(100) NOT NULL,
ResignationDate date NOT NULL,
ReferrerId int NOT NULL,
ResignationDate date,
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),
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_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>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" 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" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.0" />
</ItemGroup>
<ItemGroup>

Loading…
Cancel
Save