Refacto + Generic repos et service complet

pull/2/head
Clement FERRERE 3 years ago
parent 1191ca7371
commit e5c9c3a85e
  1. 18
      Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs
  2. 2
      Collaborateur_Epa_Back/espacecollab.backend.api/Program.cs
  3. 9
      Collaborateur_Epa_Back/espacecollab.backend.api/Startup.cs
  4. 1
      Collaborateur_Epa_Back/espacecollab.backend.api/espacecollab.backend.api.csproj
  5. 10
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs
  6. 17
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/GenericApiDtoBase.cs
  7. 4
      Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs
  8. 51
      Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs
  9. 12
      Collaborateur_Epa_Back/espacecollab.backend.appservices/IGenericsServices.cs
  10. 42
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeCollaborateurRepository.cs
  11. 47
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/GenericFakeRepository.cs
  12. 14
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/espacecollab.backend.infrastructure.fake.csproj
  13. 2
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IAgenceRepository.cs
  14. 2
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IBusinessUnitRepository.cs
  15. 2
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/ICollaborateurRepository.cs
  16. 8
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IGenericRepository.cs
  17. 2
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IPeriodeEssaiRepository.cs
  18. 2
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IProjetRepository.cs
  19. 2
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IReferencementRepository.cs
  20. 13
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/espacecollab.backend.infrastructure.interfaces.csproj
  21. 3
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/AgenceSqlDto.cs
  22. 3
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/BusinessUnitSqlDto.cs
  23. 2
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurAppartientBusinessUnitSqlDto.cs
  24. 2
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurEstFonctionSqlDto.cs
  25. 3
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurSqlDto.cs
  26. 3
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/FonctionSqlDto.cs
  27. 8
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/IGenericSqlDto.cs
  28. 7
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/Interfaces/IGenericIdSqlDto.cs
  29. 5
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/PeriodeEssaiSqlDto.cs
  30. 4
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetSqlDto.cs
  31. 1
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetUtiliseTechnologieSqlDto.cs
  32. 5
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ReferencementSqlDto.cs
  33. 3
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteSqlDto.cs
  34. 3
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/TechnologieSqlDto.cs
  35. 84
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/FakeRepo/FakeCollaborateurRepository.cs
  36. 8
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/MainDbContext.cs
  37. 8
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/CollaborateurSqlRepository.cs
  38. 23
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/GenericSqlRepository.cs
  39. 1
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/espacecollab.backend.infrastructure.sql.csproj
  40. 37
      Collaborateur_Epa_Back/espacecollab.backend.sln

@ -38,24 +38,28 @@ namespace espacecollab.backend.api.Controllers
{ {
CollaborateurApiDto? addedCollaborateur = CollaborateursServices.Add(collaborateurApi); CollaborateurApiDto? addedCollaborateur = CollaborateursServices.Add(collaborateurApi);
if (addedCollaborateur == null) if (addedCollaborateur == null)
return BadRequest(); return Problem();
return Ok(addedCollaborateur); return Ok(addedCollaborateur);
} }
[HttpDelete("delete")] [HttpDelete("delete")]
public ActionResult<CollaborateurApiDto> DeleteCollaborateur(CollaborateurApiDto collaborateurApi) public ActionResult DeleteCollaborateur(CollaborateurApiDto collaborateurApi) //TODO passé uniquement l'ID
{ {
CollaborateurApiDto? deletedCollaborateur = CollaborateursServices.Delete(collaborateurApi); bool isCollaborateurDeleted = CollaborateursServices.Delete(collaborateurApi);
if (deletedCollaborateur == null) if (!isCollaborateurDeleted)
return BadRequest(); return Problem();
return Ok(deletedCollaborateur);
return Ok();
} }
[HttpPut("update")] [HttpPut("update")]
public ActionResult<CollaborateurApiDto> UpdateCollaborateur(CollaborateurApiDto collaborateurApi) public ActionResult<CollaborateurApiDto> UpdateCollaborateur(CollaborateurApiDto collaborateurApi)
{ {
CollaborateurApiDto? updatedCollaborateur = CollaborateursServices.Update(collaborateurApi); CollaborateurApiDto? updatedCollaborateur = CollaborateursServices.Update(collaborateurApi);
if (updatedCollaborateur == null) { return BadRequest(); } if (updatedCollaborateur == null)
return Problem();
return Ok(updatedCollaborateur); return Ok(updatedCollaborateur);
} }

