GetAll fonctionnel avec Fake Datas

pull/2/head
Clement FERRERE 3 years ago
parent faf2cccee7
commit 15d9b039fa
  1. 26
      Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursControllerTestGeneric.cs
  2. 43
      Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/GenericsController.cs
  3. 19
      Collaborateur_Epa_Back/espacecollab.backend.api/Startup.cs
  4. 2
      Collaborateur_Epa_Back/espacecollab.backend.api/appsettings.json
  5. 23
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs
  6. 17
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/GenericApiDtoBase.cs
  7. 12
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/CollaborateurApiDtoMapper.cs
  8. 26
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/EnumGenreMapper.cs
  9. 29
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/EnumStatutMapper.cs
  10. 73
      Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs
  11. 81
      Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs
  12. 15
      Collaborateur_Epa_Back/espacecollab.backend.appservices/IGenericsServices.cs
  13. 3
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/AgenceSqlDto.cs
  14. 4
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/BusinessUnitSqlDto.cs
  15. 3
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurAppartientBusinessUnitSqlDto.cs
  16. 1
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurCollaboreProjetSqlDto.cs
  17. 4
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurEstFonctionSqlDto.cs
  18. 3
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurSqlDto.cs
  19. 4
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/FonctionSqlDto.cs
  20. 8
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/IGenericSqlDto.cs
  21. 4
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/PeriodeEssaiSqlDto.cs
  22. 3
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetSqlDto.cs
  23. 1
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetUtiliseTechnologieSqlDto.cs
  24. 4
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ReferencementSqlDto.cs
  25. 3
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteDeveloppeProjetSqlDto.cs
  26. 5
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteSqlDto.cs
  27. 3
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/TechnologieSqlDto.cs
  28. 81
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/FakeRepo/FakeCollaborateurRepository.cs
  29. 34
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/CollaborateurRepository.cs
  30. 24
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/GenericRepository.cs
  31. 7
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/IGenericEntity.cs
  32. 1
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IAgenceRepository.cs
  33. 1
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IBusinessUnitRepository.cs
  34. 6
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/ICollaborateurRepository.cs
  35. 15
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IGenericRepository.cs
  36. 11
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/INotGenericRepository.cs
  37. 1
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IPeriodeEssaiRepository.cs
  38. 4
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IProjetRepository.cs

@ -0,0 +1,26 @@
using espacecollab.backend.appservices;
using espacecollab.backend.appservices.dtos;
using Microsoft.AspNetCore.Mvc;
namespace espacecollab.backend.api.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class CollaborateursControllerTestGeneric : ControllerBase
{
private CollaborateursServices CollaborateursServices { get; }
public CollaborateursControllerTestGeneric(CollaborateursServices collaborateursServices)
{
CollaborateursServices = collaborateursServices;
}
// GET: api/collaborateurs
//[HttpGet]
//public ActionResult<IEnumerable<CollaborateurApiDto>> GetCollaborateurs()
//{
// return CollaborateursServices.GetAll();
//}
}
}

@ -1,43 +0,0 @@
using espacecollab.backend.appservices;
using espacecollab.backend.appservices.dtos;
using espacecollab.backend.infrastructure.sql.SqlRepo;
using Microsoft.AspNetCore.Mvc;
namespace espacecollab.backend.api.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class GenericsController : ControllerBase
{
private GenericsServices GenericsServices { get; }
public GenericsController(GenericsServices genericsServices)
{
GenericsServices = genericsServices;
}
[HttpGet]
public IEnumerable<T> GetAll<T>() where T : class
{
return GenericsServices.GetAll<T>();
}
[HttpGet]
public T? GetById<T>(Guid id) where T : class, IGenericEntity
{
return GenericsServices.GetById<T>(id);
}
[HttpPost]
public T? Update<T>(T entity) where T : class, IGenericEntity
{
return GenericsServices.Update<T>(entity);
}
[HttpPost]
public T? Add<T>(T entity) where T : class
{
return GenericsServices.Add<T>(entity);
}
}
}

