From e9cb320e4ad87a84eca4ee10e57f33b70ea098d4 Mon Sep 17 00:00:00 2001 From: Clement FERRERE Date: Tue, 3 May 2022 11:23:23 +0200 Subject: [PATCH] =?UTF-8?q?Gestion=20de=20l'unicit=C3=A9=20des=20adresses?= =?UTF-8?q?=20mails?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/BaseController.cs | 4 +- .../Controllers/CollaborateursController.cs | 23 +++++++++++ .../espacecollab.backend.api/appsettings.json | 4 +- ...ApiDtoMapper.cs => CollaborateurMapper.cs} | 0 .../CollaborateursService.cs | 37 ++++++++++++++++++ .../GenericsServices.cs | 4 +- .../MainDbContext.cs | 10 +++++ .../db/init_db.sql - Raccourci.lnk | Bin 1102 -> 0 bytes .../espacecollab.backend.sln | 9 ----- 9 files changed, 76 insertions(+), 15 deletions(-) rename Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/{CollaborateurApiDtoMapper.cs => CollaborateurMapper.cs} (100%) delete mode 100644 Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/db/init_db.sql - Raccourci.lnk diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/BaseController.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/BaseController.cs index 1a1589b..b5bb33c 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/BaseController.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/BaseController.cs @@ -32,7 +32,7 @@ namespace espacecollab.backend.api.Controllers } [HttpPost] - public ActionResult Add(TO apiDto) + public virtual ActionResult 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 Update(uint id, TO apiDto) + public virtual ActionResult Update(uint id, TO apiDto) { if (apiDto.Id != id) return Unauthorized(); diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs index 3b8af84..8fd6a20 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs @@ -13,6 +13,29 @@ public class CollaborateursController : BaseController CollaborateursServices = collaborateursServices; } + [HttpPost] + public override ActionResult Add(CollaborateurApiDto apiDto) + { + CollaborateurApiDto? addedApiDto = Services.Add(apiDto); + if (addedApiDto == null) + return Problem(); + + return Ok(addedApiDto); + } + + [HttpPut("{id:int:min(1)}")] + public override ActionResult 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> GetCollaborateursByBusinessUnit(uint businessUnitId) { diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/appsettings.json b/Collaborateur_Epa_Back/espacecollab.backend.api/appsettings.json index b8e3730..64f8b67 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/appsettings.json +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/appsettings.json @@ -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 } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/CollaborateurApiDtoMapper.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/CollaborateurMapper.cs similarity index 100% rename from Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/CollaborateurApiDtoMapper.cs rename to Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/CollaborateurMapper.cs diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursService.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursService.cs index 81796f9..6893a17 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursService.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursService.cs @@ -15,6 +15,43 @@ public class CollaborateursService : GenericsServices 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 GetCollaborateursByBusinessUnit(uint businessUnitId) { return CollaborateurRepository.GetCollaborateursByBusinessUnit((int)businessUnitId).Select(collaborateurSql => collaborateurSql.ToApi()); diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs index 72d8693..1fea564 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs @@ -34,7 +34,7 @@ public abstract class GenericsServices : IGenericsServices 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 : IGenericsServices where T : return MapperToApiDto(entitySqlValidation); } - public TO? Update(TO apiDto) + public virtual TO? Update(TO apiDto) { if (GetById(apiDto.Id) == null) return null; diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/MainDbContext.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/MainDbContext.cs index 1f7f0bd..59b5eea 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/MainDbContext.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/MainDbContext.cs @@ -24,9 +24,19 @@ public class MainDbContext : DbContext protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity().Property(p => p.Id).UseMySqlIdentityColumn(); + modelBuilder.Entity().Property(p => p.Id).UseMySqlIdentityColumn(); + modelBuilder.Entity().Property(p => p.Id).UseMySqlIdentityColumn(); + modelBuilder.Entity().Property(p => p.Id).UseMySqlIdentityColumn(); + + modelBuilder.Entity().Property(p => p.Id).UseMySqlIdentityColumn(); + modelBuilder + .Entity() + .Property(e => e.Issue) + .HasConversion(); + modelBuilder.Entity().Property(p => p.Id).UseMySqlIdentityColumn(); modelBuilder .Entity() diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/db/init_db.sql - Raccourci.lnk b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/db/init_db.sql - Raccourci.lnk deleted file mode 100644 index 411b0c65ca031db5eb4e1337051f11aecb7d4b50..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1102 zcma)4T}TvB6#mxMP$XDOBtvVlmrB}P!xk5X+8>*irCoBOf~jrS*=lWeW}KZVGZ6)q zs08sBk)-G$dhl`I5_+@f_bDRk+}R%&YiZBr{M>ubJ>U7cK>(JTGLpax zQ=)SU6|j@tINJPV!j-m!FD~4Bb}Vgam<{Z7b)+q4Dl?9jjLOUXWi{9pUJb3-*W3x) z{d5JInw#&`;egjIAd%F`V>?+nj7Hf8Zzvc%;u&lK_&mmIPY$DesFvPr z+JMp8b^%_BC(()`MwUieCp?3!2>eiK&#*?aSi`)py%0;vVj298WDaZh@-}*7-GKGG z>23*F5z{A0xC&JqryP7_b(=YG`FaQXZ4hI?p)9(_@9i7o2SnCQW#M1wH&>rRqzZwp zBwN77Z14m9b|mD49uZ@XRIdas8&Bq!PqJGUuc~viiB6(`-dD^c0hw5*99d)s<=abr z1a=UQ5!Vy5Z^U#fF{4r9I$|~nYt<{*NS{i`qH;B52Yscmru4-1lt(cnMHjq^Bt>J2 z7S-d17V)dmzfU4wC8;W@c*Li43t~(tEQkJ-145BJz0_$p-4_32LJ9LK#i!Uz1+#DG zGu@azO`1`+q^Y{2cwGBZzCO_tc)l{U=hobZ#rZeGlaFRTR*#<@+4rk@=KKHd z{S=3WJ>5py*%j`Zt4;c5$5rkjci8cuqwjVDonK;D9Pu@gTRHcxJ+OH6?awbuU#Hl4 Gj{X3&qw=`` diff --git a/Collaborateur_Epa_Back/espacecollab.backend.sln b/Collaborateur_Epa_Back/espacecollab.backend.sln index 3def954..d16a1b6 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.sln +++ b/Collaborateur_Epa_Back/espacecollab.backend.sln @@ -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