@ -1,4 +1,4 @@
namespace Api namespace espacecollab.backend.api
{ {
public static class Program public static class Program
{ {

@ -1,12 +1,11 @@
using espacecollab.backend.appservices; using espacecollab.backend.appservices;
using espacecollab.backend.infrastructure.fake;
using espacecollab.backend.infrastructure.interfaces;
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.Repository;
using espacecollab.backend.infrastructure.sql.SqlRepo.Interface;
namespace Api namespace espacecollab.backend.api
{ {
public class Startup public class Startup
{ {

@ -12,6 +12,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\espacecollab.backend.appservices\espacecollab.backend.appservices.csproj" /> <ProjectReference Include="..\espacecollab.backend.appservices\espacecollab.backend.appservices.csproj" />
<ProjectReference Include="..\espacecollab.backend.infrastructure.fake\espacecollab.backend.infrastructure.fake.csproj" />
<ProjectReference Include="..\espacecollab.backend.infrastructure.sql\espacecollab.backend.infrastructure.sql.csproj" /> <ProjectReference Include="..\espacecollab.backend.infrastructure.sql\espacecollab.backend.infrastructure.sql.csproj" />
</ItemGroup> </ItemGroup>

@ -1,7 +1,4 @@
using espacecollab.backend.appservices.dtos.Mappers; namespace espacecollab.backend.appservices.dtos
using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.appservices.dtos
{ {
public class CollaborateurApiDto public class CollaborateurApiDto
{ {
@ -22,7 +19,6 @@ namespace espacecollab.backend.appservices.dtos
public CollaborateurApiDto() public CollaborateurApiDto()
{ {
} }
public CollaborateurApiDto(int 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) public CollaborateurApiDto(int 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)
@ -43,10 +39,6 @@ namespace espacecollab.backend.appservices.dtos
BusinessUnitId = businessUnitId; BusinessUnitId = businessUnitId;
} }
public CollaborateurApiDto(CollaborateurSqlDto entity)
{
}
//public override CollaborateurSqlDto ToEntity() //public override CollaborateurSqlDto ToEntity()
//{ //{
// return new CollaborateurSqlDto(Id, Name, FirstName, BirthDate, Gender.ToEnumGenreSql(), Status.ToEnumStatutSql(), ChildrenNumber, // return new CollaborateurSqlDto(Id, Name, FirstName, BirthDate, Gender.ToEnumGenreSql(), Status.ToEnumStatutSql(), ChildrenNumber,

@ -1,17 +0,0 @@
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);
}
}
}

@ -1,9 +1,7 @@
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.interfaces;
using espacecollab.backend.infrastructure.sql.dtos; 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;
namespace espacecollab.backend.appservices namespace espacecollab.backend.appservices
{ {

@ -1,29 +1,29 @@
using espacecollab.backend.infrastructure.sql.dtos; using espacecollab.backend.infrastructure.interfaces;
using espacecollab.backend.infrastructure.sql.SqlRepo.Interface; using espacecollab.backend.infrastructure.sql.dtos.Interfaces;
namespace espacecollab.backend.appservices namespace espacecollab.backend.appservices
{ {
public abstract class GenericsServices<T, To> where T : class, IGenericSqlDto public abstract class GenericsServices<T, TO> where T : class, IGenericIdSqlDto
where To : class where TO : class
{ {
Func<T, To> MapperToApiDto { get; } Func<T, TO> MapperToApiDto { get; }
Func<To, T> MapperToSqlDto { get; } Func<TO, T> MapperToSqlDto { get; }
private IGenericRepository<T> GenericRepository { get; } private IGenericRepository<T> GenericRepository { get; }
public GenericsServices(IGenericRepository<T> genericRepository, Func<T, To> mapperToApiDto, Func<To, T> mapperToSqlDto) protected GenericsServices(IGenericRepository<T> genericRepository, Func<T, TO> mapperToApiDto, Func<TO, T> mapperToSqlDto)
{ {
GenericRepository = genericRepository; GenericRepository = genericRepository;
MapperToApiDto = mapperToApiDto; MapperToApiDto = mapperToApiDto;
MapperToSqlDto = mapperToSqlDto; MapperToSqlDto = mapperToSqlDto;
} }
public IEnumerable<To> GetAll() public IEnumerable<TO> GetAll()
{ {
return GenericRepository.GetAll().Select(entity => MapperToApiDto(entity)).ToList(); return GenericRepository.GetAll().Select(entity => MapperToApiDto(entity)).ToList();
} }
public To? GetById(int id) public TO? GetById(int id)
{ {
T? entity = GenericRepository.GetById(id); T? entity = GenericRepository.GetById(id);
if (entity == null) if (entity == null)
@ -32,34 +32,35 @@ namespace espacecollab.backend.appservices
return MapperToApiDto(entity); return MapperToApiDto(entity);
} }
public To? Add(To apiDto) public TO? Add(TO apiDto)
{ {
T sqlDto = MapperToSqlDto(apiDto); T sqlDto = MapperToSqlDto(apiDto);
if (sqlDto == null) { return null; }
T? entitySqlValidation = GenericRepository.Add(sqlDto); T? entitySqlValidation = GenericRepository.Add(sqlDto);
if (entitySqlValidation == null) { return null; } if (entitySqlValidation == null)
return null;
return MapperToApiDto(entitySqlValidation); return MapperToApiDto(entitySqlValidation);
} }
public To? Update(To apiDto) public TO? Update(TO apiDto)
{ {
T? sqlDto = MapperToSqlDto(apiDto); //TODO tester l'existence de l'apiDto dans le SQL
if (sqlDto == null)
return null; T sqlDto = MapperToSqlDto(apiDto);
T? sqlDtoValidation = GenericRepository.Update(sqlDto); T? sqlDtoValidation = GenericRepository.Update(sqlDto);
if (sqlDtoValidation == null) { return null; }
return MapperToApiDto(sqlDtoValidation); if (sqlDtoValidation == null)
}
public To? Delete(To apiDto)
{
T? sqlDto = MapperToSqlDto(apiDto);
if (sqlDto == null)
return null; return null;
T? sqlDtoValidation = GenericRepository.Delete(sqlDto);
if (sqlDtoValidation == null) { return null; }
return MapperToApiDto(sqlDtoValidation); return MapperToApiDto(sqlDtoValidation);
} }
public bool Delete(TO apiDto)
{
T sqlDto = MapperToSqlDto(apiDto);
return GenericRepository.Delete(sqlDto);
}
} }
} }

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

@ -0,0 +1,42 @@
using espacecollab.backend.infrastructure.interfaces;
using espacecollab.backend.infrastructure.sql.dtos;
using espacecollab.backend.infrastructure.sql.dtos.Values;
namespace espacecollab.backend.infrastructure.fake
{
public class FakeCollaborateurRepository : GenericFakeRepository<CollaborateurSqlDto>, ICollaborateurRepository
{
public FakeCollaborateurRepository()
{
Context = new List<CollaborateurSqlDto>
{
new(1, "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), 2, 1),
new(2, "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), 1, 1)
};
}
#region méthodes spécifiques à l'interface ICollaborateurRepository
public IList<CollaborateurSqlDto> GetCollaborateursByBusinessUnit(int businessUnitId)
{
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)
{
return Context.First(entity => entity.ApsideMail == apsideMail);
}
#endregion
}
}

@ -0,0 +1,47 @@
using espacecollab.backend.infrastructure.interfaces;
using espacecollab.backend.infrastructure.sql.dtos.Interfaces;
namespace espacecollab.backend.infrastructure.fake
{
public class GenericFakeRepository<T> : IGenericRepository<T> where T : class, IGenericIdSqlDto
{
protected List<T> Context { get; set; }
public virtual T? Add(T entity)
{
int lastId = Context.Max(e => e.Id);
entity.Id = lastId + 1;
Context.Add(entity);
return entity;
}
public virtual bool Delete(T entity)
{
return Context.Remove(entity);
}
public virtual IEnumerable<T> GetAll()
{
return Context.ToList();
}
public virtual T? GetById(int id)
{
return Context.FirstOrDefault(entity => entity.Id == id);
}
public virtual T? Update(T entity)
{
T? oldEntity = GetById(entity.Id);
if (oldEntity == null)
return null;
Context.Remove(oldEntity);
Context.Add(entity);
return Context.FirstOrDefault(e => e.Id == entity.Id);
}
}
}

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\espacecollab.backend.infrastructure.interfaces\espacecollab.backend.infrastructure.interfaces.csproj" />
<ProjectReference Include="..\espacecollab.backend.infrastructure.sql.dtos\espacecollab.backend.infrastructure.sql.dtos.csproj" />
</ItemGroup>
</Project>

@ -1,6 +1,6 @@
using espacecollab.backend.infrastructure.sql.dtos; using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface namespace espacecollab.backend.infrastructure.interfaces
{ {
public interface IAgenceRepository : IGenericRepository<AgenceSqlDto> public interface IAgenceRepository : IGenericRepository<AgenceSqlDto>
{ {

@ -1,6 +1,6 @@
using espacecollab.backend.infrastructure.sql.dtos; using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface namespace espacecollab.backend.infrastructure.interfaces
{ {
public interface IBusinessUnitRepository : IGenericRepository<BusinessUnitSqlDto> public interface IBusinessUnitRepository : IGenericRepository<BusinessUnitSqlDto>
{ {

@ -1,6 +1,6 @@
using espacecollab.backend.infrastructure.sql.dtos; using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface namespace espacecollab.backend.infrastructure.interfaces
{ {
public interface ICollaborateurRepository : IGenericRepository<CollaborateurSqlDto> public interface ICollaborateurRepository : IGenericRepository<CollaborateurSqlDto>
{ {

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

@ -1,6 +1,6 @@
using espacecollab.backend.infrastructure.sql.dtos; using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface namespace espacecollab.backend.infrastructure.interfaces
{ {
public interface IPeriodeEssaiRepository : IGenericRepository<PeriodeEssaiSqlDto> public interface IPeriodeEssaiRepository : IGenericRepository<PeriodeEssaiSqlDto>
{ {

@ -1,6 +1,6 @@
using espacecollab.backend.infrastructure.sql.dtos; using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface namespace espacecollab.backend.infrastructure.interfaces
{ {
public interface IProjetRepository : IGenericRepository<ProjetSqlDto> public interface IProjetRepository : IGenericRepository<ProjetSqlDto>
{ {

@ -1,6 +1,6 @@
using espacecollab.backend.infrastructure.sql.dtos; using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface namespace espacecollab.backend.infrastructure.interfaces
{ {
public interface IReferencementRepository : IGenericRepository<ReferencementSqlDto> public interface IReferencementRepository : IGenericRepository<ReferencementSqlDto>
{ {

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\espacecollab.backend.infrastructure.sql.dtos\espacecollab.backend.infrastructure.sql.dtos.csproj" />
</ItemGroup>
</Project>

@ -1,8 +1,9 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using espacecollab.backend.infrastructure.sql.dtos.Interfaces;
namespace espacecollab.backend.infrastructure.sql.dtos namespace espacecollab.backend.infrastructure.sql.dtos
{ {
public class AgenceSqlDto : IGenericSqlDto public class AgenceSqlDto : IGenericIdSqlDto
{ {
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } public string Name { get; set; }

@ -1,8 +1,9 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using espacecollab.backend.infrastructure.sql.dtos.Interfaces;
namespace espacecollab.backend.infrastructure.sql.dtos namespace espacecollab.backend.infrastructure.sql.dtos
{ {
public class BusinessUnitSqlDto : IGenericSqlDto public class BusinessUnitSqlDto : IGenericIdSqlDto
{ {
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } public string Name { get; set; }

@ -1,6 +1,6 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
namespace espacecollab.backend.infrastructure.sql.dtos.Associations namespace espacecollab.backend.infrastructure.sql.dtos
{ {
public class CollaborateurAppartientBusinessUnitSqlDto public class CollaborateurAppartientBusinessUnitSqlDto
{ {

@ -1,6 +1,6 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
namespace espacecollab.backend.infrastructure.sql.dtos.Associations namespace espacecollab.backend.infrastructure.sql.dtos
{ {
public class CollaborateurEstFonctionSqlDto public class CollaborateurEstFonctionSqlDto
{ {

@ -1,9 +1,10 @@
using espacecollab.backend.infrastructure.sql.dtos.Values; using espacecollab.backend.infrastructure.sql.dtos.Values;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using espacecollab.backend.infrastructure.sql.dtos.Interfaces;
namespace espacecollab.backend.infrastructure.sql.dtos namespace espacecollab.backend.infrastructure.sql.dtos
{ {
public class CollaborateurSqlDto : IGenericSqlDto public class CollaborateurSqlDto : IGenericIdSqlDto
{ {
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } public string Name { get; set; }

@ -1,8 +1,9 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using espacecollab.backend.infrastructure.sql.dtos.Interfaces;
namespace espacecollab.backend.infrastructure.sql.dtos namespace espacecollab.backend.infrastructure.sql.dtos
{ {
public class FonctionSqlDto : IGenericSqlDto public class FonctionSqlDto : IGenericIdSqlDto
{ {
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } public string Name { get; set; }

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

@ -0,0 +1,7 @@
namespace espacecollab.backend.infrastructure.sql.dtos.Interfaces
{
public interface IGenericIdSqlDto
{
public int Id { get; set; }
}
}

@ -1,9 +1,10 @@
using espacecollab.backend.infrastructure.sql.dtos.Values; using espacecollab.backend.infrastructure.sql.dtos.Values;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using espacecollab.backend.infrastructure.sql.dtos.Interfaces;
namespace espacecollab.backend.infrastructure.sql.dtos namespace espacecollab.backend.infrastructure.sql.dtos
{ {
public class PeriodeEssaiSqlDto : IGenericSqlDto public class PeriodeEssaiSqlDto : IGenericIdSqlDto
{ {
public int Id { get; set; } public int Id { get; set; }
public DateTime StartingDate { get; set; } public DateTime StartingDate { get; set; }
@ -29,7 +30,5 @@ namespace espacecollab.backend.infrastructure.sql.dtos
Issue = issue; Issue = issue;
CollaborateurId = collaborateurId; CollaborateurId = collaborateurId;
} }
} }
} }

@ -1,8 +1,9 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using espacecollab.backend.infrastructure.sql.dtos.Interfaces;
namespace espacecollab.backend.infrastructure.sql.dtos namespace espacecollab.backend.infrastructure.sql.dtos
{ {
public class ProjetSqlDto : IGenericSqlDto public class ProjetSqlDto : IGenericIdSqlDto
{ {
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } public string Name { get; set; }
@ -25,6 +26,5 @@ namespace espacecollab.backend.infrastructure.sql.dtos
StartingDate = startingDate; StartingDate = startingDate;
EndingDate = endingDate; EndingDate = endingDate;
} }
} }
} }

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

@ -1,8 +1,9 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using espacecollab.backend.infrastructure.sql.dtos.Interfaces;
namespace espacecollab.backend.infrastructure.sql.dtos namespace espacecollab.backend.infrastructure.sql.dtos
{ {
public class ReferencementSqlDto : IGenericSqlDto public class ReferencementSqlDto : IGenericIdSqlDto
{ {
public int Id { get; set; } public int Id { get; set; }
public DateTime StartingDate { get; set; } public DateTime StartingDate { get; set; }
@ -23,7 +24,5 @@ namespace espacecollab.backend.infrastructure.sql.dtos
ReferredId = referredId; ReferredId = referredId;
ReferrerId = referrerId; ReferrerId = referrerId;
} }
} }
} }

@ -1,8 +1,9 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using espacecollab.backend.infrastructure.sql.dtos.Interfaces;
namespace espacecollab.backend.infrastructure.sql.dtos namespace espacecollab.backend.infrastructure.sql.dtos
{ {
public class SiteSqlDto : IGenericSqlDto public class SiteSqlDto : IGenericIdSqlDto
{ {
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } public string Name { get; set; }

@ -1,8 +1,9 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using espacecollab.backend.infrastructure.sql.dtos.Interfaces;
namespace espacecollab.backend.infrastructure.sql.dtos namespace espacecollab.backend.infrastructure.sql.dtos
{ {
public class TechnologieSqlDto : IGenericSqlDto public class TechnologieSqlDto : IGenericIdSqlDto
{ {
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } public string Name { get; set; }

@ -1,84 +0,0 @@
using espacecollab.backend.infrastructure.sql.dtos;
using espacecollab.backend.infrastructure.sql.dtos.Values;
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 IList<CollaborateurSqlDto> Collaborateurs { get; } = new List<CollaborateurSqlDto>
{
new CollaborateurSqlDto(1, "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), 2, 1),
new CollaborateurSqlDto(2, "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), 1, 1)
};
public FakeCollaborateurRepository()
{
}
#region redéfinition des méthodes du GenericRepository pour fonctionner avec Fake
public new CollaborateurSqlDto? GetById(int 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;
}
#endregion
#region méthodes spécifiques à l'interface ICollaborateurRepository
public IList<CollaborateurSqlDto> GetCollaborateursByBusinessUnit(int businessUnitId)
{
return Collaborateurs.Where(entity => entity.BusinessUnitId == businessUnitId).ToList();
}
public IList<CollaborateurSqlDto> GetCollaborateursByReferrer(int referrerId)
{
return Collaborateurs.Where(entity => entity.ReferrerId == referrerId).ToList();
}
public CollaborateurSqlDto GetCollaborateurByApsideMail(string apsideMail)
{
return Collaborateurs.First(entity => entity.ApsideMail == apsideMail);
}
#endregion
}
}

@ -1,5 +1,4 @@
using espacecollab.backend.infrastructure.sql.dtos; using espacecollab.backend.infrastructure.sql.Options;
using espacecollab.backend.infrastructure.sql.Options;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
namespace espacecollab.backend.infrastructure.sql namespace espacecollab.backend.infrastructure.sql
@ -8,12 +7,11 @@ namespace espacecollab.backend.infrastructure.sql
{ {
private IOptions<SqlOption> SqlSettings { get; } private IOptions<SqlOption> SqlSettings { get; }
public DbSet<CollaborateurSqlDto>? Collaborateur { get; set; }
public MainDbContext(IOptions<SqlOption> sqlSettings) public MainDbContext(IOptions<SqlOption> sqlSettings)
{ {
SqlSettings = sqlSettings; SqlSettings = sqlSettings;
} }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{ {
optionsBuilder.UseSqlServer(SqlSettings.Value.ConnectionString, builder => optionsBuilder.UseSqlServer(SqlSettings.Value.ConnectionString, builder =>
@ -21,7 +19,5 @@ namespace espacecollab.backend.infrastructure.sql
builder.EnableRetryOnFailure(5, TimeSpan.FromSeconds(10), null); builder.EnableRetryOnFailure(5, TimeSpan.FromSeconds(10), null);
}); });
} }
} }
} }

@ -1,9 +1,9 @@
using espacecollab.backend.infrastructure.sql.dtos; using espacecollab.backend.infrastructure.interfaces;
using espacecollab.backend.infrastructure.sql.SqlRepo.Interface; using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.infrastructure.sql.SqlRepo namespace espacecollab.backend.infrastructure.sql.Repository
{ {
public class CollaborateurSqlRepository : GenericRepository<CollaborateurSqlDto>,ICollaborateurRepository public class CollaborateurSqlRepository : GenericSqlRepository<CollaborateurSqlDto>, ICollaborateurRepository
{ {
private MainDbContext Context { get; } private MainDbContext Context { get; }

@ -1,18 +1,13 @@
using espacecollab.backend.infrastructure.sql.dtos; using espacecollab.backend.infrastructure.interfaces;
using espacecollab.backend.infrastructure.sql.SqlRepo.Interface; using espacecollab.backend.infrastructure.sql.dtos.Interfaces;
namespace espacecollab.backend.infrastructure.sql.SqlRepo namespace espacecollab.backend.infrastructure.sql.Repository
{ {
public class GenericRepository<T> : IGenericRepository<T> where T : class, IGenericSqlDto public class GenericSqlRepository<T> : IGenericRepository<T> where T : class, IGenericIdSqlDto
{ {
private MainDbContext Context { get; } private MainDbContext Context { get; }
public GenericRepository() public GenericSqlRepository(MainDbContext context)
{
}
public GenericRepository(MainDbContext context)
{ {
Context = context; Context = context;
} }
@ -22,9 +17,11 @@ namespace espacecollab.backend.infrastructure.sql.SqlRepo
return Context.Set<T>().Add(entity) as T; return Context.Set<T>().Add(entity) as T;
} }
public virtual T? Delete(T entity) public virtual bool Delete(T entity)
{ {
return Context.Set<T>().Remove(entity) as T; Context.Set<T>().Remove(entity);
return Context.SaveChanges() == 1;
} }
public virtual IEnumerable<T> GetAll() public virtual IEnumerable<T> GetAll()
@ -41,8 +38,8 @@ namespace espacecollab.backend.infrastructure.sql.SqlRepo
{ {
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);
} }
} }
} }

@ -17,6 +17,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\espacecollab.backend.infrastructure.interfaces\espacecollab.backend.infrastructure.interfaces.csproj" />
<ProjectReference Include="..\espacecollab.backend.infrastructure.sql.dtos\espacecollab.backend.infrastructure.sql.dtos.csproj" /> <ProjectReference Include="..\espacecollab.backend.infrastructure.sql.dtos\espacecollab.backend.infrastructure.sql.dtos.csproj" />
</ItemGroup> </ItemGroup>

@ -3,15 +3,25 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.0.31912.275 VisualStudioVersion = 17.0.31912.275
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "espacecollab.backend.api", "espacecollab.backend.api\espacecollab.backend.api.csproj", "{A8DEB005-D7E2-4A96-B004-A66BBF12AC54}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "espacecollab.backend.api", "espacecollab.backend.api\espacecollab.backend.api.csproj", "{A8DEB005-D7E2-4A96-B004-A66BBF12AC54}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "espacecollab.backend.appservices", "espacecollab.backend.appservices\espacecollab.backend.appservices.csproj", "{70F1BE1C-87C1-4CCF-A7E8-2A36F3F16D9E}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "espacecollab.backend.appservices", "espacecollab.backend.appservices\espacecollab.backend.appservices.csproj", "{70F1BE1C-87C1-4CCF-A7E8-2A36F3F16D9E}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "espacecollab.backend.appservices.dtos", "espacecollab.backend.appservices.dtos\espacecollab.backend.appservices.dtos.csproj", "{CB0CB8FC-0E53-4205-AAA3-4176211C922B}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "espacecollab.backend.appservices.dtos", "espacecollab.backend.appservices.dtos\espacecollab.backend.appservices.dtos.csproj", "{CB0CB8FC-0E53-4205-AAA3-4176211C922B}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "espacecollab.backend.infrastructure.sql", "espacecollab.backend.infrastructure.sql\espacecollab.backend.infrastructure.sql.csproj", "{590FF09D-0DF3-4881-8D86-E4FDAAC75FDC}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "espacecollab.backend.infrastructure.sql", "espacecollab.backend.infrastructure.sql\espacecollab.backend.infrastructure.sql.csproj", "{590FF09D-0DF3-4881-8D86-E4FDAAC75FDC}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "espacecollab.backend.infrastructure.sql.dtos", "espacecollab.backend.infrastructure.sql.dtos\espacecollab.backend.infrastructure.sql.dtos.csproj", "{26C08CE0-E6E5-4E03-8AEA-233F93218A3B}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "espacecollab.backend.infrastructure.sql.dtos", "espacecollab.backend.infrastructure.sql.dtos\espacecollab.backend.infrastructure.sql.dtos.csproj", "{26C08CE0-E6E5-4E03-8AEA-233F93218A3B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "1 Host", "1 Host", "{19237F76-6CA9-47DF-87F8-8027C78070C9}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "2 ApplicationsServices", "2 ApplicationsServices", "{CE5199B3-E423-46C1-B141-18C46473D964}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "4 Infrastructure", "4 Infrastructure", "{E29F5CA9-ABAF-4437-8633-49FF27110E6D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "espacecollab.backend.infrastructure.interfaces", "espacecollab.backend.infrastructure.interfaces\espacecollab.backend.infrastructure.interfaces.csproj", "{3E9E4801-D686-4581-8051-E0E1B036AC70}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "espacecollab.backend.infrastructure.fake", "espacecollab.backend.infrastructure.fake\espacecollab.backend.infrastructure.fake.csproj", "{48253B9B-9B42-48CF-A95F-358171BABA74}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -39,10 +49,27 @@ Global
{26C08CE0-E6E5-4E03-8AEA-233F93218A3B}.Debug|Any CPU.Build.0 = Debug|Any CPU {26C08CE0-E6E5-4E03-8AEA-233F93218A3B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{26C08CE0-E6E5-4E03-8AEA-233F93218A3B}.Release|Any CPU.ActiveCfg = Release|Any CPU {26C08CE0-E6E5-4E03-8AEA-233F93218A3B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{26C08CE0-E6E5-4E03-8AEA-233F93218A3B}.Release|Any CPU.Build.0 = Release|Any CPU {26C08CE0-E6E5-4E03-8AEA-233F93218A3B}.Release|Any CPU.Build.0 = Release|Any CPU
{3E9E4801-D686-4581-8051-E0E1B036AC70}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3E9E4801-D686-4581-8051-E0E1B036AC70}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3E9E4801-D686-4581-8051-E0E1B036AC70}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3E9E4801-D686-4581-8051-E0E1B036AC70}.Release|Any CPU.Build.0 = Release|Any CPU
{48253B9B-9B42-48CF-A95F-358171BABA74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{48253B9B-9B42-48CF-A95F-358171BABA74}.Debug|Any CPU.Build.0 = Debug|Any CPU
{48253B9B-9B42-48CF-A95F-358171BABA74}.Release|Any CPU.ActiveCfg = Release|Any CPU
{48253B9B-9B42-48CF-A95F-358171BABA74}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
EndGlobalSection EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{A8DEB005-D7E2-4A96-B004-A66BBF12AC54} = {19237F76-6CA9-47DF-87F8-8027C78070C9}
{70F1BE1C-87C1-4CCF-A7E8-2A36F3F16D9E} = {CE5199B3-E423-46C1-B141-18C46473D964}
{CB0CB8FC-0E53-4205-AAA3-4176211C922B} = {CE5199B3-E423-46C1-B141-18C46473D964}
{590FF09D-0DF3-4881-8D86-E4FDAAC75FDC} = {E29F5CA9-ABAF-4437-8633-49FF27110E6D}
{26C08CE0-E6E5-4E03-8AEA-233F93218A3B} = {E29F5CA9-ABAF-4437-8633-49FF27110E6D}
{3E9E4801-D686-4581-8051-E0E1B036AC70} = {E29F5CA9-ABAF-4437-8633-49FF27110E6D}
{48253B9B-9B42-48CF-A95F-358171BABA74} = {E29F5CA9-ABAF-4437-8633-49FF27110E6D}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0A56A44C-135E-4CE4-834B-8DFDF69DC415} SolutionGuid = {0A56A44C-135E-4CE4-834B-8DFDF69DC415}
EndGlobalSection EndGlobalSection

Loading…
Cancel
Save