@ -1,5 +1,7 @@
using espacecollab.backend.appservices; using espacecollab.backend.appservices;
using espacecollab.backend.infrastructure.sql; using espacecollab.backend.infrastructure.sql;
using espacecollab.backend.infrastructure.sql.dtos;
using espacecollab.backend.infrastructure.sql.FakeRepo;
using espacecollab.backend.infrastructure.sql.Options; using espacecollab.backend.infrastructure.sql.Options;
using espacecollab.backend.infrastructure.sql.SqlRepo; using espacecollab.backend.infrastructure.sql.SqlRepo;
using espacecollab.backend.infrastructure.sql.SqlRepo.Interface; using espacecollab.backend.infrastructure.sql.SqlRepo.Interface;
@ -26,11 +28,20 @@ namespace Api
services.AddControllers(); services.AddControllers();
services.AddRouting(options => options.LowercaseUrls = true); services.AddRouting(options => options.LowercaseUrls = true);
if (contextOptions.LoadFake)
services.AddScoped<ICollaborateurRepository, CollaborateurRepository>(); {
services.AddScoped<IGenericRepository, GenericRepository>();
}
else
{
//services.AddScoped<ICollaborateurRepository, CollaborateurRepository>();
}
//services.AddScoped<IGenericRepository<CollaborateurSqlDto>, GenericRepository<CollaborateurSqlDto>>();
//services.AddScoped<IGenericRepository<CollaborateurSqlDto>, FakeCollaborateurRepository>();
services.AddScoped<ICollaborateurRepository, FakeCollaborateurRepository>();
services.AddScoped<CollaborateursServices>(); services.AddScoped<CollaborateursServices>();
services.AddScoped<MainDbContext>(); services.AddScoped<MainDbContext>();

@ -7,7 +7,7 @@
}, },
"AllowedHosts": "*", "AllowedHosts": "*",
"Sql": { "Sql": {
"LoadFake": false, "LoadFake": true,
"ConnectionString": "server=127.0.0.1;uid=root;pwd=root;database=collaborateur_epa" "ConnectionString": "server=127.0.0.1;uid=root;pwd=root;database=collaborateur_epa"
} }
} }

@ -1,4 +1,7 @@
namespace espacecollab.backend.appservices.dtos using espacecollab.backend.appservices.dtos.Mappers;
using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.appservices.dtos
{ {
public class CollaborateurApiDto public class CollaborateurApiDto
{ {
@ -17,8 +20,9 @@
public Guid ReferrerId { get; set; } public Guid ReferrerId { get; set; }
public Guid BusinessUnitId { get; set; } public Guid BusinessUnitId { get; set; }
private CollaborateurApiDto() public CollaborateurApiDto()
{ {
} }
public CollaborateurApiDto(Guid id, string name, string firstName, DateTime birthDate, EnumGenreApi gender, EnumStatutApi status, int childrenNumber, string address, string telephone, string personalMail, string apsideMail, DateTime resignationDate, Guid referrerId, Guid businessUnitId) public CollaborateurApiDto(Guid id, string name, string firstName, DateTime birthDate, EnumGenreApi gender, EnumStatutApi status, int childrenNumber, string address, string telephone, string personalMail, string apsideMail, DateTime resignationDate, Guid referrerId, Guid businessUnitId)
@ -38,5 +42,20 @@
ReferrerId = referrerId; ReferrerId = referrerId;
BusinessUnitId = businessUnitId; BusinessUnitId = businessUnitId;
} }
public CollaborateurApiDto(CollaborateurSqlDto entity)
{
}
//public override CollaborateurSqlDto ToEntity()
//{
// return new CollaborateurSqlDto(Id, Name, FirstName, BirthDate, Gender.ToEnumGenreSql(), Status.ToEnumStatutSql(), ChildrenNumber,
// Address, Telephone, PersonalMail, ApsideMail, ResignationDate, ReferrerId, BusinessUnitId);
//}
//public override CollaborateurApiDto FromEntity(CollaborateurSqlDto entity)
//{
// return this;
//}
} }
} }

@ -0,0 +1,17 @@
using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.appservices.dtos
{
public abstract class GenericApiDtoBase<T, To> where T : class, IGenericSqlDto
where To : GenericApiDtoBase<T, To>
{
public abstract T ToEntity();
public abstract To FromEntity(T entity);
public GenericApiDtoBase(T entity)
{
FromEntity(entity);
}
}
}

