Généricité complète, TODO fixed.

pull/2/head
Clement FERRERE 3 years ago
parent e5c9c3a85e
commit 09ff256ca7
  1. 4
      Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs
  2. 6
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs
  3. 7
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Interfaces/IGenericIdSqlDto.cs
  4. 27
      Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs
  5. 14
      Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs
  6. 4
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/GenericFakeRepository.cs
  7. 2
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IGenericRepository.cs
  8. 2
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IReferencementRepository.cs
  9. 4
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/GenericSqlRepository.cs

@ -44,9 +44,9 @@ namespace espacecollab.backend.api.Controllers
}
[HttpDelete("delete")]
public ActionResult DeleteCollaborateur(CollaborateurApiDto collaborateurApi) //TODO passé uniquement l'ID
public ActionResult DeleteCollaborateur(int collaborateurId)
{
bool isCollaborateurDeleted = CollaborateursServices.Delete(collaborateurApi);
bool isCollaborateurDeleted = CollaborateursServices.Delete(collaborateurId);
if (!isCollaborateurDeleted)
return Problem();

@ -1,6 +1,8 @@
namespace espacecollab.backend.appservices.dtos
using espacecollab.backend.infrastructure.sql.dtos.Interfaces;
namespace espacecollab.backend.appservices.dtos
{
public class CollaborateurApiDto
public class CollaborateurApiDto : IGenericIdApiDto
{
public int Id { get; set; }
public string Name { get; set; }

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

@ -15,33 +15,6 @@ namespace espacecollab.backend.appservices
CollaborateurRepository = collaborateurRepository;
}
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 CollaborateurApiDto? UpdateCollaborateur(CollaborateurApiDto collaborateurApi)
{
CollaborateurSqlDto collaborateurSql = collaborateurApi.ToSql();
if (collaborateurSql == null)
return null;
CollaborateurRepository.Update(collaborateurSql);
return collaborateurApi;
}
public IEnumerable<CollaborateurApiDto> GetCollaborateursByBusinessUnit(int businessUnitId)
{
return CollaborateurRepository.GetCollaborateursByBusinessUnit(businessUnitId).Select(collaborateurSql => collaborateurSql.ToApi());

@ -4,7 +4,7 @@ using espacecollab.backend.infrastructure.sql.dtos.Interfaces;
namespace espacecollab.backend.appservices
{
public abstract class GenericsServices<T, TO> where T : class, IGenericIdSqlDto
where TO : class
where TO : class, IGenericIdApiDto
{
Func<T, TO> MapperToApiDto { get; }
Func<TO, T> MapperToSqlDto { get; }
@ -45,8 +45,10 @@ namespace espacecollab.backend.appservices
public TO? Update(TO apiDto)
{
//TODO tester l'existence de l'apiDto dans le SQL
if(GetById(apiDto.Id)==null)
{
return null;
}
T sqlDto = MapperToSqlDto(apiDto);
T? sqlDtoValidation = GenericRepository.Update(sqlDto);
@ -56,11 +58,9 @@ namespace espacecollab.backend.appservices
return MapperToApiDto(sqlDtoValidation);
}
public bool Delete(TO apiDto)
public bool Delete(int apiDtoId)
{
T sqlDto = MapperToSqlDto(apiDto);
return GenericRepository.Delete(sqlDto);
return GenericRepository.Delete(apiDtoId);
}
}
}

@ -17,8 +17,10 @@ namespace espacecollab.backend.infrastructure.fake
return entity;
}
public virtual bool Delete(T entity)
public virtual bool Delete(int entityId)
{
T? entity = GetById(entityId);
if (entity == null) return false;
return Context.Remove(entity);
}

@ -5,7 +5,7 @@ namespace espacecollab.backend.infrastructure.interfaces
public interface IGenericRepository<T> where T : class, IGenericIdSqlDto
{
T? Add(T entity);
bool Delete(T entity);
bool Delete(int entityId);
IEnumerable<T> GetAll();
T? GetById(int id);
T? Update(T entity);

@ -6,7 +6,5 @@ namespace espacecollab.backend.infrastructure.interfaces
{
IList<CollaborateurSqlDto>? GetReferrersByCollaborateurId(int collaborateurId);
IList<CollaborateurSqlDto>? GetReferrersByCollaborateurApsideMail(string apsideMail);
//TODO Voir les attentes concernant "le référent ayant le plus suivi depuis une date"
}
}

@ -17,8 +17,10 @@ namespace espacecollab.backend.infrastructure.sql.Repository
return Context.Set<T>().Add(entity) as T;
}
public virtual bool Delete(T entity)
public virtual bool Delete(int entityId)
{
T? entity = GetById(entityId);
if (entity == null) return false;
Context.Set<T>().Remove(entity);
return Context.SaveChanges() == 1;

Loading…
Cancel
Save