Gestion de l'unicité des adresses mails

pull/11/head
Clement FERRERE 3 years ago
parent bc6daab6d1
commit e9cb320e4a
  1. 4
      Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/BaseController.cs
  2. 23
      Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs
  3. 4
      Collaborateur_Epa_Back/espacecollab.backend.api/appsettings.json
  4. 0
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/CollaborateurMapper.cs
  5. 37
      Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursService.cs
  6. 4
      Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs
  7. 10
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/MainDbContext.cs
  8. BIN
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/db/init_db.sql - Raccourci.lnk
  9. 9
      Collaborateur_Epa_Back/espacecollab.backend.sln

@ -32,7 +32,7 @@ namespace espacecollab.backend.api.Controllers
}
[HttpPost]
public ActionResult<TO> Add(TO apiDto)
public virtual ActionResult<TO> Add(TO apiDto)
{
TO? addedApiDto = Services.Add(apiDto);
if (addedApiDto == null)
@ -52,7 +52,7 @@ namespace espacecollab.backend.api.Controllers
}
[HttpPut("{id:int:min(1)}")]
public ActionResult<TO> Update(uint id, TO apiDto)
public virtual ActionResult<TO> Update(uint id, TO apiDto)
{
if (apiDto.Id != id)
return Unauthorized();

@ -13,6 +13,29 @@ public class CollaborateursController : BaseController<CollaborateurApiDto>
CollaborateursServices = collaborateursServices;
}
[HttpPost]
public override ActionResult<CollaborateurApiDto> Add(CollaborateurApiDto apiDto)
{
CollaborateurApiDto? addedApiDto = Services.Add(apiDto);
if (addedApiDto == null)
return Problem();
return Ok(addedApiDto);
}
[HttpPut("{id:int:min(1)}")]
public override ActionResult<CollaborateurApiDto> Update(uint id, CollaborateurApiDto apiDto)
{
if (apiDto.Id != id)
return Unauthorized();
CollaborateurApiDto? updatedApiDto = Services.Update(apiDto);
if (updatedApiDto == null)
return Problem();
return Ok(updatedApiDto);
}
[HttpGet("businessunit/{businessUnitId:int:min(1)}")]
public ActionResult<IEnumerable<CollaborateurApiDto>> GetCollaborateursByBusinessUnit(uint businessUnitId)
{

@ -8,8 +8,8 @@
"AllowedHosts": "*",
"Sql": {
"LoadFake": false,
//"ConnectionString": "server=database;user=root;password=root;database=collaborateur_epa" //préprod
"ConnectionString": "server=database;user=root;password=root;database=collaborateur_epa" //préprod
//"ConnectionString": "server=db;user=root;password=root;database=collaborateur_epa" //docker-compose
"ConnectionString": "server=localhost;user=root;password=root;database=collaborateur_epa" //local
//"ConnectionString": "server=localhost;user=root;password=root;database=collaborateur_epa" //local
}
}

@ -15,6 +15,43 @@ public class CollaborateursService : GenericsServices<CollaborateurSqlDto, Colla
CollaborateurRepository = collaborateurRepository;
}
public override CollaborateurApiDto? Add(CollaborateurApiDto apiDto)
{
if(GetAll().Where(collab => apiDto.ApsideMail == collab.ApsideMail).Any())
{
return null;
}
CollaborateurSqlDto sqlDto = apiDto.ToSql();
CollaborateurSqlDto? entitySqlValidation = CollaborateurRepository.Add(sqlDto);
if (entitySqlValidation == null)
return null;
return entitySqlValidation.ToApi();
}
public override CollaborateurApiDto? Update(CollaborateurApiDto apiDto)
{
if (GetById(apiDto.Id) == null)
return null;
if (GetAll().Where(collab => apiDto.ApsideMail == collab.ApsideMail && apiDto.Id != collab.Id).Any())
{
return null;
}
CollaborateurSqlDto sqlDto = apiDto.ToSql();
CollaborateurSqlDto? sqlDtoValidation = CollaborateurRepository.Update(sqlDto);
if (sqlDtoValidation == null)
return null;
return sqlDtoValidation.ToApi();
}
public IEnumerable<CollaborateurApiDto> GetCollaborateursByBusinessUnit(uint businessUnitId)
{
return CollaborateurRepository.GetCollaborateursByBusinessUnit((int)businessUnitId).Select(collaborateurSql => collaborateurSql.ToApi());

@ -34,7 +34,7 @@ public abstract class GenericsServices<T, TO> : IGenericsServices<TO> where T :
return MapperToApiDto(entity);
}
public TO? Add(TO apiDto)
public virtual TO? Add(TO apiDto)
{
T sqlDto = MapperToSqlDto(apiDto);
@ -45,7 +45,7 @@ public abstract class GenericsServices<T, TO> : IGenericsServices<TO> where T :
return MapperToApiDto(entitySqlValidation);
}
public TO? Update(TO apiDto)
public virtual TO? Update(TO apiDto)
{
if (GetById(apiDto.Id) == null)
return null;

@ -24,9 +24,19 @@ public class MainDbContext : DbContext
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<BusinessUnitSqlDto>().Property(p => p.Id).UseMySqlIdentityColumn();
modelBuilder.Entity<AgenceSqlDto>().Property(p => p.Id).UseMySqlIdentityColumn();
modelBuilder.Entity<FonctionSqlDto>().Property(p => p.Id).UseMySqlIdentityColumn();
modelBuilder.Entity<TechnologieSqlDto>().Property(p => p.Id).UseMySqlIdentityColumn();
modelBuilder.Entity<PeriodeEssaiSqlDto>().Property(p => p.Id).UseMySqlIdentityColumn();
modelBuilder
.Entity<PeriodeEssaiSqlDto>()
.Property(e => e.Issue)
.HasConversion<string>();
modelBuilder.Entity<CollaborateurSqlDto>().Property(p => p.Id).UseMySqlIdentityColumn();
modelBuilder
.Entity<CollaborateurSqlDto>()

@ -27,12 +27,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "espacecollab.backend.appser
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "espacecollab.backend.api.tests", "espacecollab.backend.api.tests\espacecollab.backend.api.tests.csproj", "{5EA7CAB6-B7A8-4A54-8A1D-774A376974CB}"
EndProject
Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{815B6ABD-7550-4D79-A53B-E84F4D4A7475}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "9 Database", "9 Database", "{4C74D622-BEC1-41C9-95F1-7C44375B531B}"
ProjectSection(SolutionItems) = preProject
init_db.sql = init_db.sql
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -76,10 +71,6 @@ Global
{5EA7CAB6-B7A8-4A54-8A1D-774A376974CB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5EA7CAB6-B7A8-4A54-8A1D-774A376974CB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5EA7CAB6-B7A8-4A54-8A1D-774A376974CB}.Release|Any CPU.Build.0 = Release|Any CPU
{815B6ABD-7550-4D79-A53B-E84F4D4A7475}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{815B6ABD-7550-4D79-A53B-E84F4D4A7475}.Debug|Any CPU.Build.0 = Debug|Any CPU
{815B6ABD-7550-4D79-A53B-E84F4D4A7475}.Release|Any CPU.ActiveCfg = Release|Any CPU
{815B6ABD-7550-4D79-A53B-E84F4D4A7475}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

Loading…
Cancel
Save