@ -2,14 +2,22 @@
namespace espacecollab.backend.appservices.dtos.Mappers namespace espacecollab.backend.appservices.dtos.Mappers
{ {
public static class CollaborateurApiDtoMapper public static class CollaborateurMapper
{ {
public static CollaborateurApiDto ToCollaborateurApi(this CollaborateurSqlDto collaborateurSql) public static CollaborateurApiDto ToApi(this CollaborateurSqlDto collaborateurSql)
{ {
return new CollaborateurApiDto(collaborateurSql.Id, collaborateurSql.Name, collaborateurSql.FirstName, return new CollaborateurApiDto(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.ReferrerId, collaborateurSql.BusinessUnitId);
} }
public static CollaborateurSqlDto ToSql(this CollaborateurApiDto collaborateurApi)
{
return new CollaborateurSqlDto(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);
}
} }
} }

@ -6,18 +6,24 @@ namespace espacecollab.backend.appservices.dtos.Mappers
{ {
public static EnumGenreApi ToEnumGenreApi(this EnumGenreSql enumGenreSql) public static EnumGenreApi ToEnumGenreApi(this EnumGenreSql enumGenreSql)
{ {
switch (enumGenreSql) return enumGenreSql switch
{ {
case EnumGenreSql.MASCULIN: EnumGenreSql.MASCULIN => EnumGenreApi.MASCULIN,
return EnumGenreApi.MASCULIN; EnumGenreSql.FEMININ => EnumGenreApi.FEMININ,
case EnumGenreSql.FEMININ: EnumGenreSql.AUTRE => EnumGenreApi.AUTRE,
return EnumGenreApi.FEMININ; _ => EnumGenreApi.AUTRE,
case EnumGenreSql.AUTRE: };
return EnumGenreApi.AUTRE; }
default:
return EnumGenreApi.AUTRE;
}
public static EnumGenreSql ToEnumGenreSql(this EnumGenreApi enumGenreApi)
{
return enumGenreApi switch
{
EnumGenreApi.MASCULIN => EnumGenreSql.MASCULIN,
EnumGenreApi.FEMININ => EnumGenreSql.FEMININ,
EnumGenreApi.AUTRE => EnumGenreSql.AUTRE,
_ => EnumGenreSql.AUTRE,
};
} }
} }
} }

@ -6,19 +6,26 @@ namespace espacecollab.backend.appservices.dtos.Mappers
{ {
public static EnumStatutApi ToEnumStatutApi(this EnumStatutSql enumStatutSql) public static EnumStatutApi ToEnumStatutApi(this EnumStatutSql enumStatutSql)
{ {
switch (enumStatutSql) return enumStatutSql switch
{ {
case EnumStatutSql.STAGIAIRE: EnumStatutSql.STAGIAIRE => EnumStatutApi.STAGIAIRE,
return EnumStatutApi.STAGIAIRE; EnumStatutSql.NONCADRE => EnumStatutApi.NONCADRE,
case EnumStatutSql.NONCADRE: EnumStatutSql.CADRE => EnumStatutApi.CADRE,
return EnumStatutApi.NONCADRE; EnumStatutSql.ALTERNANT => EnumStatutApi.ALTERNANT,
case EnumStatutSql.CADRE: _ => EnumStatutApi.NONCADRE,
return EnumStatutApi.CADRE; };
case EnumStatutSql.ALTERNANT: }
return EnumStatutApi.ALTERNANT;
default: return EnumStatutApi.NONCADRE;
}
public static EnumStatutSql ToEnumStatutSql(this EnumStatutApi enumStatutApi)
{
return enumStatutApi switch
{
EnumStatutApi.STAGIAIRE => EnumStatutSql.STAGIAIRE,
EnumStatutApi.NONCADRE => EnumStatutSql.NONCADRE,
EnumStatutApi.CADRE => EnumStatutSql.CADRE,
EnumStatutApi.ALTERNANT => EnumStatutSql.ALTERNANT,
_ => EnumStatutSql.NONCADRE,
};
} }
} }
} }

