rework referencement

pull/13/head
Clement FERRERE 2 years ago
parent 2b92cb2fb2
commit 988a48a8cf
  1. 10
      Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs
  2. 13
      Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/ReferencementsController.cs
  3. 2
      Collaborateur_Epa_Back/espacecollab.backend.api/Register.cs
  4. 4
      Collaborateur_Epa_Back/espacecollab.backend.api/appsettings.json
  5. 2
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs
  6. 4
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/CollaborateurMapper.cs
  7. 15
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/ReferencementMapper.cs
  8. 12
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/ReferencementApiDto.cs
  9. 5
      Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursService.cs
  10. 18
      Collaborateur_Epa_Back/espacecollab.backend.appservices/ReferencementService.cs
  11. 17
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeCollaborateurRepository.cs
  12. 1
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/ICollaborateurRepository.cs
  13. 2
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IReferencementRepository.cs
  14. 4
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurSqlDto.cs
  15. 4
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ReferencementSqlDto.cs
  16. 3
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/MainDbContext.cs
  17. 3
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/CollaborateurSqlRepository.cs
  18. 11
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/ReferencementSqlRepository.cs

@ -71,16 +71,6 @@ public class CollaborateursController : BaseController<CollaborateurApiDto>
return Ok(collaborateurs); return Ok(collaborateurs);
} }
[HttpGet("referrer/{referrerId:int:min(1)}")]
public ActionResult<IEnumerable<CollaborateurApiDto>> GetCollaborateursByReferrer(uint referrerId)
{
IEnumerable<CollaborateurApiDto> collaborateurs = CollaborateursServices.GetCollaborateursByReferrer(referrerId);
if (!collaborateurs.Any())
return NotFound();
return Ok(collaborateurs);
}
[HttpGet("apsidemail/{apsideMail:minlength(1):regex(^\\S.*)}")] [HttpGet("apsidemail/{apsideMail:minlength(1):regex(^\\S.*)}")]
public ActionResult<CollaborateurApiDto> GetCollaborateurByApsideMail(string apsideMail) public ActionResult<CollaborateurApiDto> GetCollaborateurByApsideMail(string apsideMail)
{ {

@ -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<ReferencementApiDto>
{
public ReferencementsController(ReferencementService referencementServices) : base(referencementServices)
{
}
}

@ -17,6 +17,7 @@ internal static class Register
services.AddScoped<BusinessUnitService>(); services.AddScoped<BusinessUnitService>();
services.AddScoped<FonctionService>(); services.AddScoped<FonctionService>();
services.AddScoped<PeriodeEssaiService>(); services.AddScoped<PeriodeEssaiService>();
services.AddScoped<ReferencementService>();
if (contextOptions.LoadFake) if (contextOptions.LoadFake)
{ {
@ -35,6 +36,7 @@ internal static class Register
services.AddScoped<IFonctionRepository, FonctionSqlRepository>(); services.AddScoped<IFonctionRepository, FonctionSqlRepository>();
services.AddScoped<ITechnologieRepository, TechnologieSqlRepository>(); services.AddScoped<ITechnologieRepository, TechnologieSqlRepository>();
services.AddScoped<IPeriodeEssaiRepository, PeriodeEssaiSqlRepository>(); services.AddScoped<IPeriodeEssaiRepository, PeriodeEssaiSqlRepository>();
services.AddScoped<IReferencementRepository, ReferencementSqlRepository>();
} }
} }
} }

@ -8,8 +8,8 @@
"AllowedHosts": "*", "AllowedHosts": "*",
"Sql": { "Sql": {
"LoadFake": false, "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=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
} }
} }

@ -4,7 +4,7 @@ using espacecollab.backend.appservices.dtos.Values;
namespace espacecollab.backend.appservices.dtos; namespace espacecollab.backend.appservices.dtos;
public record CollaborateurApiDto(uint Id, string Name, string FirstName, DateTime BirthDate, EnumGenreApi Gender, EnumStatutApi Status, int ChildrenNumber, string Address, 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; public uint Id { get; set; } = Id;
} }

