refonte_agence_bu #11

Merged
Clement.Ferrere merged 4 commits from refonte_agence_bu into develop 3 years ago
  1. 18
      Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/AgencesController.cs
  2. 4
      Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/BaseController.cs
  3. 12
      Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/BusinessUnitsController.cs
  4. 48
      Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs
  5. 4
      Collaborateur_Epa_Back/espacecollab.backend.api/Register.cs
  6. 2
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/AgenceApiDto.cs
  7. 2
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/BusinessUnitApiDto.cs
  8. 4
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/AgenceMapper.cs
  9. 4
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/BusinessUnitMapper.cs
  10. 0
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/CollaborateurMapper.cs
  11. 8
      Collaborateur_Epa_Back/espacecollab.backend.appservices/AgenceService.cs
  12. 7
      Collaborateur_Epa_Back/espacecollab.backend.appservices/BusinessUnitService.cs
  13. 37
      Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursService.cs
  14. 4
      Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs
  15. 22
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeAgenceRepository.cs
  16. 36
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeBusinessUnitRepository.cs
  17. 1
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IAgenceRepository.cs
  18. 1
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IBusinessUnitRepository.cs
  19. 4
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/AgenceSqlDto.cs
  20. 4
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/BusinessUnitSqlDto.cs
  21. 10
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/MainDbContext.cs
  22. 3
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/AgenceSqlRepository.cs
  23. 3
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/BusinessUnitSqlRepository.cs
  24. BIN
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/db/init_db.sql - Raccourci.lnk
  25. 9
      Collaborateur_Epa_Back/espacecollab.backend.sln

@ -1,11 +1,25 @@
using espacecollab.backend.appservices;
using espacecollab.backend.appservices.dtos;
using Microsoft.AspNetCore.Mvc;
namespace espacecollab.backend.api.Controllers;
public class AgencesController : BaseController<AgenceApiDto>
{
public AgencesController(AgenceService agenceService) : base(agenceService)
{
private AgenceService AgenceServices { get; }
public AgencesController(AgenceService agenceServices) : base(agenceServices)
{
AgenceServices = agenceServices;
}
[HttpGet("agences/{agenceId:int:min(1)}")]
public ActionResult<IEnumerable<AgenceApiDto>> GetAgencesByBusinessUnit(uint businessUnitId)
{
IEnumerable<AgenceApiDto> agences = AgenceServices.GetAgencesByBusinessUnit(businessUnitId);
if (!agences.Any())
return NotFound();
return Ok(agences);
}
}

@ -32,7 +32,7 @@ namespace espacecollab.backend.api.Controllers
}
[HttpPost]
public ActionResult<TO> Add(TO apiDto)
public virtual ActionResult<TO> 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<TO> Update(uint id, TO apiDto)
public virtual ActionResult<TO> Update(uint id, TO apiDto)
{
if (apiDto.Id != id)
return Unauthorized();

@ -8,21 +8,9 @@ namespace espacecollab.backend.api.Controllers
//[ApiController]
public class BusinessUnitsController : BaseController<BusinessUnitApiDto>
{
private BusinessUnitService BusinessUnitServices { get; }
public BusinessUnitsController(BusinessUnitService businessUnitServices) : base(businessUnitServices)
{
BusinessUnitServices = businessUnitServices;
}
[HttpGet("agences/{agenceId:int:min(1)}")]
public ActionResult<IEnumerable<BusinessUnitApiDto>> GetBusinessUnitsByAgence(uint agenceId)
{
IEnumerable<BusinessUnitApiDto> businessUnits = BusinessUnitServices.GetBusinessUnitsByAgence(agenceId);
if (!businessUnits.Any())
return NotFound();
return Ok(businessUnits);
}
}
}