@ -1,5 +1,8 @@
using espacecollab.backend.appservices.dtos; using espacecollab.backend.appservices.dtos;
using espacecollab.backend.appservices.dtos.Mappers; using espacecollab.backend.appservices.dtos.Mappers;
using espacecollab.backend.infrastructure.sql.dtos;
using espacecollab.backend.infrastructure.sql.FakeRepo;
using espacecollab.backend.infrastructure.sql.SqlRepo;
using espacecollab.backend.infrastructure.sql.SqlRepo.Interface; using espacecollab.backend.infrastructure.sql.SqlRepo.Interface;
namespace espacecollab.backend.appservices namespace espacecollab.backend.appservices
@ -8,14 +11,78 @@ namespace espacecollab.backend.appservices
{ {
private ICollaborateurRepository CollaborateurRepository { get; } private ICollaborateurRepository CollaborateurRepository { get; }
public CollaborateursServices(ICollaborateurRepository collaborateurRepository) public CollaborateursServices(ICollaborateurRepository collaborateur)
{ {
CollaborateurRepository = collaborateurRepository; CollaborateurRepository = collaborateur;
} }
public IEnumerable<CollaborateurApiDto> GetCollaborateurs() public IEnumerable<CollaborateurApiDto> GetCollaborateurs()
{ {
return CollaborateurRepository.GetAllCollaborateurs().Select(collaborateurSql => collaborateurSql.ToCollaborateurApi()); return CollaborateurRepository.GetAll().Select(collaborateurSql => collaborateurSql.ToApi());
} }
public CollaborateurApiDto? GetCollaborateurById(Guid id)
{
return CollaborateurRepository.GetById(id)?.ToApi();
}
public CollaborateurApiDto? AddCollaborateur(CollaborateurApiDto collaborateurApi)
{
CollaborateurSqlDto collaborateurSql = collaborateurApi.ToSql();
if (collaborateurSql == null)
return null;
CollaborateurRepository.Add(collaborateurSql);
return collaborateurApi;
}
public CollaborateurApiDto? DeleteCollaborateur(CollaborateurApiDto collaborateurApi)
{
CollaborateurSqlDto collaborateurSql = collaborateurApi.ToSql();
if (collaborateurSql == null)
return null;
CollaborateurRepository.Delete(collaborateurSql);
return collaborateurApi;
}
//public new CollaborateurSqlDto? Delete(CollaborateurSqlDto entity)
//{
// Collaborateurs.Remove(entity);
// return entity;
//}
//public new IEnumerable<CollaborateurSqlDto> GetAll()
//{
// return Collaborateurs;
//}
//public new CollaborateurSqlDto? Update(CollaborateurSqlDto collaborateur)
//{
// CollaborateurSqlDto? oldCollab = Collaborateurs.FirstOrDefault(entity => entity.Id == collaborateur.Id);
// if (oldCollab == null)
// {
// Collaborateurs.Add(collaborateur);
// return collaborateur;
// }
// Collaborateurs.Remove(oldCollab);
// Collaborateurs.Add(collaborateur);
// return collaborateur;
//}
////méthodes spécifiques à l'interface ICollaborateurRepository
//public IList<CollaborateurSqlDto>? GetCollaborateursByBusinessUnit(Guid businessUnitId)
//{
// return Collaborateurs.Where(entity => entity.BusinessUnitId == businessUnitId).ToList();
//}
//public IList<CollaborateurSqlDto>? GetCollaborateursByReferrer(Guid referrerId)
//{
// return Collaborateurs.Where(entity => entity.ReferrerId == referrerId).ToList();
//}
//public CollaborateurSqlDto? GetCollaborateurByApsideMail(string apsideMail)
//{
// return Collaborateurs.FirstOrDefault(entity => entity.ApsideMail == apsideMail);
//}
} }
} }

@ -1,42 +1,49 @@
using espacecollab.backend.infrastructure.sql.SqlRepo; using espacecollab.backend.appservices.dtos;
using espacecollab.backend.infrastructure.sql.dtos;
using espacecollab.backend.infrastructure.sql.SqlRepo.Interface; using espacecollab.backend.infrastructure.sql.SqlRepo.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace espacecollab.backend.appservices namespace espacecollab.backend.appservices
{ {
public class GenericsServices //public abstract class GenericsServices<T, To> where T : class, IGenericSqlDto
{ // where To : GenericApiDtoBase<T, To>, new()
private IGenericRepository genericRepository { get; } //{
// private IGenericRepository GenericRepository { get; }
public GenericsServices(IGenericRepository genericRepository)
{ // public GenericsServices(IGenericRepository genericRepository)
this.genericRepository = genericRepository; // {
} // GenericRepository = genericRepository;
// }
public T? Add<T>(T entity) where T : class
{ // public To? Add(To apiDto)
return genericRepository.Add<T>(entity); // {
} // T? entity = GenericRepository.Add(apiDto.ToEntity());
// if (entity == null)
public IEnumerable<T> GetAll<T>() where T : class // return null;
{
return genericRepository.GetAll<T>(); // return new To().FromEntity(entity);
} // }
public T? GetById<T>(Guid id) where T : class, IGenericEntity // public IEnumerable<T> GetAll<T>() where T : class, IGenericSqlDto
{ // {
return genericRepository.GetById<T>(id); // return GenericRepository.GetAll<T>();
} // }
public T? Update<T>(T entity) where T : class, IGenericEntity // public To? GetById<T>(Guid id) where T : class, IGenericSqlDto
{ // {
return genericRepository.Update<T>(entity); // T? entity = GenericRepository.GetById<T>(id);
} // if (entity == null)
// return null;
} // return new To().FromEntity(entity);
// }
// public To? Update(To apiDto)
// {
// T? entity = GenericRepository.Update<T>(apiDto.ToEntity());
// if (entity == null)
// return null;
// return new To().FromEntity(entity);
// }
//}
} }

@ -0,0 +1,15 @@
using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.appservices
{
public interface IGenericsServices<T, To> where T : class, IGenericSqlDto
{
To? Add(T entity);
IEnumerable<To> GetAll();
To? GetById(Guid id);
To? Update(T entity);
}
}

@ -2,7 +2,7 @@
namespace espacecollab.backend.infrastructure.sql.dtos namespace espacecollab.backend.infrastructure.sql.dtos
{ {
public class AgenceSqlDto public class AgenceSqlDto : IGenericSqlDto
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public string Name { get; set; } public string Name { get; set; }
@ -18,5 +18,6 @@ namespace espacecollab.backend.infrastructure.sql.dtos
Id = id; Id = id;
Name = name; Name = name;
} }
} }
} }

