From e5c9c3a85e6187484a17569b07a4778720041f4f Mon Sep 17 00:00:00 2001 From: Clement FERRERE Date: Thu, 2 Dec 2021 15:52:39 +0100 Subject: [PATCH] Refacto + Generic repos et service complet --- .../Controllers/CollaborateursController.cs | 18 ++-- .../espacecollab.backend.api/Program.cs | 2 +- .../espacecollab.backend.api/Startup.cs | 9 +- .../espacecollab.backend.api.csproj | 1 + .../CollaborateurApiDto.cs | 10 +-- .../EnumStatutApi.cs | 2 +- .../GenericApiDtoBase.cs | 17 ---- .../CollaborateursServices.cs | 4 +- .../GenericsServices.cs | 51 +++++------ .../IGenericsServices.cs | 12 +-- .../FakeCollaborateurRepository.cs | 42 ++++++++++ .../GenericFakeRepository.cs | 47 +++++++++++ ...ecollab.backend.infrastructure.fake.csproj | 14 ++++ .../IAgenceRepository.cs | 2 +- .../IBusinessUnitRepository.cs | 2 +- .../ICollaborateurRepository.cs | 2 +- .../IGenericRepository.cs | 8 +- .../IPeriodeEssaiRepository.cs | 2 +- .../IProjetRepository.cs | 2 +- .../IReferencementRepository.cs | 2 +- ...b.backend.infrastructure.interfaces.csproj | 13 +++ .../AgenceSqlDto.cs | 3 +- .../BusinessUnitSqlDto.cs | 3 +- ...llaborateurAppartientBusinessUnitSqlDto.cs | 2 +- .../CollaborateurEstFonctionSqlDto.cs | 2 +- .../CollaborateurSqlDto.cs | 3 +- .../FonctionSqlDto.cs | 3 +- .../IGenericSqlDto.cs | 8 -- .../Interfaces/IGenericIdSqlDto.cs | 7 ++ .../PeriodeEssaiSqlDto.cs | 5 +- .../ProjetSqlDto.cs | 4 +- .../ProjetUtiliseTechnologieSqlDto.cs | 1 - .../ReferencementSqlDto.cs | 5 +- .../SiteSqlDto.cs | 3 +- .../TechnologieSqlDto.cs | 3 +- .../FakeRepo/FakeCollaborateurRepository.cs | 84 ------------------- .../MainDbContext.cs | 8 +- .../CollaborateurSqlRepository.cs | 8 +- .../GenericSqlRepository.cs} | 23 +++-- ...cecollab.backend.infrastructure.sql.csproj | 1 + .../espacecollab.backend.sln | 37 ++++++-- 41 files changed, 254 insertions(+), 221 deletions(-) delete mode 100644 Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/GenericApiDtoBase.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeCollaborateurRepository.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/GenericFakeRepository.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/espacecollab.backend.infrastructure.fake.csproj rename Collaborateur_Epa_Back/{espacecollab.backend.infrastructure.sql/SqlRepo/Interface => espacecollab.backend.infrastructure.interfaces}/IAgenceRepository.cs (67%) rename Collaborateur_Epa_Back/{espacecollab.backend.infrastructure.sql/SqlRepo/Interface => espacecollab.backend.infrastructure.interfaces}/IBusinessUnitRepository.cs (69%) rename Collaborateur_Epa_Back/{espacecollab.backend.infrastructure.sql/SqlRepo/Interface => espacecollab.backend.infrastructure.interfaces}/ICollaborateurRepository.cs (85%) rename Collaborateur_Epa_Back/{espacecollab.backend.infrastructure.sql/SqlRepo/Interface => espacecollab.backend.infrastructure.interfaces}/IGenericRepository.cs (60%) rename Collaborateur_Epa_Back/{espacecollab.backend.infrastructure.sql/SqlRepo/Interface => espacecollab.backend.infrastructure.interfaces}/IPeriodeEssaiRepository.cs (69%) rename Collaborateur_Epa_Back/{espacecollab.backend.infrastructure.sql/SqlRepo/Interface => espacecollab.backend.infrastructure.interfaces}/IProjetRepository.cs (75%) rename Collaborateur_Epa_Back/{espacecollab.backend.infrastructure.sql/SqlRepo/Interface => espacecollab.backend.infrastructure.interfaces}/IReferencementRepository.cs (86%) create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/espacecollab.backend.infrastructure.interfaces.csproj delete mode 100644 Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/IGenericSqlDto.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/Interfaces/IGenericIdSqlDto.cs delete mode 100644 Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/FakeRepo/FakeCollaborateurRepository.cs rename Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/{SqlRepo => Repository}/CollaborateurSqlRepository.cs (74%) rename Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/{SqlRepo/GenericRepository.cs => Repository/GenericSqlRepository.cs} (60%) diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs index 76bd73b..a249fe4 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs @@ -38,24 +38,28 @@ namespace espacecollab.backend.api.Controllers { CollaborateurApiDto? addedCollaborateur = CollaborateursServices.Add(collaborateurApi); if (addedCollaborateur == null) - return BadRequest(); + return Problem(); + return Ok(addedCollaborateur); } [HttpDelete("delete")] - public ActionResult DeleteCollaborateur(CollaborateurApiDto collaborateurApi) + public ActionResult DeleteCollaborateur(CollaborateurApiDto collaborateurApi) //TODO passé uniquement l'ID { - CollaborateurApiDto? deletedCollaborateur = CollaborateursServices.Delete(collaborateurApi); - if (deletedCollaborateur == null) - return BadRequest(); - return Ok(deletedCollaborateur); + bool isCollaborateurDeleted = CollaborateursServices.Delete(collaborateurApi); + if (!isCollaborateurDeleted) + return Problem(); + + return Ok(); } [HttpPut("update")] public ActionResult UpdateCollaborateur(CollaborateurApiDto collaborateurApi) { CollaborateurApiDto? updatedCollaborateur = CollaborateursServices.Update(collaborateurApi); - if (updatedCollaborateur == null) { return BadRequest(); } + if (updatedCollaborateur == null) + return Problem(); + return Ok(updatedCollaborateur); } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Program.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Program.cs index 5520279..edf6cfb 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/Program.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Program.cs @@ -1,4 +1,4 @@ -namespace Api +namespace espacecollab.backend.api { public static class Program { diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Startup.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Startup.cs index ad7b864..0748fcf 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/Startup.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Startup.cs @@ -1,12 +1,11 @@ using espacecollab.backend.appservices; +using espacecollab.backend.infrastructure.fake; +using espacecollab.backend.infrastructure.interfaces; using espacecollab.backend.infrastructure.sql; -using espacecollab.backend.infrastructure.sql.dtos; -using espacecollab.backend.infrastructure.sql.FakeRepo; using espacecollab.backend.infrastructure.sql.Options; -using espacecollab.backend.infrastructure.sql.SqlRepo; -using espacecollab.backend.infrastructure.sql.SqlRepo.Interface; +using espacecollab.backend.infrastructure.sql.Repository; -namespace Api +namespace espacecollab.backend.api { public class Startup { diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/espacecollab.backend.api.csproj b/Collaborateur_Epa_Back/espacecollab.backend.api/espacecollab.backend.api.csproj index 348965b..eacb4b7 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/espacecollab.backend.api.csproj +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/espacecollab.backend.api.csproj @@ -12,6 +12,7 @@ + diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs index aabbb3a..d974894 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs @@ -1,7 +1,4 @@ -using espacecollab.backend.appservices.dtos.Mappers; -using espacecollab.backend.infrastructure.sql.dtos; - -namespace espacecollab.backend.appservices.dtos +namespace espacecollab.backend.appservices.dtos { public class CollaborateurApiDto { @@ -22,7 +19,6 @@ namespace espacecollab.backend.appservices.dtos public CollaborateurApiDto() { - } public CollaborateurApiDto(int 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) @@ -43,10 +39,6 @@ namespace espacecollab.backend.appservices.dtos BusinessUnitId = businessUnitId; } - public CollaborateurApiDto(CollaborateurSqlDto entity) - { - } - //public override CollaborateurSqlDto ToEntity() //{ // return new CollaborateurSqlDto(Id, Name, FirstName, BirthDate, Gender.ToEnumGenreSql(), Status.ToEnumStatutSql(), ChildrenNumber, diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/EnumStatutApi.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/EnumStatutApi.cs index 35c7d70..0cad417 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/EnumStatutApi.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/EnumStatutApi.cs @@ -7,4 +7,4 @@ ALTERNANT, STAGIAIRE } -} +} \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/GenericApiDtoBase.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/GenericApiDtoBase.cs deleted file mode 100644 index 6f54298..0000000 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/GenericApiDtoBase.cs +++ /dev/null @@ -1,17 +0,0 @@ -using espacecollab.backend.infrastructure.sql.dtos; - -namespace espacecollab.backend.appservices.dtos -{ - public abstract class GenericApiDtoBase where T : class, IGenericSqlDto - where To : GenericApiDtoBase - { - public abstract T ToEntity(); - - public abstract To FromEntity(T entity); - - public GenericApiDtoBase(T entity) - { - FromEntity(entity); - } - } -} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs index a5e442d..9255799 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs @@ -1,9 +1,7 @@ using espacecollab.backend.appservices.dtos; using espacecollab.backend.appservices.dtos.Mappers; +using espacecollab.backend.infrastructure.interfaces; using espacecollab.backend.infrastructure.sql.dtos; -using espacecollab.backend.infrastructure.sql.FakeRepo; -using espacecollab.backend.infrastructure.sql.SqlRepo; -using espacecollab.backend.infrastructure.sql.SqlRepo.Interface; namespace espacecollab.backend.appservices { diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs index f615f15..f4e0bcb 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs @@ -1,29 +1,29 @@ -using espacecollab.backend.infrastructure.sql.dtos; -using espacecollab.backend.infrastructure.sql.SqlRepo.Interface; +using espacecollab.backend.infrastructure.interfaces; +using espacecollab.backend.infrastructure.sql.dtos.Interfaces; namespace espacecollab.backend.appservices { - public abstract class GenericsServices where T : class, IGenericSqlDto - where To : class + public abstract class GenericsServices where T : class, IGenericIdSqlDto + where TO : class { - Func MapperToApiDto { get; } - Func MapperToSqlDto { get; } + Func MapperToApiDto { get; } + Func MapperToSqlDto { get; } private IGenericRepository GenericRepository { get; } - public GenericsServices(IGenericRepository genericRepository, Func mapperToApiDto, Func mapperToSqlDto) + protected GenericsServices(IGenericRepository genericRepository, Func mapperToApiDto, Func mapperToSqlDto) { GenericRepository = genericRepository; MapperToApiDto = mapperToApiDto; MapperToSqlDto = mapperToSqlDto; } - public IEnumerable GetAll() + public IEnumerable GetAll() { return GenericRepository.GetAll().Select(entity => MapperToApiDto(entity)).ToList(); } - public To? GetById(int id) + public TO? GetById(int id) { T? entity = GenericRepository.GetById(id); if (entity == null) @@ -32,34 +32,35 @@ namespace espacecollab.backend.appservices return MapperToApiDto(entity); } - public To? Add(To apiDto) + public TO? Add(TO apiDto) { T sqlDto = MapperToSqlDto(apiDto); - if (sqlDto == null) { return null; } + T? entitySqlValidation = GenericRepository.Add(sqlDto); - if (entitySqlValidation == null) { return null; } + if (entitySqlValidation == null) + return null; + return MapperToApiDto(entitySqlValidation); } - public To? Update(To apiDto) + public TO? Update(TO apiDto) { - T? sqlDto = MapperToSqlDto(apiDto); - if (sqlDto == null) - return null; + //TODO tester l'existence de l'apiDto dans le SQL + + T sqlDto = MapperToSqlDto(apiDto); T? sqlDtoValidation = GenericRepository.Update(sqlDto); - if (sqlDtoValidation == null) { return null; } - return MapperToApiDto(sqlDtoValidation); - } - public To? Delete(To apiDto) - { - T? sqlDto = MapperToSqlDto(apiDto); - if (sqlDto == null) + + if (sqlDtoValidation == null) return null; - T? sqlDtoValidation = GenericRepository.Delete(sqlDto); - if (sqlDtoValidation == null) { return null; } + return MapperToApiDto(sqlDtoValidation); } + public bool Delete(TO apiDto) + { + T sqlDto = MapperToSqlDto(apiDto); + return GenericRepository.Delete(sqlDto); + } } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices/IGenericsServices.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices/IGenericsServices.cs index 443a80c..3ba9193 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices/IGenericsServices.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices/IGenericsServices.cs @@ -1,15 +1,15 @@ -using espacecollab.backend.infrastructure.sql.dtos; +using espacecollab.backend.infrastructure.sql.dtos.Interfaces; namespace espacecollab.backend.appservices { - public interface IGenericsServices where T : class, IGenericSqlDto + public interface IGenericsServices where T : class, IGenericIdSqlDto { - To? Add(T entity); + TO? Add(T entity); - IEnumerable GetAll(); + IEnumerable GetAll(); - To? GetById(int id); + TO? GetById(int id); - To? Update(T entity); + TO? Update(T entity); } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeCollaborateurRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeCollaborateurRepository.cs new file mode 100644 index 0000000..d6aa6bc --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeCollaborateurRepository.cs @@ -0,0 +1,42 @@ +using espacecollab.backend.infrastructure.interfaces; +using espacecollab.backend.infrastructure.sql.dtos; +using espacecollab.backend.infrastructure.sql.dtos.Values; + +namespace espacecollab.backend.infrastructure.fake +{ + public class FakeCollaborateurRepository : GenericFakeRepository, ICollaborateurRepository + { + public FakeCollaborateurRepository() + { + Context = new List + { + new(1, "Dupont", "Jean", new DateTime(1980, 12, 10), + EnumGenreSql.MASCULIN, EnumStatutSql.NONCADRE, 0, "1 rue du Louvre, 63000, Clermont-Ferrand", "0660258644", + "jean.dupont@gmail.com", "jean.dupont@apside-groupe.com", new DateTime(2023, 12, 17), 2, 1), + + new(2, "Michel", "Laura", new DateTime(1985, 08, 12), + EnumGenreSql.FEMININ, EnumStatutSql.NONCADRE, 0, "5 rue du Louvre, 63000, Clermont-Ferrand", "0660258644", + "laura.michel@gmail.com", "laura.michel@apside-groupe.com", new DateTime(2023, 12, 17), 1, 1) + }; + } + + #region méthodes spécifiques à l'interface ICollaborateurRepository + + public IList GetCollaborateursByBusinessUnit(int businessUnitId) + { + return Context.Where(entity => entity.BusinessUnitId == businessUnitId).ToList(); + } + + public IList GetCollaborateursByReferrer(int referrerId) + { + return Context.Where(entity => entity.ReferrerId == referrerId).ToList(); + } + + public CollaborateurSqlDto GetCollaborateurByApsideMail(string apsideMail) + { + return Context.First(entity => entity.ApsideMail == apsideMail); + } + + #endregion + } +} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/GenericFakeRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/GenericFakeRepository.cs new file mode 100644 index 0000000..6117796 --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/GenericFakeRepository.cs @@ -0,0 +1,47 @@ +using espacecollab.backend.infrastructure.interfaces; +using espacecollab.backend.infrastructure.sql.dtos.Interfaces; + +namespace espacecollab.backend.infrastructure.fake +{ + public class GenericFakeRepository : IGenericRepository where T : class, IGenericIdSqlDto + { + protected List Context { get; set; } + + public virtual T? Add(T entity) + { + int lastId = Context.Max(e => e.Id); + entity.Id = lastId + 1; + + Context.Add(entity); + + return entity; + } + + public virtual bool Delete(T entity) + { + return Context.Remove(entity); + } + + public virtual IEnumerable GetAll() + { + return Context.ToList(); + } + + public virtual T? GetById(int id) + { + return Context.FirstOrDefault(entity => entity.Id == id); + } + + public virtual T? Update(T entity) + { + T? oldEntity = GetById(entity.Id); + if (oldEntity == null) + return null; + + Context.Remove(oldEntity); + Context.Add(entity); + + return Context.FirstOrDefault(e => e.Id == entity.Id); + } + } +} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/espacecollab.backend.infrastructure.fake.csproj b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/espacecollab.backend.infrastructure.fake.csproj new file mode 100644 index 0000000..2b4f8c9 --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/espacecollab.backend.infrastructure.fake.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IAgenceRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IAgenceRepository.cs similarity index 67% rename from Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IAgenceRepository.cs rename to Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IAgenceRepository.cs index 15f90be..1443cdd 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IAgenceRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IAgenceRepository.cs @@ -1,6 +1,6 @@ using espacecollab.backend.infrastructure.sql.dtos; -namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface +namespace espacecollab.backend.infrastructure.interfaces { public interface IAgenceRepository : IGenericRepository { diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IBusinessUnitRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IBusinessUnitRepository.cs similarity index 69% rename from Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IBusinessUnitRepository.cs rename to Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IBusinessUnitRepository.cs index 0aadfc4..42a10fd 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IBusinessUnitRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IBusinessUnitRepository.cs @@ -1,6 +1,6 @@ using espacecollab.backend.infrastructure.sql.dtos; -namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface +namespace espacecollab.backend.infrastructure.interfaces { public interface IBusinessUnitRepository : IGenericRepository { diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/ICollaborateurRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/ICollaborateurRepository.cs similarity index 85% rename from Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/ICollaborateurRepository.cs rename to Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/ICollaborateurRepository.cs index 6eef355..f89aecb 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/ICollaborateurRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/ICollaborateurRepository.cs @@ -1,6 +1,6 @@ using espacecollab.backend.infrastructure.sql.dtos; -namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface +namespace espacecollab.backend.infrastructure.interfaces { public interface ICollaborateurRepository : IGenericRepository { diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IGenericRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IGenericRepository.cs similarity index 60% rename from Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IGenericRepository.cs rename to Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IGenericRepository.cs index 13a2f9a..87b225d 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IGenericRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IGenericRepository.cs @@ -1,11 +1,11 @@ -using espacecollab.backend.infrastructure.sql.dtos; +using espacecollab.backend.infrastructure.sql.dtos.Interfaces; -namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface +namespace espacecollab.backend.infrastructure.interfaces { - public interface IGenericRepository where T : class, IGenericSqlDto + public interface IGenericRepository where T : class, IGenericIdSqlDto { T? Add(T entity); - T? Delete(T entity); + bool Delete(T entity); IEnumerable GetAll(); T? GetById(int id); T? Update(T entity); diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IPeriodeEssaiRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IPeriodeEssaiRepository.cs similarity index 69% rename from Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IPeriodeEssaiRepository.cs rename to Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IPeriodeEssaiRepository.cs index 43b4c25..64e08f1 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IPeriodeEssaiRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IPeriodeEssaiRepository.cs @@ -1,6 +1,6 @@ using espacecollab.backend.infrastructure.sql.dtos; -namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface +namespace espacecollab.backend.infrastructure.interfaces { public interface IPeriodeEssaiRepository : IGenericRepository { diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IProjetRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IProjetRepository.cs similarity index 75% rename from Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IProjetRepository.cs rename to Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IProjetRepository.cs index 2dfb773..8738106 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IProjetRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IProjetRepository.cs @@ -1,6 +1,6 @@ using espacecollab.backend.infrastructure.sql.dtos; -namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface +namespace espacecollab.backend.infrastructure.interfaces { public interface IProjetRepository : IGenericRepository { diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IReferencementRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IReferencementRepository.cs similarity index 86% rename from Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IReferencementRepository.cs rename to Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IReferencementRepository.cs index b6f6f75..0e9c81a 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IReferencementRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IReferencementRepository.cs @@ -1,6 +1,6 @@ using espacecollab.backend.infrastructure.sql.dtos; -namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface +namespace espacecollab.backend.infrastructure.interfaces { public interface IReferencementRepository : IGenericRepository { diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/espacecollab.backend.infrastructure.interfaces.csproj b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/espacecollab.backend.infrastructure.interfaces.csproj new file mode 100644 index 0000000..a18f76e --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/espacecollab.backend.infrastructure.interfaces.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/AgenceSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/AgenceSqlDto.cs index cbe1ccc..780ffaa 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/AgenceSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/AgenceSqlDto.cs @@ -1,8 +1,9 @@ using System.Diagnostics.CodeAnalysis; +using espacecollab.backend.infrastructure.sql.dtos.Interfaces; namespace espacecollab.backend.infrastructure.sql.dtos { - public class AgenceSqlDto : IGenericSqlDto + public class AgenceSqlDto : IGenericIdSqlDto { public int Id { get; set; } public string Name { get; set; } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/BusinessUnitSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/BusinessUnitSqlDto.cs index 4b20d4a..1df0c73 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/BusinessUnitSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/BusinessUnitSqlDto.cs @@ -1,8 +1,9 @@ using System.Diagnostics.CodeAnalysis; +using espacecollab.backend.infrastructure.sql.dtos.Interfaces; namespace espacecollab.backend.infrastructure.sql.dtos { - public class BusinessUnitSqlDto : IGenericSqlDto + public class BusinessUnitSqlDto : IGenericIdSqlDto { public int Id { get; set; } public string Name { get; set; } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurAppartientBusinessUnitSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurAppartientBusinessUnitSqlDto.cs index 8eb40da..7c63750 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurAppartientBusinessUnitSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurAppartientBusinessUnitSqlDto.cs @@ -1,6 +1,6 @@ using System.Diagnostics.CodeAnalysis; -namespace espacecollab.backend.infrastructure.sql.dtos.Associations +namespace espacecollab.backend.infrastructure.sql.dtos { public class CollaborateurAppartientBusinessUnitSqlDto { diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurEstFonctionSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurEstFonctionSqlDto.cs index a3cdd1a..b1129c4 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurEstFonctionSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurEstFonctionSqlDto.cs @@ -1,6 +1,6 @@ using System.Diagnostics.CodeAnalysis; -namespace espacecollab.backend.infrastructure.sql.dtos.Associations +namespace espacecollab.backend.infrastructure.sql.dtos { public class CollaborateurEstFonctionSqlDto { diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurSqlDto.cs index 137764e..e1adf0f 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurSqlDto.cs @@ -1,9 +1,10 @@ using espacecollab.backend.infrastructure.sql.dtos.Values; using System.Diagnostics.CodeAnalysis; +using espacecollab.backend.infrastructure.sql.dtos.Interfaces; namespace espacecollab.backend.infrastructure.sql.dtos { - public class CollaborateurSqlDto : IGenericSqlDto + public class CollaborateurSqlDto : IGenericIdSqlDto { public int Id { get; set; } public string Name { get; set; } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/FonctionSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/FonctionSqlDto.cs index db63bc9..1b1cee1 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/FonctionSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/FonctionSqlDto.cs @@ -1,8 +1,9 @@ using System.Diagnostics.CodeAnalysis; +using espacecollab.backend.infrastructure.sql.dtos.Interfaces; namespace espacecollab.backend.infrastructure.sql.dtos { - public class FonctionSqlDto : IGenericSqlDto + public class FonctionSqlDto : IGenericIdSqlDto { public int Id { get; set; } public string Name { get; set; } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/IGenericSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/IGenericSqlDto.cs deleted file mode 100644 index 93547ed..0000000 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/IGenericSqlDto.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace espacecollab.backend.infrastructure.sql.dtos -{ - public interface IGenericSqlDto - { - public int Id { get; set; } - - } -} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/Interfaces/IGenericIdSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/Interfaces/IGenericIdSqlDto.cs new file mode 100644 index 0000000..ce4c282 --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/Interfaces/IGenericIdSqlDto.cs @@ -0,0 +1,7 @@ +namespace espacecollab.backend.infrastructure.sql.dtos.Interfaces +{ + public interface IGenericIdSqlDto + { + public int Id { get; set; } + } +} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/PeriodeEssaiSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/PeriodeEssaiSqlDto.cs index bcc3d5e..7379399 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/PeriodeEssaiSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/PeriodeEssaiSqlDto.cs @@ -1,9 +1,10 @@ using espacecollab.backend.infrastructure.sql.dtos.Values; using System.Diagnostics.CodeAnalysis; +using espacecollab.backend.infrastructure.sql.dtos.Interfaces; namespace espacecollab.backend.infrastructure.sql.dtos { - public class PeriodeEssaiSqlDto : IGenericSqlDto + public class PeriodeEssaiSqlDto : IGenericIdSqlDto { public int Id { get; set; } public DateTime StartingDate { get; set; } @@ -29,7 +30,5 @@ namespace espacecollab.backend.infrastructure.sql.dtos Issue = issue; CollaborateurId = collaborateurId; } - - } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetSqlDto.cs index 2e93a0c..62df00f 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetSqlDto.cs @@ -1,8 +1,9 @@ using System.Diagnostics.CodeAnalysis; +using espacecollab.backend.infrastructure.sql.dtos.Interfaces; namespace espacecollab.backend.infrastructure.sql.dtos { - public class ProjetSqlDto : IGenericSqlDto + public class ProjetSqlDto : IGenericIdSqlDto { public int Id { get; set; } public string Name { get; set; } @@ -25,6 +26,5 @@ namespace espacecollab.backend.infrastructure.sql.dtos StartingDate = startingDate; EndingDate = endingDate; } - } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetUtiliseTechnologieSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetUtiliseTechnologieSqlDto.cs index b3ef497..bf47a6a 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetUtiliseTechnologieSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetUtiliseTechnologieSqlDto.cs @@ -17,6 +17,5 @@ namespace espacecollab.backend.infrastructure.sql.dtos ProjetId = projetId; TechnologieId = technologieId; } - } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ReferencementSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ReferencementSqlDto.cs index d69163d..8bd980a 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ReferencementSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ReferencementSqlDto.cs @@ -1,8 +1,9 @@ using System.Diagnostics.CodeAnalysis; +using espacecollab.backend.infrastructure.sql.dtos.Interfaces; namespace espacecollab.backend.infrastructure.sql.dtos { - public class ReferencementSqlDto : IGenericSqlDto + public class ReferencementSqlDto : IGenericIdSqlDto { public int Id { get; set; } public DateTime StartingDate { get; set; } @@ -23,7 +24,5 @@ namespace espacecollab.backend.infrastructure.sql.dtos ReferredId = referredId; ReferrerId = referrerId; } - - } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteSqlDto.cs index a59f867..3d6afef 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteSqlDto.cs @@ -1,8 +1,9 @@ using System.Diagnostics.CodeAnalysis; +using espacecollab.backend.infrastructure.sql.dtos.Interfaces; namespace espacecollab.backend.infrastructure.sql.dtos { - public class SiteSqlDto : IGenericSqlDto + public class SiteSqlDto : IGenericIdSqlDto { public int Id { get; set; } public string Name { get; set; } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/TechnologieSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/TechnologieSqlDto.cs index cf38ed6..cf53ce5 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/TechnologieSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/TechnologieSqlDto.cs @@ -1,8 +1,9 @@ using System.Diagnostics.CodeAnalysis; +using espacecollab.backend.infrastructure.sql.dtos.Interfaces; namespace espacecollab.backend.infrastructure.sql.dtos { - public class TechnologieSqlDto : IGenericSqlDto + public class TechnologieSqlDto : IGenericIdSqlDto { public int Id { get; set; } public string Name { get; set; } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/FakeRepo/FakeCollaborateurRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/FakeRepo/FakeCollaborateurRepository.cs deleted file mode 100644 index cc89025..0000000 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/FakeRepo/FakeCollaborateurRepository.cs +++ /dev/null @@ -1,84 +0,0 @@ -using espacecollab.backend.infrastructure.sql.dtos; -using espacecollab.backend.infrastructure.sql.dtos.Values; -using espacecollab.backend.infrastructure.sql.SqlRepo; -using espacecollab.backend.infrastructure.sql.SqlRepo.Interface; - -namespace espacecollab.backend.infrastructure.sql.FakeRepo -{ - public class FakeCollaborateurRepository : GenericRepository, ICollaborateurRepository - { - - private IList Collaborateurs { get; } = new List - { - new CollaborateurSqlDto(1, "Dupont", "Jean", new DateTime(1980, 12, 10), - EnumGenreSql.MASCULIN, EnumStatutSql.NONCADRE, 0, "1 rue du Louvre, 63000, Clermont-Ferrand", "0660258644", - "jean.dupont@gmail.com", "jean.dupont@apside-groupe.com", new DateTime(2023, 12, 17), 2, 1), - - new CollaborateurSqlDto(2, "Michel", "Laura", new DateTime(1985, 08, 12), - EnumGenreSql.FEMININ, EnumStatutSql.NONCADRE, 0, "5 rue du Louvre, 63000, Clermont-Ferrand", "0660258644", - "laura.michel@gmail.com", "laura.michel@apside-groupe.com", new DateTime(2023, 12, 17), 1, 1) - }; - - public FakeCollaborateurRepository() - { - } - - #region redéfinition des méthodes du GenericRepository pour fonctionner avec Fake - - public new CollaborateurSqlDto? GetById(int id) - { - return Collaborateurs.FirstOrDefault(entity => entity.Id == id); - } - - public new CollaborateurSqlDto? Add(CollaborateurSqlDto entity) - { - Collaborateurs.Add(entity); - return entity; - } - - public new CollaborateurSqlDto? Delete(CollaborateurSqlDto entity) - { - Collaborateurs.Remove(entity); - return entity; - } - - public new IEnumerable GetAll() - { - return Collaborateurs; - } - - public new CollaborateurSqlDto? Update(CollaborateurSqlDto collaborateur) - { - CollaborateurSqlDto? oldCollab = Collaborateurs.FirstOrDefault(entity => entity.Id == collaborateur.Id); - if (oldCollab == null) - { - Collaborateurs.Add(collaborateur); - return collaborateur; - } - Collaborateurs.Remove(oldCollab); - Collaborateurs.Add(collaborateur); - return collaborateur; - } - - #endregion - - #region méthodes spécifiques à l'interface ICollaborateurRepository - - public IList GetCollaborateursByBusinessUnit(int businessUnitId) - { - return Collaborateurs.Where(entity => entity.BusinessUnitId == businessUnitId).ToList(); - } - - public IList GetCollaborateursByReferrer(int referrerId) - { - return Collaborateurs.Where(entity => entity.ReferrerId == referrerId).ToList(); - } - - public CollaborateurSqlDto GetCollaborateurByApsideMail(string apsideMail) - { - return Collaborateurs.First(entity => entity.ApsideMail == apsideMail); - } - - #endregion - } -} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/MainDbContext.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/MainDbContext.cs index 25204d2..8642097 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/MainDbContext.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/MainDbContext.cs @@ -1,5 +1,4 @@ -using espacecollab.backend.infrastructure.sql.dtos; -using espacecollab.backend.infrastructure.sql.Options; +using espacecollab.backend.infrastructure.sql.Options; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; namespace espacecollab.backend.infrastructure.sql @@ -8,12 +7,11 @@ namespace espacecollab.backend.infrastructure.sql { private IOptions SqlSettings { get; } - public DbSet? Collaborateur { get; set; } - public MainDbContext(IOptions sqlSettings) { SqlSettings = sqlSettings; } + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlServer(SqlSettings.Value.ConnectionString, builder => @@ -21,7 +19,5 @@ namespace espacecollab.backend.infrastructure.sql builder.EnableRetryOnFailure(5, TimeSpan.FromSeconds(10), null); }); } - - } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/CollaborateurSqlRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/CollaborateurSqlRepository.cs similarity index 74% rename from Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/CollaborateurSqlRepository.cs rename to Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/CollaborateurSqlRepository.cs index 6903f92..192d593 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/CollaborateurSqlRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/CollaborateurSqlRepository.cs @@ -1,9 +1,9 @@ -using espacecollab.backend.infrastructure.sql.dtos; -using espacecollab.backend.infrastructure.sql.SqlRepo.Interface; +using espacecollab.backend.infrastructure.interfaces; +using espacecollab.backend.infrastructure.sql.dtos; -namespace espacecollab.backend.infrastructure.sql.SqlRepo +namespace espacecollab.backend.infrastructure.sql.Repository { - public class CollaborateurSqlRepository : GenericRepository,ICollaborateurRepository + public class CollaborateurSqlRepository : GenericSqlRepository, ICollaborateurRepository { private MainDbContext Context { get; } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/GenericRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/GenericSqlRepository.cs similarity index 60% rename from Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/GenericRepository.cs rename to Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/GenericSqlRepository.cs index 373b35d..bee38ec 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/GenericRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/GenericSqlRepository.cs @@ -1,18 +1,13 @@ -using espacecollab.backend.infrastructure.sql.dtos; -using espacecollab.backend.infrastructure.sql.SqlRepo.Interface; +using espacecollab.backend.infrastructure.interfaces; +using espacecollab.backend.infrastructure.sql.dtos.Interfaces; -namespace espacecollab.backend.infrastructure.sql.SqlRepo +namespace espacecollab.backend.infrastructure.sql.Repository { - public class GenericRepository : IGenericRepository where T : class, IGenericSqlDto + public class GenericSqlRepository : IGenericRepository where T : class, IGenericIdSqlDto { private MainDbContext Context { get; } - public GenericRepository() - { - - } - - public GenericRepository(MainDbContext context) + public GenericSqlRepository(MainDbContext context) { Context = context; } @@ -22,9 +17,11 @@ namespace espacecollab.backend.infrastructure.sql.SqlRepo return Context.Set().Add(entity) as T; } - public virtual T? Delete(T entity) + public virtual bool Delete(T entity) { - return Context.Set().Remove(entity) as T; + Context.Set().Remove(entity); + + return Context.SaveChanges() == 1; } public virtual IEnumerable GetAll() @@ -41,8 +38,8 @@ namespace espacecollab.backend.infrastructure.sql.SqlRepo { Context.Set().Update(entity); Context.SaveChanges(); + return Context.Set().FirstOrDefault(e => e.Id == entity.Id); } - } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/espacecollab.backend.infrastructure.sql.csproj b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/espacecollab.backend.infrastructure.sql.csproj index d919b65..66c4cb9 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/espacecollab.backend.infrastructure.sql.csproj +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/espacecollab.backend.infrastructure.sql.csproj @@ -17,6 +17,7 @@ + diff --git a/Collaborateur_Epa_Back/espacecollab.backend.sln b/Collaborateur_Epa_Back/espacecollab.backend.sln index 26e96a6..bd0a931 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.sln +++ b/Collaborateur_Epa_Back/espacecollab.backend.sln @@ -3,15 +3,25 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.0.31912.275 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "espacecollab.backend.api", "espacecollab.backend.api\espacecollab.backend.api.csproj", "{A8DEB005-D7E2-4A96-B004-A66BBF12AC54}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "espacecollab.backend.api", "espacecollab.backend.api\espacecollab.backend.api.csproj", "{A8DEB005-D7E2-4A96-B004-A66BBF12AC54}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "espacecollab.backend.appservices", "espacecollab.backend.appservices\espacecollab.backend.appservices.csproj", "{70F1BE1C-87C1-4CCF-A7E8-2A36F3F16D9E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "espacecollab.backend.appservices", "espacecollab.backend.appservices\espacecollab.backend.appservices.csproj", "{70F1BE1C-87C1-4CCF-A7E8-2A36F3F16D9E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "espacecollab.backend.appservices.dtos", "espacecollab.backend.appservices.dtos\espacecollab.backend.appservices.dtos.csproj", "{CB0CB8FC-0E53-4205-AAA3-4176211C922B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "espacecollab.backend.appservices.dtos", "espacecollab.backend.appservices.dtos\espacecollab.backend.appservices.dtos.csproj", "{CB0CB8FC-0E53-4205-AAA3-4176211C922B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "espacecollab.backend.infrastructure.sql", "espacecollab.backend.infrastructure.sql\espacecollab.backend.infrastructure.sql.csproj", "{590FF09D-0DF3-4881-8D86-E4FDAAC75FDC}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "espacecollab.backend.infrastructure.sql", "espacecollab.backend.infrastructure.sql\espacecollab.backend.infrastructure.sql.csproj", "{590FF09D-0DF3-4881-8D86-E4FDAAC75FDC}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "espacecollab.backend.infrastructure.sql.dtos", "espacecollab.backend.infrastructure.sql.dtos\espacecollab.backend.infrastructure.sql.dtos.csproj", "{26C08CE0-E6E5-4E03-8AEA-233F93218A3B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "espacecollab.backend.infrastructure.sql.dtos", "espacecollab.backend.infrastructure.sql.dtos\espacecollab.backend.infrastructure.sql.dtos.csproj", "{26C08CE0-E6E5-4E03-8AEA-233F93218A3B}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "1 Host", "1 Host", "{19237F76-6CA9-47DF-87F8-8027C78070C9}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "2 ApplicationsServices", "2 ApplicationsServices", "{CE5199B3-E423-46C1-B141-18C46473D964}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "4 Infrastructure", "4 Infrastructure", "{E29F5CA9-ABAF-4437-8633-49FF27110E6D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "espacecollab.backend.infrastructure.interfaces", "espacecollab.backend.infrastructure.interfaces\espacecollab.backend.infrastructure.interfaces.csproj", "{3E9E4801-D686-4581-8051-E0E1B036AC70}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "espacecollab.backend.infrastructure.fake", "espacecollab.backend.infrastructure.fake\espacecollab.backend.infrastructure.fake.csproj", "{48253B9B-9B42-48CF-A95F-358171BABA74}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -39,10 +49,27 @@ Global {26C08CE0-E6E5-4E03-8AEA-233F93218A3B}.Debug|Any CPU.Build.0 = Debug|Any CPU {26C08CE0-E6E5-4E03-8AEA-233F93218A3B}.Release|Any CPU.ActiveCfg = Release|Any CPU {26C08CE0-E6E5-4E03-8AEA-233F93218A3B}.Release|Any CPU.Build.0 = Release|Any CPU + {3E9E4801-D686-4581-8051-E0E1B036AC70}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3E9E4801-D686-4581-8051-E0E1B036AC70}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3E9E4801-D686-4581-8051-E0E1B036AC70}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3E9E4801-D686-4581-8051-E0E1B036AC70}.Release|Any CPU.Build.0 = Release|Any CPU + {48253B9B-9B42-48CF-A95F-358171BABA74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {48253B9B-9B42-48CF-A95F-358171BABA74}.Debug|Any CPU.Build.0 = Debug|Any CPU + {48253B9B-9B42-48CF-A95F-358171BABA74}.Release|Any CPU.ActiveCfg = Release|Any CPU + {48253B9B-9B42-48CF-A95F-358171BABA74}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {A8DEB005-D7E2-4A96-B004-A66BBF12AC54} = {19237F76-6CA9-47DF-87F8-8027C78070C9} + {70F1BE1C-87C1-4CCF-A7E8-2A36F3F16D9E} = {CE5199B3-E423-46C1-B141-18C46473D964} + {CB0CB8FC-0E53-4205-AAA3-4176211C922B} = {CE5199B3-E423-46C1-B141-18C46473D964} + {590FF09D-0DF3-4881-8D86-E4FDAAC75FDC} = {E29F5CA9-ABAF-4437-8633-49FF27110E6D} + {26C08CE0-E6E5-4E03-8AEA-233F93218A3B} = {E29F5CA9-ABAF-4437-8633-49FF27110E6D} + {3E9E4801-D686-4581-8051-E0E1B036AC70} = {E29F5CA9-ABAF-4437-8633-49FF27110E6D} + {48253B9B-9B42-48CF-A95F-358171BABA74} = {E29F5CA9-ABAF-4437-8633-49FF27110E6D} + EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {0A56A44C-135E-4CE4-834B-8DFDF69DC415} EndGlobalSection