@ -13,6 +13,54 @@ public class CollaborateursController : BaseController<CollaborateurApiDto>
CollaborateursServices = collaborateursServices;
}
[HttpPost]
public override ActionResult<CollaborateurApiDto> Add(CollaborateurApiDto apiDto)
{
(CollaborateurApiDto?,int) addedApiDto = CollaborateursServices.Add(apiDto);
if (addedApiDto.Item1 == null)
{
if(addedApiDto.Item2 == 1)
{
return Conflict("Erreur lors de la création du collaborateur : Le mail Apside renseigné est déjà utilisé pour un autre collaborateur.");
}
else if (addedApiDto.Item2 == 2)
{
return ValidationProblem("Erreur lors de la création du collaborateur : Erreur de validation de l'entité.");
}
else
return Problem("Erreur lors de la création du collaborateur : Problème interne");
}
return Ok(addedApiDto.Item1);
}
[HttpPut("{id:int:min(1)}")]
public override ActionResult<CollaborateurApiDto> Update(uint id, CollaborateurApiDto apiDto)
{
if (apiDto.Id != id)
return Unauthorized();
(CollaborateurApiDto?, int) updatedApiDto = CollaborateursServices.Update(apiDto);
if (updatedApiDto.Item1 == null)
{
if (updatedApiDto.Item2 == 1)
{
return NoContent();
}
else if (updatedApiDto.Item2 == 2)
{
return Conflict("Erreur lors de la mise à jour du collaborateur : Le mail Apside renseigné est déjà utilisé pour un autre collaborateur.");
}
else if (updatedApiDto.Item2 == 3)
{
return ValidationProblem("Erreur lors de la mise à jour du collaborateur : Erreur de validation de l'entité.");
}
else return Problem();
}
return Ok(updatedApiDto);
}
[HttpGet("businessunit/{businessUnitId:int:min(1)}")]
public ActionResult<IEnumerable<CollaborateurApiDto>> GetCollaborateursByBusinessUnit(uint businessUnitId)
{

@ -21,8 +21,8 @@ internal static class Register
if (contextOptions.LoadFake)
{
services.AddSingleton<ICollaborateurRepository, FakeCollaborateurRepository>();
services.AddSingleton<IAgenceRepository, FakeAgenceRepository>();
services.AddSingleton<IBusinessUnitRepository, FakeBusinessUnitRepository>();
//services.AddSingleton<IAgenceRepository, FakeAgenceRepository>();
//services.AddSingleton<IBusinessUnitRepository, FakeBusinessUnitRepository>();
services.AddSingleton<IFonctionRepository, FakeFonctionRepository>();
services.AddSingleton<IPeriodeEssaiRepository, FakePeriodeEssaiRepository>();
}

@ -2,7 +2,7 @@
namespace espacecollab.backend.appservices.dtos;
public record AgenceApiDto(uint Id, string Name) : IGenericIdApiDto
public record AgenceApiDto(uint Id, string Name, uint BusinessUnitId) : IGenericIdApiDto
{
public uint Id { get; set; } = Id;
}

@ -2,7 +2,7 @@
namespace espacecollab.backend.appservices.dtos;
public record BusinessUnitApiDto(uint Id, string Name, uint AgenceId) : IGenericIdApiDto
public record BusinessUnitApiDto(uint Id, string Name) : IGenericIdApiDto
{
public uint Id { get; set; } = Id;
}

@ -6,10 +6,10 @@ public static class AgenceMapper
{
public static AgenceApiDto ToApi(this AgenceSqlDto agenceSqlDto)
{
return new AgenceApiDto((uint)agenceSqlDto.Id, agenceSqlDto.Name);
return new AgenceApiDto((uint)agenceSqlDto.Id, agenceSqlDto.Name,(uint)agenceSqlDto.BusinessUnitId);
}
public static AgenceSqlDto ToSql(this AgenceApiDto agenceApiDto)
{
return new AgenceSqlDto((int)agenceApiDto.Id, agenceApiDto.Name);
return new AgenceSqlDto((int)agenceApiDto.Id, agenceApiDto.Name, (int)agenceApiDto.BusinessUnitId);
}
}

@ -6,10 +6,10 @@ public static class BusinessUnitMapper
{
public static BusinessUnitApiDto ToApi(this BusinessUnitSqlDto businessUnitSqlDto)
{
return new BusinessUnitApiDto((uint)businessUnitSqlDto.Id, businessUnitSqlDto.Name, (uint)businessUnitSqlDto.AgenceId);
return new BusinessUnitApiDto((uint)businessUnitSqlDto.Id, businessUnitSqlDto.Name);
}
public static BusinessUnitSqlDto ToSql(this BusinessUnitApiDto businessUnitApiDto)
{
return new BusinessUnitSqlDto((int)businessUnitApiDto.Id, businessUnitApiDto.Name, (int)businessUnitApiDto.AgenceId);
return new BusinessUnitSqlDto((int)businessUnitApiDto.Id, businessUnitApiDto.Name);
}
}

@ -7,8 +7,16 @@ namespace espacecollab.backend.appservices;
public class AgenceService : GenericsServices<AgenceSqlDto, AgenceApiDto>
{
private IAgenceRepository AgenceRepository { get; }
public AgenceService(IAgenceRepository agenceRepository)
: base(agenceRepository, AgenceMapper.ToApi, AgenceMapper.ToSql)
{
AgenceRepository = agenceRepository;
}
public IEnumerable<AgenceApiDto> GetAgencesByBusinessUnit(uint businessUnitId)
{
return AgenceRepository.GetAgencesByBusinessUnit((int)businessUnitId).Select(bu => bu.ToApi());
}
}

@ -7,14 +7,9 @@ namespace espacecollab.backend.appservices;
public class BusinessUnitService : GenericsServices<BusinessUnitSqlDto, BusinessUnitApiDto>
{
private IBusinessUnitRepository BusinessUnitRepository { get; }
public BusinessUnitService(IBusinessUnitRepository businessUnitRepository)
:base(businessUnitRepository, BusinessUnitMapper.ToApi, BusinessUnitMapper.ToSql)
{}
public IEnumerable<BusinessUnitApiDto> GetBusinessUnitsByAgence(uint agenceId)
{
return BusinessUnitRepository.GetBusinessUnitsByAgence((int)agenceId).Select(bu => bu.ToApi());
}
}

@ -15,6 +15,43 @@ public class CollaborateursService : GenericsServices<CollaborateurSqlDto, Colla
CollaborateurRepository = collaborateurRepository;
}
public (CollaborateurApiDto?,int) Add(CollaborateurApiDto apiDto)
{
if(GetAll().Where(collab => apiDto.ApsideMail == collab.ApsideMail).Any())
{
return (null,1);
}
CollaborateurSqlDto sqlDto = apiDto.ToSql();
CollaborateurSqlDto? entitySqlValidation = CollaborateurRepository.Add(sqlDto);
if (entitySqlValidation == null)
return (null,2);
return (entitySqlValidation.ToApi(),0);
}
public (CollaborateurApiDto?,int) Update(CollaborateurApiDto apiDto)
{
if (GetById(apiDto.Id) == null)
return (null,1);
if (GetAll().Where(collab => apiDto.ApsideMail == collab.ApsideMail && apiDto.Id != collab.Id).Any())
{
return (null,2);
}
CollaborateurSqlDto sqlDto = apiDto.ToSql();
CollaborateurSqlDto? sqlDtoValidation = CollaborateurRepository.Update(sqlDto);
if (sqlDtoValidation == null)
return (null,3);
return (sqlDtoValidation.ToApi(),0);
}
public IEnumerable<CollaborateurApiDto> GetCollaborateursByBusinessUnit(uint businessUnitId)
{
return CollaborateurRepository.GetCollaborateursByBusinessUnit((int)businessUnitId).Select(collaborateurSql => collaborateurSql.ToApi());

@ -34,7 +34,7 @@ public abstract class GenericsServices<T, TO> : IGenericsServices<TO> 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<T, TO> : IGenericsServices<TO> where T :
return MapperToApiDto(entitySqlValidation);
}
public TO? Update(TO apiDto)
public virtual TO? Update(TO apiDto)
{
if (GetById(apiDto.Id) == null)
return null;

@ -3,14 +3,14 @@ using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.infrastructure.fake;
public class FakeAgenceRepository : GenericFakeRepository<AgenceSqlDto>, IAgenceRepository
{
public FakeAgenceRepository()
{
Context = new List<AgenceSqlDto>
{
new(1, "Tours"),
new(2, "Clermont-Ferrand")
};
}
}
//public class FakeAgenceRepository : GenericFakeRepository<AgenceSqlDto>, IAgenceRepository
//{
// public FakeAgenceRepository()
// {
// Context = new List<AgenceSqlDto>
// {
// new(1, "Tours"),
// new(2, "Clermont-Ferrand")
// };
// }
//}

@ -1,21 +1,21 @@
using espacecollab.backend.infrastructure.interfaces;
using espacecollab.backend.infrastructure.sql.dtos;
//using espacecollab.backend.infrastructure.interfaces;
//using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.infrastructure.fake;
//namespace espacecollab.backend.infrastructure.fake;
public class FakeBusinessUnitRepository : GenericFakeRepository<BusinessUnitSqlDto>, IBusinessUnitRepository
{
public FakeBusinessUnitRepository()
{
Context = new List<BusinessUnitSqlDto>
{
new(1, "BU 1", 1),
new(2, "BU 2", 1)
};
}
//public class FakeBusinessUnitRepository : GenericFakeRepository<BusinessUnitSqlDto>, IBusinessUnitRepository
//{
// public FakeBusinessUnitRepository()
// {
// Context = new List<BusinessUnitSqlDto>
// {
// new(1, "BU 1", 1),
// new(2, "BU 2", 1)
// };
// }
public IList<BusinessUnitSqlDto> GetBusinessUnitsByAgence(int agenceId)
{
return Context.Where(c => c.AgenceId == agenceId).ToList();
}
}
// public IList<BusinessUnitSqlDto> GetBusinessUnitsByAgence(int agenceId)
// {
// return Context.Where(c => c.AgenceId == agenceId).ToList();
// }
//}

@ -4,4 +4,5 @@ namespace espacecollab.backend.infrastructure.interfaces;
public interface IAgenceRepository : IGenericRepository<AgenceSqlDto>
{
public IList<AgenceSqlDto> GetAgencesByBusinessUnit(int businessUnitId);
}

@ -4,5 +4,4 @@ namespace espacecollab.backend.infrastructure.interfaces;
public interface IBusinessUnitRepository : IGenericRepository<BusinessUnitSqlDto>
{
public IList<BusinessUnitSqlDto> GetBusinessUnitsByAgence(int agenceId);
}

@ -11,6 +11,7 @@ public class AgenceSqlDto : IGenericIdSqlDto
[Key]
public int Id { get; set; }
public string Name { get; set; }
public int BusinessUnitId { get; set; }
[ExcludeFromCodeCoverage]
@ -18,9 +19,10 @@ public class AgenceSqlDto : IGenericIdSqlDto
{
}
public AgenceSqlDto(int id, string name)
public AgenceSqlDto(int id, string name, int businessUnitId)
{
Id = id;
Name = name;
BusinessUnitId = businessUnitId;
}
}