@ -2,7 +2,7 @@
namespace espacecollab.backend.infrastructure.sql.dtos namespace espacecollab.backend.infrastructure.sql.dtos
{ {
public class BusinessUnitSqlDto public class BusinessUnitSqlDto : IGenericSqlDto
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public string Name { get; set; } public string Name { get; set; }
@ -20,5 +20,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos
Name = name; Name = name;
AgenceId = agenceId; AgenceId = agenceId;
} }
} }
} }

@ -7,6 +7,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos.Associations
public Guid CollaborateurId { get; set; } public Guid CollaborateurId { get; set; }
public Guid BusinessUnitId { get; set; } public Guid BusinessUnitId { get; set; }
[ExcludeFromCodeCoverage] [ExcludeFromCodeCoverage]
private CollaborateurAppartientBusinessUnitSqlDto() private CollaborateurAppartientBusinessUnitSqlDto()
{ {
@ -17,5 +18,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos.Associations
CollaborateurId = collaborateurId; CollaborateurId = collaborateurId;
BusinessUnitId = businessUnitId; BusinessUnitId = businessUnitId;
} }
} }
} }

@ -19,5 +19,6 @@ namespace espacecollab.backend.infrastructure.sql.dtos
ProjetId = projetId; ProjetId = projetId;
IsManager = isManager; IsManager = isManager;
} }
} }
} }

@ -2,7 +2,7 @@
namespace espacecollab.backend.infrastructure.sql.dtos.Associations namespace espacecollab.backend.infrastructure.sql.dtos.Associations
{ {
public class CollaborateurEstFonctionSqlDto public class CollaborateurEstFonctionSqlDto
{ {
public Guid CollaborateurId { get; set; } public Guid CollaborateurId { get; set; }
public Guid FonctionId { get; set; } public Guid FonctionId { get; set; }
@ -17,5 +17,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos.Associations
CollaborateurId = collaborateurId; CollaborateurId = collaborateurId;
FonctionId = fonctionId; FonctionId = fonctionId;
} }
} }
} }

@ -2,7 +2,7 @@
namespace espacecollab.backend.infrastructure.sql.dtos namespace espacecollab.backend.infrastructure.sql.dtos
{ {
public class CollaborateurSqlDto public class CollaborateurSqlDto : IGenericSqlDto
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public string Name { get; set; } public string Name { get; set; }
@ -41,5 +41,6 @@ namespace espacecollab.backend.infrastructure.sql.dtos
ReferrerId = referrerId; ReferrerId = referrerId;
BusinessUnitId = businessUnitId; BusinessUnitId = businessUnitId;
} }
} }
} }

@ -2,7 +2,7 @@
namespace espacecollab.backend.infrastructure.sql.dtos namespace espacecollab.backend.infrastructure.sql.dtos
{ {
public class FonctionSqlDto public class FonctionSqlDto : IGenericSqlDto
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public string Name { get; set; } public string Name { get; set; }
@ -17,5 +17,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos
Id = id; Id = id;
Name = name; Name = name;
} }
} }
} }

@ -0,0 +1,8 @@
namespace espacecollab.backend.infrastructure.sql.dtos
{
public interface IGenericSqlDto
{
public Guid Id { get; set; }
}
}

@ -2,7 +2,7 @@
namespace espacecollab.backend.infrastructure.sql.dtos namespace espacecollab.backend.infrastructure.sql.dtos
{ {
public class PeriodeEssaiSqlDto public class PeriodeEssaiSqlDto : IGenericSqlDto
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public DateTime StartingDate { get; set; } public DateTime StartingDate { get; set; }
@ -27,5 +27,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos
Issue = issue; Issue = issue;
CollaborateurId = collaborateurId; CollaborateurId = collaborateurId;
} }
} }
} }

@ -2,7 +2,7 @@
namespace espacecollab.backend.infrastructure.sql.dtos namespace espacecollab.backend.infrastructure.sql.dtos
{ {
public class ProjetSqlDto public class ProjetSqlDto : IGenericSqlDto
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public string Name { get; set; } public string Name { get; set; }
@ -25,5 +25,6 @@ namespace espacecollab.backend.infrastructure.sql.dtos
StartingDate = startingDate; StartingDate = startingDate;
EndingDate = endingDate; EndingDate = endingDate;
} }
} }
} }

@ -17,5 +17,6 @@ namespace espacecollab.backend.infrastructure.sql.dtos
ProjetId = projetId; ProjetId = projetId;
TechnologieId = technologieId; TechnologieId = technologieId;
} }
} }
} }

