ajout de l'entité businessUnit

pull/7/head
Clement FERRERE 3 years ago
parent 09f21deee3
commit fa4e6668ff
  1. 4
      Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/AgencesController.cs
  2. 28
      Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/BusinessUnitsController.cs
  3. 4
      Collaborateur_Epa_Back/espacecollab.backend.api/Register.cs
  4. 8
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/BusinessUnitApiDto.cs
  5. 15
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/BusinessUnitMapper.cs
  6. 4
      Collaborateur_Epa_Back/espacecollab.backend.appservices/AgenceServices.cs
  7. 19
      Collaborateur_Epa_Back/espacecollab.backend.appservices/BusinessUnitServices.cs
  8. 1
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IBusinessUnitRepository.cs
  9. 4
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/MainDbContext.cs
  10. 13
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/BusinessUnitSqlRepository.cs

@ -3,9 +3,9 @@ using espacecollab.backend.appservices.dtos;
namespace espacecollab.backend.api.Controllers
{
public class AgenceController : BaseController<AgenceApiDto>
public class AgencesController : BaseController<AgenceApiDto>
{
public AgenceController(AgenceService agenceService) : base(agenceService)
public AgencesController(AgenceServices agenceService) : base(agenceService)
{
}
}

@ -0,0 +1,28 @@
using espacecollab.backend.appservices;
using espacecollab.backend.appservices.dtos;
using Microsoft.AspNetCore.Mvc;
namespace espacecollab.backend.api.Controllers
{
//[Route("api/[controller]")]
//[ApiController]
public class BusinessUnitsController : BaseController<BusinessUnitApiDto>
{
private BusinessUnitServices BusinessUnitServices { get; }
public BusinessUnitsController(BusinessUnitServices businessUnitServices) : base(businessUnitServices)
{
BusinessUnitServices = businessUnitServices;
}
[HttpGet("agence/{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,7 +13,8 @@ internal static class Register
{
services.AddCors();
services.AddScoped<CollaborateursServices>();
services.AddScoped<AgenceService>();
services.AddScoped<AgenceServices>();
services.AddScoped<BusinessUnitServices>();
if (contextOptions.LoadFake)
{
@ -25,6 +26,7 @@ internal static class Register
services.AddScoped<MainDbContext>();
services.AddScoped<ICollaborateurRepository, CollaborateurSqlRepository>();
services.AddScoped<IAgenceRepository, AgenceSqlRepository>();
services.AddScoped<IBusinessUnitRepository, BusinessUnitSqlRepository>();
}
}
}

@ -0,0 +1,8 @@
using espacecollab.backend.appservices.dtos.Interfaces;
namespace espacecollab.backend.appservices.dtos;
public record BusinessUnitApiDto(uint Id, string Name, int AgenceId) : IGenericIdApiDto
{
public uint Id { get; set; } = Id;
}

@ -0,0 +1,15 @@
using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.appservices.dtos.Mappers;
public static class BusinessUnitMapper
{
public static BusinessUnitApiDto ToApi(this BusinessUnitSqlDto agenceSqlDto)
{
return new BusinessUnitApiDto((uint)agenceSqlDto.Id, agenceSqlDto.Name,agenceSqlDto.AgenceId);
}
public static BusinessUnitSqlDto ToSql(this BusinessUnitApiDto agenceApiDto)
{
return new BusinessUnitSqlDto((int)agenceApiDto.Id, agenceApiDto.Name, agenceApiDto.AgenceId);
}
}

@ -5,9 +5,9 @@ using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.appservices;
public class AgenceService : GenericsServices<AgenceSqlDto, AgenceApiDto>
public class AgenceServices : GenericsServices<AgenceSqlDto, AgenceApiDto>
{
public AgenceService(IAgenceRepository agenceRepository)
public AgenceServices(IAgenceRepository agenceRepository)
:base(agenceRepository, AgenceMapper.ToApi, AgenceMapper.ToSql)
{
}

@ -0,0 +1,19 @@
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 BusinessUnitServices : GenericsServices<BusinessUnitSqlDto, BusinessUnitApiDto>
{
private IBusinessUnitRepository BusinessUnitRepository { get; }
public BusinessUnitServices(IBusinessUnitRepository businessUnitRepository)
:base(businessUnitRepository, BusinessUnitMapper.ToApi, BusinessUnitMapper.ToSql)
{}
public IEnumerable<BusinessUnitApiDto> GetBusinessUnitsByAgence(uint agenceId)
{
return BusinessUnitRepository.GetBusinessUnitsByAgence((int)agenceId).Select(bu => bu.ToApi());
}
}

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

@ -8,6 +8,8 @@ namespace espacecollab.backend.infrastructure.sql
{
private IOptions<SqlOption> SqlSettings { get; }
private DbSet<CollaborateurSqlDto>? Collaborateur { get; set; }
private DbSet<AgenceSqlDto>? Agence { get; set; }
private DbSet<BusinessUnitSqlDto>? BusinessUnit { get; set; }
public MainDbContext(IOptions<SqlOption> sqlSettings)
{
@ -23,6 +25,8 @@ namespace espacecollab.backend.infrastructure.sql
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<BusinessUnitSqlDto>().Property(p => p.Id).UseMySqlIdentityColumn();
modelBuilder.Entity<AgenceSqlDto>().Property(p => p.Id).UseMySqlIdentityColumn();
modelBuilder.Entity<CollaborateurSqlDto>().Property(p=> p.Id).UseMySqlIdentityColumn();
modelBuilder
.Entity<CollaborateurSqlDto>()

@ -0,0 +1,13 @@
using espacecollab.backend.infrastructure.interfaces;
using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.infrastructure.sql.Repository;
public class BusinessUnitSqlRepository : GenericSqlRepository<BusinessUnitSqlDto>, IBusinessUnitRepository
{
public BusinessUnitSqlRepository(MainDbContext context) : base(context)
{
}
public IList<BusinessUnitSqlDto> GetBusinessUnitsByAgence(int agenceId)
=> Context.Set<BusinessUnitSqlDto>().Where(bu => bu.AgenceId == agenceId).ToList();
}
Loading…
Cancel
Save