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 411b0c6..0000000 Binary files a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/db/init_db.sql - Raccourci.lnk and /dev/null differ 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