@ -2,7 +2,7 @@
namespace espacecollab.backend.infrastructure.sql.dtos namespace espacecollab.backend.infrastructure.sql.dtos
{ {
public class ReferencementSqlDto public class ReferencementSqlDto : IGenericSqlDto
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public DateTime StartingDate { get; set; } public DateTime StartingDate { get; set; }
@ -23,5 +23,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos
ReferredId = referredId; ReferredId = referredId;
ReferrerId = referrerId; ReferrerId = referrerId;
} }
} }
} }

@ -17,5 +17,8 @@ namespace espacecollab.backend.infrastructure.sql.dtos
SiteId = siteId; SiteId = siteId;
ProjetId = projetId; ProjetId = projetId;
} }
} }
} }

@ -2,7 +2,7 @@
namespace espacecollab.backend.infrastructure.sql.dtos namespace espacecollab.backend.infrastructure.sql.dtos
{ {
public class SiteSqlDto public class SiteSqlDto : IGenericSqlDto
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public string Name { get; set; } public string Name { get; set; }
@ -21,5 +21,8 @@ namespace espacecollab.backend.infrastructure.sql.dtos
Address = address; Address = address;
BusinessUnitId = businessUnitId; BusinessUnitId = businessUnitId;
} }
} }
} }

@ -2,7 +2,7 @@
namespace espacecollab.backend.infrastructure.sql.dtos namespace espacecollab.backend.infrastructure.sql.dtos
{ {
public class TechnologieSqlDto public class TechnologieSqlDto : IGenericSqlDto
{ {
public Guid Id { get; set; } public Guid Id { get; set; }
public string Name { get; set; } public string Name { get; set; }
@ -17,5 +17,6 @@ namespace espacecollab.backend.infrastructure.sql.dtos
Id = id; Id = id;
Name = name; Name = name;
} }
} }
} }