@ -9,7 +9,7 @@ public static class CollaborateurMapper
return new CollaborateurApiDto((uint)collaborateurSql.Id, collaborateurSql.Name, collaborateurSql.FirstName, return new CollaborateurApiDto((uint)collaborateurSql.Id, collaborateurSql.Name, collaborateurSql.FirstName,
collaborateurSql.BirthDate, collaborateurSql.Gender.ToEnumGenreApi(), collaborateurSql.Status.ToEnumStatutApi(), collaborateurSql.ChildrenNumber, collaborateurSql.BirthDate, collaborateurSql.Gender.ToEnumGenreApi(), collaborateurSql.Status.ToEnumStatutApi(), collaborateurSql.ChildrenNumber,
collaborateurSql.Address, collaborateurSql.Telephone, collaborateurSql.PersonalMail, collaborateurSql.ApsideMail, 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) 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, return new CollaborateurSqlDto((int)collaborateurApi.Id, collaborateurApi.Name, collaborateurApi.FirstName,
collaborateurApi.BirthDate, collaborateurApi.Gender.ToEnumGenreSql(), collaborateurApi.Status.ToEnumStatutSql(), collaborateurApi.ChildrenNumber, collaborateurApi.BirthDate, collaborateurApi.Gender.ToEnumGenreSql(), collaborateurApi.Status.ToEnumStatutSql(), collaborateurApi.ChildrenNumber,
collaborateurApi.Address, collaborateurApi.Telephone, collaborateurApi.PersonalMail, collaborateurApi.ApsideMail, collaborateurApi.Address, collaborateurApi.Telephone, collaborateurApi.PersonalMail, collaborateurApi.ApsideMail,
collaborateurApi.ResignationDate, collaborateurApi.ReferrerId, collaborateurApi.BusinessUnitId); collaborateurApi.ResignationDate, collaborateurApi.BusinessUnitId);
} }
} }

@ -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);
}
}

@ -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;
}

@ -57,11 +57,6 @@ public class CollaborateursService : GenericsServices<CollaborateurSqlDto, Colla
return CollaborateurRepository.GetCollaborateursByBusinessUnit((int)businessUnitId).Select(collaborateurSql => collaborateurSql.ToApi()); return CollaborateurRepository.GetCollaborateursByBusinessUnit((int)businessUnitId).Select(collaborateurSql => collaborateurSql.ToApi());
} }
public IEnumerable<CollaborateurApiDto> GetCollaborateursByReferrer(uint referrerId)
{
return CollaborateurRepository.GetCollaborateursByReferrer((int)referrerId).Select(collaborateurSql => collaborateurSql.ToApi());
}
public CollaborateurApiDto? GetCollaborateurByApsideMail(string apsideMail) public CollaborateurApiDto? GetCollaborateurByApsideMail(string apsideMail)
{ {
if (string.IsNullOrEmpty(apsideMail)) if (string.IsNullOrEmpty(apsideMail))

@ -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<ReferencementSqlDto, ReferencementApiDto>
{
private IReferencementRepository ReferencementRepository { get; }
public ReferencementService(IReferencementRepository referencementRepository)
: base(referencementRepository, ReferencementMapper.ToApi, ReferencementMapper.ToSql)
{
ReferencementRepository = referencementRepository;
}
}

@ -10,12 +10,12 @@ public class FakeCollaborateurRepository : GenericFakeRepository<CollaborateurSq
{ {
Context = new List<CollaborateurSqlDto> Context = new List<CollaborateurSqlDto>
{ {
new(1, "Dupont", "Jean", new DateTime(1980, 12, 10), //new(1, "Dupont", "Jean", new DateTime(1980, 12, 10),
EnumGenreSql.MASCULIN, EnumStatutSql.NONCADRE, 0, "1 rue du Louvre, 63000, Clermont-Ferrand", "0660258644", // 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), // "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), //new(2, "Michel", "Laura", new DateTime(1985, 08, 12),
EnumGenreSql.FEMININ, EnumStatutSql.NONCADRE, 0, "5 rue du Louvre, 63000, Clermont-Ferrand", "0660258644", // 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) // "laura.michel@gmail.com", "laura.michel@apside-groupe.com", new DateTime(2023, 12, 17), 1, 1)
}; };
} }
@ -26,11 +26,6 @@ public class FakeCollaborateurRepository : GenericFakeRepository<CollaborateurSq
return Context.Where(entity => entity.BusinessUnitId == businessUnitId).ToList(); return Context.Where(entity => entity.BusinessUnitId == businessUnitId).ToList();
} }
public IList<CollaborateurSqlDto> GetCollaborateursByReferrer(int referrerId)
{
return Context.Where(entity => entity.ReferrerId == referrerId).ToList();
}
public CollaborateurSqlDto GetCollaborateurByApsideMail(string apsideMail) public CollaborateurSqlDto GetCollaborateurByApsideMail(string apsideMail)
{ {
return Context.First(entity => entity.ApsideMail == apsideMail); return Context.First(entity => entity.ApsideMail == apsideMail);

@ -6,5 +6,4 @@ public interface ICollaborateurRepository : IGenericRepository<CollaborateurSqlD
{ {
CollaborateurSqlDto? GetCollaborateurByApsideMail(string apsideMail); CollaborateurSqlDto? GetCollaborateurByApsideMail(string apsideMail);
IList<CollaborateurSqlDto> GetCollaborateursByBusinessUnit(int businessUnitId); IList<CollaborateurSqlDto> GetCollaborateursByBusinessUnit(int businessUnitId);
IList<CollaborateurSqlDto> GetCollaborateursByReferrer(int referrerId);
} }

@ -4,6 +4,4 @@ namespace espacecollab.backend.infrastructure.interfaces;
public interface IReferencementRepository : IGenericRepository<ReferencementSqlDto> public interface IReferencementRepository : IGenericRepository<ReferencementSqlDto>
{ {
IList<CollaborateurSqlDto>? GetReferrersByCollaborateurId(int collaborateurId);
IList<CollaborateurSqlDto>? GetReferrersByCollaborateurApsideMail(string apsideMail);
} }

@ -22,7 +22,6 @@ public class CollaborateurSqlDto : IGenericIdSqlDto
public string PersonalMail { get; set; } public string PersonalMail { get; set; }
public string ApsideMail { get; set; } public string ApsideMail { get; set; }
public DateTime? ResignationDate { get; set; } public DateTime? ResignationDate { get; set; }
public int ReferrerId { get; set; }
public int BusinessUnitId { get; set; } public int BusinessUnitId { get; set; }
[ExcludeFromCodeCoverage] [ExcludeFromCodeCoverage]
@ -36,7 +35,7 @@ public class CollaborateurSqlDto : IGenericIdSqlDto
ApsideMail = string.Empty; 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; Id = id;
Name = name; Name = name;
@ -50,7 +49,6 @@ public class CollaborateurSqlDto : IGenericIdSqlDto
PersonalMail = personalMail; PersonalMail = personalMail;
ApsideMail = apsideMail; ApsideMail = apsideMail;
ResignationDate = resignationDate; ResignationDate = resignationDate;
ReferrerId = referrerId;
BusinessUnitId = businessUnitId; BusinessUnitId = businessUnitId;
} }
} }