@ -11,7 +11,6 @@ public class BusinessUnitSqlDto : IGenericIdSqlDto
[Key]
public int Id { get; set; }
public string Name { get; set; }
public int AgenceId { get; set; }
[ExcludeFromCodeCoverage]
@ -19,10 +18,9 @@ public class BusinessUnitSqlDto : IGenericIdSqlDto
{
}
public BusinessUnitSqlDto(int id, string name, int agenceId)
public BusinessUnitSqlDto(int id, string name)
{
Id = id;
Name = name;
AgenceId = agenceId;
}
}

@ -24,9 +24,19 @@ public class MainDbContext : DbContext
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<BusinessUnitSqlDto>().Property(p => p.Id).UseMySqlIdentityColumn();
modelBuilder.Entity<AgenceSqlDto>().Property(p => p.Id).UseMySqlIdentityColumn();
modelBuilder.Entity<FonctionSqlDto>().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(e => e.Issue)
.HasConversion<string>();
modelBuilder.Entity<CollaborateurSqlDto>().Property(p => p.Id).UseMySqlIdentityColumn();
modelBuilder
.Entity<CollaborateurSqlDto>()

@ -8,4 +8,7 @@ public class AgenceSqlRepository : GenericSqlRepository<AgenceSqlDto>, IAgenceRe
public AgenceSqlRepository(MainDbContext context) : base(context)
{
}
public IList<AgenceSqlDto> GetAgencesByBusinessUnit(int businessUnitId)
=> Context.Set<AgenceSqlDto>().Where(bu => bu.BusinessUnitId == businessUnitId).ToList();
}

@ -9,6 +9,5 @@ public class BusinessUnitSqlRepository : GenericSqlRepository<BusinessUnitSqlDto
{
}
public IList<BusinessUnitSqlDto> GetBusinessUnitsByAgence(int agenceId)
=> Context.Set<BusinessUnitSqlDto>().Where(bu => bu.AgenceId == agenceId).ToList();
}

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

Loading…
Cancel
Save