diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs index fe0a556..adf4a21 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs @@ -71,16 +71,6 @@ public class CollaborateursController : BaseController return Ok(collaborateurs); } - [HttpGet("referrer/{referrerId:int:min(1)}")] - public ActionResult> GetCollaborateursByReferrer(uint referrerId) - { - IEnumerable collaborateurs = CollaborateursServices.GetCollaborateursByReferrer(referrerId); - if (!collaborateurs.Any()) - return NotFound(); - - return Ok(collaborateurs); - } - [HttpGet("apsidemail/{apsideMail:minlength(1):regex(^\\S.*)}")] public ActionResult GetCollaborateurByApsideMail(string apsideMail) { diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/ReferencementsController.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/ReferencementsController.cs new file mode 100644 index 0000000..4b2fb25 --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/ReferencementsController.cs @@ -0,0 +1,13 @@ +using espacecollab.backend.appservices; +using espacecollab.backend.appservices.dtos; +using Microsoft.AspNetCore.Mvc; + +namespace espacecollab.backend.api.Controllers; + +public class ReferencementsController : BaseController +{ + public ReferencementsController(ReferencementService referencementServices) : base(referencementServices) + { + } + +} \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Register.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Register.cs index 569bc08..ba59d90 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/Register.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Register.cs @@ -17,6 +17,7 @@ internal static class Register services.AddScoped(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); if (contextOptions.LoadFake) { @@ -35,6 +36,7 @@ internal static class Register services.AddScoped(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); } } } \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/appsettings.json b/Collaborateur_Epa_Back/espacecollab.backend.api/appsettings.json index 64f8b67..b8e3730 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/CollaborateurApiDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs index 731c835..93d6082 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs @@ -4,7 +4,7 @@ using espacecollab.backend.appservices.dtos.Values; 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 + string Telephone, string PersonalMail, string ApsideMail, DateTime? ResignationDate, int BusinessUnitId) : IGenericIdApiDto { public uint Id { get; set; } = Id; } \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/CollaborateurMapper.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/CollaborateurMapper.cs index 8672269..75ae43b 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/CollaborateurMapper.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/CollaborateurMapper.cs @@ -9,7 +9,7 @@ public static class CollaborateurMapper return new CollaborateurApiDto((uint)collaborateurSql.Id, collaborateurSql.Name, collaborateurSql.FirstName, collaborateurSql.BirthDate, collaborateurSql.Gender.ToEnumGenreApi(), collaborateurSql.Status.ToEnumStatutApi(), collaborateurSql.ChildrenNumber, collaborateurSql.Address, collaborateurSql.Telephone, collaborateurSql.PersonalMail, collaborateurSql.ApsideMail, - collaborateurSql.ResignationDate, collaborateurSql.ReferrerId, collaborateurSql.BusinessUnitId); + collaborateurSql.ResignationDate, collaborateurSql.BusinessUnitId); } public static CollaborateurSqlDto ToSql(this CollaborateurApiDto collaborateurApi) @@ -17,6 +17,6 @@ public static class CollaborateurMapper return new CollaborateurSqlDto((int)collaborateurApi.Id, collaborateurApi.Name, collaborateurApi.FirstName, collaborateurApi.BirthDate, collaborateurApi.Gender.ToEnumGenreSql(), collaborateurApi.Status.ToEnumStatutSql(), collaborateurApi.ChildrenNumber, collaborateurApi.Address, collaborateurApi.Telephone, collaborateurApi.PersonalMail, collaborateurApi.ApsideMail, - collaborateurApi.ResignationDate, collaborateurApi.ReferrerId, collaborateurApi.BusinessUnitId); + collaborateurApi.ResignationDate, collaborateurApi.BusinessUnitId); } } \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/ReferencementMapper.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/ReferencementMapper.cs new file mode 100644 index 0000000..8d5c6b6 --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/ReferencementMapper.cs @@ -0,0 +1,15 @@ +using espacecollab.backend.infrastructure.sql.dtos; + +namespace espacecollab.backend.appservices.dtos.Mappers; + +public static class ReferencementMapper +{ + public static ReferencementApiDto ToApi(this ReferencementSqlDto referencementSqlDto) + { + return new ReferencementApiDto((uint)referencementSqlDto.Id, referencementSqlDto.StartingDate,referencementSqlDto.EndingDate,referencementSqlDto.ReferredId, referencementSqlDto.ReferrerId); + } + public static ReferencementSqlDto ToSql(this ReferencementApiDto referencementApiDto) + { + return new ReferencementSqlDto((int)referencementApiDto.Id, referencementApiDto.StartingDate, referencementApiDto.EndingDate, referencementApiDto.ReferredId, referencementApiDto.ReferrerId); + } +} \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/ReferencementApiDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/ReferencementApiDto.cs new file mode 100644 index 0000000..51c135c --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/ReferencementApiDto.cs @@ -0,0 +1,12 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Diagnostics.CodeAnalysis; +using espacecollab.backend.appservices.dtos.Interfaces; +using espacecollab.backend.infrastructure.sql.dtos.Interfaces; + +namespace espacecollab.backend.appservices.dtos; + +public record ReferencementApiDto(uint Id, DateTime StartingDate, DateTime? EndingDate, int ReferredId, int ReferrerId) : IGenericIdApiDto +{ + public uint Id { get; set; } = Id; +} \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursService.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursService.cs index 4bacdd1..ef28beb 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursService.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursService.cs @@ -57,11 +57,6 @@ public class CollaborateursService : GenericsServices collaborateurSql.ToApi()); } - public IEnumerable GetCollaborateursByReferrer(uint referrerId) - { - return CollaborateurRepository.GetCollaborateursByReferrer((int)referrerId).Select(collaborateurSql => collaborateurSql.ToApi()); - } - public CollaborateurApiDto? GetCollaborateurByApsideMail(string apsideMail) { if (string.IsNullOrEmpty(apsideMail)) diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices/ReferencementService.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices/ReferencementService.cs new file mode 100644 index 0000000..bd69ad0 --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices/ReferencementService.cs @@ -0,0 +1,18 @@ +using espacecollab.backend.appservices.dtos; +using espacecollab.backend.appservices.dtos.Mappers; +using espacecollab.backend.infrastructure.interfaces; +using espacecollab.backend.infrastructure.sql.dtos; + +namespace espacecollab.backend.appservices; + +public class ReferencementService : GenericsServices +{ + private IReferencementRepository ReferencementRepository { get; } + + public ReferencementService(IReferencementRepository referencementRepository) + : base(referencementRepository, ReferencementMapper.ToApi, ReferencementMapper.ToSql) + { + ReferencementRepository = referencementRepository; + } + +} \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeCollaborateurRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeCollaborateurRepository.cs index f1a956c..8ccde8e 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeCollaborateurRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeCollaborateurRepository.cs @@ -10,12 +10,12 @@ public class FakeCollaborateurRepository : GenericFakeRepository { - 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) + //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) }; } @@ -26,11 +26,6 @@ public class FakeCollaborateurRepository : GenericFakeRepository 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); diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/ICollaborateurRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/ICollaborateurRepository.cs index 35f8866..d110bf1 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/ICollaborateurRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/ICollaborateurRepository.cs @@ -6,5 +6,4 @@ public interface ICollaborateurRepository : IGenericRepository GetCollaborateursByBusinessUnit(int businessUnitId); - IList GetCollaborateursByReferrer(int referrerId); } \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IReferencementRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IReferencementRepository.cs index c12b65f..65c2b3a 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IReferencementRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IReferencementRepository.cs @@ -4,6 +4,4 @@ namespace espacecollab.backend.infrastructure.interfaces; public interface IReferencementRepository : IGenericRepository { - IList? GetReferrersByCollaborateurId(int collaborateurId); - IList? GetReferrersByCollaborateurApsideMail(string apsideMail); } \ No newline at end of file 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 3874a61..1116d74 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurSqlDto.cs @@ -22,7 +22,6 @@ public class CollaborateurSqlDto : IGenericIdSqlDto public string PersonalMail { get; set; } public string ApsideMail { get; set; } public DateTime? ResignationDate { get; set; } - public int ReferrerId { get; set; } public int BusinessUnitId { get; set; } [ExcludeFromCodeCoverage] @@ -36,7 +35,7 @@ public class CollaborateurSqlDto : IGenericIdSqlDto ApsideMail = string.Empty; } - public CollaborateurSqlDto(int id, string name, string firstName, DateTime birthDate, EnumGenreSql gender, EnumStatutSql status, int childrenNumber, string address, string telephone, string personalMail, string apsideMail, DateTime? resignationDate, int referrerId, int businessUnitId) + public CollaborateurSqlDto(int id, string name, string firstName, DateTime birthDate, EnumGenreSql gender, EnumStatutSql status, int childrenNumber, string address, string telephone, string personalMail, string apsideMail, DateTime? resignationDate, int businessUnitId) { Id = id; Name = name; @@ -50,7 +49,6 @@ public class CollaborateurSqlDto : IGenericIdSqlDto PersonalMail = personalMail; ApsideMail = apsideMail; ResignationDate = resignationDate; - ReferrerId = referrerId; BusinessUnitId = businessUnitId; } } \ No newline at end of file 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 11dd489..c81054c 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ReferencementSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ReferencementSqlDto.cs @@ -11,7 +11,7 @@ public class ReferencementSqlDto : IGenericIdSqlDto [Key] public int Id { get; set; } public DateTime StartingDate { get; set; } - public DateTime EndingDate { get; set; } + public DateTime? EndingDate { get; set; } public int ReferredId { get; set; } public int ReferrerId { get; set; } @@ -20,7 +20,7 @@ public class ReferencementSqlDto : IGenericIdSqlDto { } - public ReferencementSqlDto(int id, DateTime startingDate, DateTime endingDate, int referredId, int referrerId) + public ReferencementSqlDto(int id, DateTime startingDate, DateTime? endingDate, int referredId, int referrerId) { Id = id; StartingDate = startingDate; diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/MainDbContext.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/MainDbContext.cs index 59b5eea..f3dd2b8 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/MainDbContext.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/MainDbContext.cs @@ -32,6 +32,7 @@ public class MainDbContext : DbContext modelBuilder.Entity().Property(p => p.Id).UseMySqlIdentityColumn(); modelBuilder.Entity().Property(p => p.Id).UseMySqlIdentityColumn(); + modelBuilder .Entity() .Property(e => e.Issue) @@ -46,5 +47,7 @@ public class MainDbContext : DbContext .Entity() .Property(e => e.Status) .HasConversion(); + + modelBuilder.Entity().Property(p => p.Id).UseMySqlIdentityColumn(); } } \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/CollaborateurSqlRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/CollaborateurSqlRepository.cs index 7abfa46..90c71a2 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/CollaborateurSqlRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/CollaborateurSqlRepository.cs @@ -13,9 +13,6 @@ public class CollaborateurSqlRepository : GenericSqlRepository GetCollaborateursByBusinessUnit(int businessUnitId) => Context.Set().Where(collaborateur => collaborateur.BusinessUnitId == businessUnitId).ToList(); - public IList GetCollaborateursByReferrer(int referrerId) - => Context.Set().Where(collaborateur => collaborateur.ReferrerId == referrerId).ToList(); - public CollaborateurSqlDto? GetCollaborateurByApsideMail(string apsideMail) => Context?.Set().SingleOrDefault(collaborateur => collaborateur.ApsideMail == apsideMail); } \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/ReferencementSqlRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/ReferencementSqlRepository.cs new file mode 100644 index 0000000..7753be4 --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/ReferencementSqlRepository.cs @@ -0,0 +1,11 @@ +using espacecollab.backend.infrastructure.interfaces; +using espacecollab.backend.infrastructure.sql.dtos; + +namespace espacecollab.backend.infrastructure.sql.Repository; + +public class ReferencementSqlRepository: GenericSqlRepository, IReferencementRepository +{ + public ReferencementSqlRepository(MainDbContext context) : base(context) + { + } +} \ No newline at end of file