@ -11,7 +11,7 @@ public class ReferencementSqlDto : IGenericIdSqlDto
[Key] [Key]
public int Id { get; set; } public int Id { get; set; }
public DateTime StartingDate { get; set; } public DateTime StartingDate { get; set; }
public DateTime EndingDate { get; set; } public DateTime? EndingDate { get; set; }
public int ReferredId { get; set; } public int ReferredId { get; set; }
public int ReferrerId { 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; Id = id;
StartingDate = startingDate; StartingDate = startingDate;

@ -32,6 +32,7 @@ public class MainDbContext : DbContext
modelBuilder.Entity<TechnologieSqlDto>().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(p => p.Id).UseMySqlIdentityColumn();
modelBuilder modelBuilder
.Entity<PeriodeEssaiSqlDto>() .Entity<PeriodeEssaiSqlDto>()
.Property(e => e.Issue) .Property(e => e.Issue)
@ -46,5 +47,7 @@ public class MainDbContext : DbContext
.Entity<CollaborateurSqlDto>() .Entity<CollaborateurSqlDto>()
.Property(e => e.Status) .Property(e => e.Status)
.HasConversion<string>(); .HasConversion<string>();
modelBuilder.Entity<ReferencementSqlDto>().Property(p => p.Id).UseMySqlIdentityColumn();
} }
} }

@ -13,9 +13,6 @@ public class CollaborateurSqlRepository : GenericSqlRepository<CollaborateurSqlD
public IList<CollaborateurSqlDto> GetCollaborateursByBusinessUnit(int businessUnitId) public IList<CollaborateurSqlDto> GetCollaborateursByBusinessUnit(int businessUnitId)
=> Context.Set<CollaborateurSqlDto>().Where(collaborateur => collaborateur.BusinessUnitId == businessUnitId).ToList(); => Context.Set<CollaborateurSqlDto>().Where(collaborateur => collaborateur.BusinessUnitId == businessUnitId).ToList();
public IList<CollaborateurSqlDto> GetCollaborateursByReferrer(int referrerId)
=> Context.Set<CollaborateurSqlDto>().Where(collaborateur => collaborateur.ReferrerId == referrerId).ToList();
public CollaborateurSqlDto? GetCollaborateurByApsideMail(string apsideMail) public CollaborateurSqlDto? GetCollaborateurByApsideMail(string apsideMail)
=> Context?.Set<CollaborateurSqlDto>().SingleOrDefault(collaborateur => collaborateur.ApsideMail == apsideMail); => Context?.Set<CollaborateurSqlDto>().SingleOrDefault(collaborateur => collaborateur.ApsideMail == apsideMail);
} }

@ -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<ReferencementSqlDto>, IReferencementRepository
{
public ReferencementSqlRepository(MainDbContext context) : base(context)
{
}
}
Loading…
Cancel
Save