refonte complète de l'agence et de la BU (inversion)

pull/11/head
Clement FERRERE 3 years ago
parent 75d62373ac
commit bc6daab6d1
  1. 18
      Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/AgencesController.cs
  2. 12
      Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/BusinessUnitsController.cs
  3. 4
      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/AgenceApiDto.cs
  6. 2
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/BusinessUnitApiDto.cs
  7. 4
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/AgenceMapper.cs
  8. 4
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/BusinessUnitMapper.cs
  9. 8
      Collaborateur_Epa_Back/espacecollab.backend.appservices/AgenceService.cs
  10. 7
      Collaborateur_Epa_Back/espacecollab.backend.appservices/BusinessUnitService.cs
  11. 22
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeAgenceRepository.cs
  12. 36
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeBusinessUnitRepository.cs
  13. 1
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IAgenceRepository.cs
  14. 1
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IBusinessUnitRepository.cs
  15. 4
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/AgenceSqlDto.cs
  16. 4
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/BusinessUnitSqlDto.cs
  17. 3
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/AgenceSqlRepository.cs
  18. 3
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/BusinessUnitSqlRepository.cs

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

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

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

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

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

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

@ -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();
}
Loading…
Cancel
Save