@ -0,0 +1,81 @@
using espacecollab.backend.infrastructure.sql.dtos;
using espacecollab.backend.infrastructure.sql.SqlRepo;
using espacecollab.backend.infrastructure.sql.SqlRepo.Interface;
namespace espacecollab.backend.infrastructure.sql.FakeRepo
{
public class FakeCollaborateurRepository : GenericRepository<CollaborateurSqlDto>, ICollaborateurRepository
{
private List<CollaborateurSqlDto> Collaborateurs { get; set; }
//Context obligatoire car le Generic Repository en a un.
public FakeCollaborateurRepository()
{
Collaborateurs = new List<CollaborateurSqlDto>
{
new CollaborateurSqlDto(new Guid(), "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), new Guid(), new Guid()),
new CollaborateurSqlDto(new Guid(), "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), new Guid(), new Guid())
};
}
//redéfinition des méthodes du GenericRepository pour fonctionner avec Fake
public new CollaborateurSqlDto? GetById(Guid id)
{
return Collaborateurs.FirstOrDefault(entity => entity.Id == id);
}
public new CollaborateurSqlDto? Add(CollaborateurSqlDto entity)
{
Collaborateurs.Add(entity);
return entity;
}
public new CollaborateurSqlDto? Delete(CollaborateurSqlDto entity)
{
Collaborateurs.Remove(entity);
return entity;
}
public new IEnumerable<CollaborateurSqlDto> GetAll()
{
return Collaborateurs;
}
public new CollaborateurSqlDto? Update(CollaborateurSqlDto collaborateur)
{
CollaborateurSqlDto? oldCollab = Collaborateurs.FirstOrDefault(entity => entity.Id == collaborateur.Id);
if (oldCollab == null)
{
Collaborateurs.Add(collaborateur);
return collaborateur;
}
Collaborateurs.Remove(oldCollab);
Collaborateurs.Add(collaborateur);
return collaborateur;
}
//méthodes spécifiques à l'interface ICollaborateurRepository
public IList<CollaborateurSqlDto>? GetCollaborateursByBusinessUnit(Guid businessUnitId)
{
return Collaborateurs.Where(entity => entity.BusinessUnitId == businessUnitId).ToList();
}
public IList<CollaborateurSqlDto>? GetCollaborateursByReferrer(Guid referrerId)
{
return Collaborateurs.Where(entity => entity.ReferrerId == referrerId).ToList();
}
public CollaborateurSqlDto? GetCollaborateurByApsideMail(string apsideMail)
{
return Collaborateurs.FirstOrDefault(entity => entity.ApsideMail == apsideMail);
}
}
}

@ -3,50 +3,22 @@ using espacecollab.backend.infrastructure.sql.SqlRepo.Interface;
namespace espacecollab.backend.infrastructure.sql.SqlRepo namespace espacecollab.backend.infrastructure.sql.SqlRepo
{ {
public class CollaborateurRepository : ICollaborateurRepository public class CollaborateurRepository : GenericRepository<CollaborateurSqlDto>,ICollaborateurRepository
{ {
private MainDbContext Context { get; } private MainDbContext Context { get; }
public CollaborateurRepository(MainDbContext context) public CollaborateurRepository(MainDbContext context) : base(context)
{ {
Context = context; Context = context;
} }
/* TODO Récupération des collaborateurs par agence directement dans le service Collaborateur */
public CollaborateurSqlDto? AddCollaborateur(CollaborateurSqlDto newCollaborateur)
{
CollaborateurSqlDto? collaborateurAlreadyExists = Context.Collaborateur?.FirstOrDefault(c => c.Id == newCollaborateur.Id);
if (collaborateurAlreadyExists != null)
return null;
Context.Set<CollaborateurSqlDto>().Add(newCollaborateur);
Context.SaveChanges();
return Context.Set<CollaborateurSqlDto>().FirstOrDefault(c => c.Id == newCollaborateur.Id);
}
public IList<CollaborateurSqlDto>? GetAllCollaborateurs()
=> Context.Set<CollaborateurSqlDto>().ToList();
public IList<CollaborateurSqlDto>? GetCollaborateursByBusinessUnit(Guid businessUnitId) public IList<CollaborateurSqlDto>? GetCollaborateursByBusinessUnit(Guid businessUnitId)
=> Context.Set<CollaborateurSqlDto>().Where(collaborateur => collaborateur.BusinessUnitId == businessUnitId).ToList(); => Context.Set<CollaborateurSqlDto>().Where(collaborateur => collaborateur.BusinessUnitId == businessUnitId).ToList();
public IList<CollaborateurSqlDto>? GetCollaborateursByReferrer(Guid referrerId) public IList<CollaborateurSqlDto>? GetCollaborateursByReferrer(Guid referrerId)
=> Context.Set<CollaborateurSqlDto>().Where(collaborateur => collaborateur.ReferrerId == referrerId).ToList(); => Context.Set<CollaborateurSqlDto>().Where(collaborateur => collaborateur.ReferrerId == referrerId).ToList();
public CollaborateurSqlDto? GetCollaborateurById(Guid id)
=> Context?.Set<CollaborateurSqlDto>().SingleOrDefault(collaborateur => collaborateur.Id == id);
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);
public CollaborateurSqlDto? UpdateCollaborateur(CollaborateurSqlDto newCollaborateur)
{
Context.Set<CollaborateurSqlDto>().Update(newCollaborateur);
Context.SaveChanges();
return Context.Set<CollaborateurSqlDto>().FirstOrDefault(c => c.Id == newCollaborateur.Id);
}
} }
} }

@ -1,36 +1,48 @@
using espacecollab.backend.infrastructure.sql.SqlRepo.Interface; using espacecollab.backend.infrastructure.sql.dtos;
using espacecollab.backend.infrastructure.sql.SqlRepo.Interface;
namespace espacecollab.backend.infrastructure.sql.SqlRepo namespace espacecollab.backend.infrastructure.sql.SqlRepo
{ {
public class GenericRepository : IGenericRepository public class GenericRepository<T> : IGenericRepository<T> where T : class, IGenericSqlDto
{ {
private MainDbContext Context { get; } private MainDbContext Context { get; }
public GenericRepository()
{
}
public GenericRepository(MainDbContext context) public GenericRepository(MainDbContext context)
{ {
Context = context; Context = context;
} }
public T? Add<T>(T entity) where T : class public virtual T? Add(T entity)
{ {
return Context.Set<T>().Add(entity) as T; return Context.Set<T>().Add(entity) as T;
} }
public IList<T> GetAll<T>() where T : class public virtual T? Delete(T entity)
{
return Context.Set<T>().Remove(entity) as T;
}
public virtual IEnumerable<T> GetAll()
{ {
return Context.Set<T>().ToList(); return Context.Set<T>().ToList();
} }
public T? GetById<T>(Guid id) where T : class,IGenericEntity public virtual T? GetById(Guid id)
{ {
return Context.Set<T>().FirstOrDefault(entity => entity.Id == id); return Context.Set<T>().FirstOrDefault(entity => entity.Id == id);
} }
public T? Update<T>(T entity) where T : class, IGenericEntity public virtual T? Update(T entity)
{ {
Context.Set<T>().Update(entity); Context.Set<T>().Update(entity);
Context.SaveChanges(); Context.SaveChanges();
return Context.Set<T>().FirstOrDefault(e => e.Id == entity.Id); return Context.Set<T>().FirstOrDefault(e => e.Id == entity.Id);
} }
} }
} }

@ -1,7 +0,0 @@
namespace espacecollab.backend.infrastructure.sql.SqlRepo
{
public interface IGenericEntity
{
public Guid Id { get; set; }
}
}

@ -4,6 +4,7 @@ namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface
{ {
public interface IAgenceRepository public interface IAgenceRepository
{ {
//inutile !
AgenceSqlDto? AddAgence(AgenceSqlDto newAgence); AgenceSqlDto? AddAgence(AgenceSqlDto newAgence);
IList<AgenceSqlDto>? GetAllAgences(); IList<AgenceSqlDto>? GetAllAgences();
AgenceSqlDto? GetAgenceById(AgenceSqlDto agence); AgenceSqlDto? GetAgenceById(AgenceSqlDto agence);

@ -4,6 +4,7 @@ namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface
{ {
public interface IBusinessUnitRepository public interface IBusinessUnitRepository
{ {
//inutile !
BusinessUnitSqlDto? AddBusinessUnit(BusinessUnitSqlDto newBusinessUnit); BusinessUnitSqlDto? AddBusinessUnit(BusinessUnitSqlDto newBusinessUnit);
IList<BusinessUnitSqlDto>? GetAllBusinessUnits(); IList<BusinessUnitSqlDto>? GetAllBusinessUnits();
BusinessUnitSqlDto? GetBusinessUnitById(BusinessUnitSqlDto businessUnit); BusinessUnitSqlDto? GetBusinessUnitById(BusinessUnitSqlDto businessUnit);

@ -2,14 +2,10 @@
namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface
{ {
public interface ICollaborateurRepository public interface ICollaborateurRepository : IGenericRepository<CollaborateurSqlDto>
{ {
CollaborateurSqlDto? AddCollaborateur(CollaborateurSqlDto newCollaborateur);
IList<CollaborateurSqlDto>? GetAllCollaborateurs();
CollaborateurSqlDto? GetCollaborateurByApsideMail(string apsideMail); CollaborateurSqlDto? GetCollaborateurByApsideMail(string apsideMail);
CollaborateurSqlDto? GetCollaborateurById(Guid id);
IList<CollaborateurSqlDto>? GetCollaborateursByBusinessUnit(Guid businessUnitId); IList<CollaborateurSqlDto>? GetCollaborateursByBusinessUnit(Guid businessUnitId);
IList<CollaborateurSqlDto>? GetCollaborateursByReferrer(Guid referrerId); IList<CollaborateurSqlDto>? GetCollaborateursByReferrer(Guid referrerId);
CollaborateurSqlDto? UpdateCollaborateur(CollaborateurSqlDto newCollaborateur);
} }
} }

@ -1,11 +1,14 @@
namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface
{ {
public interface IGenericRepository public interface IGenericRepository<T> where T : class, IGenericSqlDto
{ {
T? Add<T>(T entity) where T : class; T? Add(T entity);
IList<T> GetAll<T>() where T : class; T? Delete(T entity);
T? GetById<T>(Guid id) where T : class, IGenericEntity; IEnumerable<T> GetAll();
T? Update<T>(T entity) where T : class, IGenericEntity; T? GetById(Guid id);
T? Update(T entity);

@ -1,11 +0,0 @@
using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface
{
public interface INotGenericRepository
{
CollaborateurSqlDto? GetCollaborateurByApsideMail(string apsideMail);
IList<CollaborateurSqlDto>? GetCollaborateursByBusinessUnit(Guid businessUnitId);
IList<CollaborateurSqlDto>? GetCollaborateursByReferrer(Guid referrerId);
}
}

@ -4,6 +4,7 @@ namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface
{ {
public interface IPeriodeEssaiRepository public interface IPeriodeEssaiRepository
{ {
//inutile !
PeriodeEssaiSqlDto? AddPeriodeEssai(PeriodeEssaiSqlDto newPeriodeEssai); PeriodeEssaiSqlDto? AddPeriodeEssai(PeriodeEssaiSqlDto newPeriodeEssai);
IList<PeriodeEssaiSqlDto>? GetAllPeriodeEssais(); IList<PeriodeEssaiSqlDto>? GetAllPeriodeEssais();
PeriodeEssaiSqlDto? GetPeriodeEssaiById(PeriodeEssaiSqlDto periodeEssai); PeriodeEssaiSqlDto? GetPeriodeEssaiById(PeriodeEssaiSqlDto periodeEssai);

@ -4,10 +4,6 @@ namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface
{ {
public interface IProjetRepository public interface IProjetRepository
{ {
ProjetSqlDto? AddProjet(ProjetSqlDto newProjet);
IList<ProjetSqlDto>? GetAllProjets();
IList<ProjetSqlDto>? GetProjetsByClient(string client); IList<ProjetSqlDto>? GetProjetsByClient(string client);
ProjetSqlDto? GetProjetById(ProjetSqlDto projet);
ProjetSqlDto UpdateProjet(ProjetSqlDto projet);
} }
} }
Loading…
Cancel
Save