clean code ReSharper

pull/4/head
Alexandre Ruiz 3 years ago
parent f44f34fdec
commit 418b4cd972
  1. 1
      Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/BusinessUnitController.cs
  2. 27
      Collaborateur_Epa_Back/espacecollab.backend.api/Program.cs
  3. 2
      Collaborateur_Epa_Back/espacecollab.backend.api/Register.cs
  4. 87
      Collaborateur_Epa_Back/espacecollab.backend.api/Startup.cs
  5. 11
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/BusinessUnitApiDto.cs
  6. 13
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs
  7. 11
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Interfaces/IGenericIdApiDto.cs
  8. 33
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/CollaborateurApiDtoMapper.cs
  9. 41
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/EnumGenreMapper.cs
  10. 45
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/EnumStatutMapper.cs
  11. 3
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/PeriodeEssaiMapper.cs
  12. 2
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/PeriodeEssaiApiDto.cs
  13. 15
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Values/EnumGenreApi.cs
  14. 19
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Values/EnumIssueApi.cs
  15. 15
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Values/EnumStatutApi.cs
  16. 19
      Collaborateur_Epa_Back/espacecollab.backend.appservices.interfaces/IGenericsServices.cs
  17. 2
      Collaborateur_Epa_Back/espacecollab.backend.appservices/AgenceService.cs
  18. 3
      Collaborateur_Epa_Back/espacecollab.backend.appservices/BusinessUnitService.cs
  19. 47
      Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursService.cs
  20. 95
      Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs
  21. 1
      Collaborateur_Epa_Back/espacecollab.backend.appservices/PeriodeEssaiService.cs
  22. 20
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeAgenceRepository.cs
  23. 20
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeBusinessUnitRepository.cs
  24. 58
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeCollaborateurRepository.cs
  25. 1
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeFonctionRepository.cs
  26. 1
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakePeriodeEssaiRepository.cs
  27. 85
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/GenericFakeRepository.cs
  28. 7
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IAgenceRepository.cs
  29. 7
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IBusinessUnitRepository.cs
  30. 13
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/ICollaborateurRepository.cs
  31. 18
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IGenericRepository.cs
  32. 9
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IProjetRepository.cs
  33. 11
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IReferencementRepository.cs
  34. 31
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurAppartientBusinessUnitSqlDto.cs
  35. 34
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurCollaboreProjetSqlDto.cs
  36. 31
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurEstFonctionSqlDto.cs
  37. 1
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/FonctionSqlDto.cs
  38. 11
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/Interfaces/IGenericIdSqlDto.cs
  39. 45
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetSqlDto.cs
  40. 29
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetUtiliseTechnologieSqlDto.cs
  41. 41
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ReferencementSqlDto.cs
  42. 32
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteDeveloppeProjetSqlDto.cs
  43. 40
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteSqlDto.cs
  44. 34
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/TechnologieSqlDto.cs
  45. 15
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/Values/EnumGenreSql.cs
  46. 19
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/Values/EnumIssueSql.cs
  47. 17
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/Values/EnumStatutSql.cs
  48. 53
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/MainDbContext.cs
  49. 21
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Options/SqlOption.cs
  50. 27
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/CollaborateurSqlRepository.cs
  51. 89
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/GenericSqlRepository.cs

@ -1,4 +1,5 @@
using espacecollab.backend.appservices;
using espacecollab.backend.appservices.dtos;
using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.api.Controllers

@ -1,17 +1,16 @@
namespace espacecollab.backend.api
namespace espacecollab.backend.api;
public static class Program
{
public static class Program
public static void Main(string[] args)
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
CreateHostBuilder(args).Build().Run();
}
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}

@ -12,7 +12,7 @@ internal static class Register
public static void InjectDependencies(IServiceCollection services, SqlOption contextOptions)
{
services.AddCors();
services.AddScoped<CollaborateursServices>();
services.AddScoped<CollaborateursService>();
services.AddScoped<AgenceService>();
services.AddScoped<BusinessUnitService>();
services.AddScoped<FonctionService>();

@ -1,58 +1,57 @@
using espacecollab.backend.infrastructure.sql.Options;
using System.Text.Json.Serialization;
namespace espacecollab.backend.api
namespace espacecollab.backend.api;
public class Startup
{
public class Startup
public IConfiguration Configuration { get; }
public Startup(IConfiguration configuration)
{
public IConfiguration Configuration { get; }
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
Configuration = configuration;
}
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
IConfigurationSection sqlSection = Configuration.GetSection(SqlOption.Key);
services.Configure<SqlOption>(sqlSection);
SqlOption sqlOptions = sqlSection.Get<SqlOption>();
services.AddControllers().AddJsonOptions(opt =>
{
IConfigurationSection sqlSection = Configuration.GetSection(SqlOption.Key);
services.Configure<SqlOption>(sqlSection);
SqlOption sqlOptions = sqlSection.Get<SqlOption>();
opt.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
}); ;
services.AddRouting(options => options.LowercaseUrls = true);
services.AddControllers().AddJsonOptions(opt =>
{
opt.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
}); ;
services.AddRouting(options => options.LowercaseUrls = true);
services.AddEndpointsApiExplorer();
services.AddSwaggerGen();
services.AddEndpointsApiExplorer();
services.AddSwaggerGen();
Register.InjectDependencies(services, sqlOptions);
}
Register.InjectDependencies(services, sqlOptions);
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseCors(
options => options.WithOrigins("http://localhost:4200").AllowAnyMethod().AllowAnyHeader()
);
app.UseSwagger();
app.UseSwaggerUI();
app.UseHttpsRedirection();
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseCors(
options => options.WithOrigins("http://localhost:4200").AllowAnyMethod().AllowAnyHeader()
);
app.UseSwagger();
app.UseSwaggerUI();
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
endpoints.MapControllers();
});
}
}
}

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

@ -1,11 +1,10 @@
using espacecollab.backend.appservices.dtos.Interfaces;
using espacecollab.backend.appservices.dtos.Values;
namespace espacecollab.backend.appservices.dtos
namespace espacecollab.backend.appservices.dtos;
public record CollaborateurApiDto(uint Id, string Name, string FirstName, string BirthDate, EnumGenreApi Gender, EnumStatutApi Status, int ChildrenNumber, string Address,
string Telephone, string PersonalMail, string ApsideMail, string ResignationDate, int ReferrerId, int BusinessUnitId) : IGenericIdApiDto
{
public record CollaborateurApiDto(uint Id, string Name, string FirstName, string BirthDate, EnumGenreApi Gender, EnumStatutApi Status, int ChildrenNumber, string Address,
string Telephone, string PersonalMail, string ApsideMail, string ResignationDate, int ReferrerId, int BusinessUnitId) : IGenericIdApiDto
{
public uint Id { get; set; } = Id;
}
}
public uint Id { get; set; } = Id;
}

@ -1,7 +1,6 @@
namespace espacecollab.backend.appservices.dtos.Interfaces
namespace espacecollab.backend.appservices.dtos.Interfaces;
public interface IGenericIdApiDto
{
public interface IGenericIdApiDto
{
public uint Id { get; set; }
}
}
public uint Id { get; set; }
}

@ -1,24 +1,23 @@
using espacecollab.backend.infrastructure.sql.dtos;
using System.Globalization;
namespace espacecollab.backend.appservices.dtos.Mappers
namespace espacecollab.backend.appservices.dtos.Mappers;
public static class CollaborateurMapper
{
public static class CollaborateurMapper
public static CollaborateurApiDto ToApi(this CollaborateurSqlDto collaborateurSql)
{
public static CollaborateurApiDto ToApi(this CollaborateurSqlDto collaborateurSql)
{
return new CollaborateurApiDto((uint)collaborateurSql.Id, collaborateurSql.Name, collaborateurSql.FirstName,
collaborateurSql.BirthDate.ToShortDateString(), collaborateurSql.Gender.ToEnumGenreApi(), collaborateurSql.Status.ToEnumStatutApi(), collaborateurSql.ChildrenNumber,
collaborateurSql.Address, collaborateurSql.Telephone, collaborateurSql.PersonalMail, collaborateurSql.ApsideMail,
collaborateurSql.ResignationDate.ToShortDateString(), collaborateurSql.ReferrerId, collaborateurSql.BusinessUnitId);
}
return new CollaborateurApiDto((uint)collaborateurSql.Id, collaborateurSql.Name, collaborateurSql.FirstName,
collaborateurSql.BirthDate.ToShortDateString(), collaborateurSql.Gender.ToEnumGenreApi(), collaborateurSql.Status.ToEnumStatutApi(), collaborateurSql.ChildrenNumber,
collaborateurSql.Address, collaborateurSql.Telephone, collaborateurSql.PersonalMail, collaborateurSql.ApsideMail,
collaborateurSql.ResignationDate.ToShortDateString(), collaborateurSql.ReferrerId, collaborateurSql.BusinessUnitId);
}
public static CollaborateurSqlDto ToSql(this CollaborateurApiDto collaborateurApi)
{
return new CollaborateurSqlDto((int)collaborateurApi.Id, collaborateurApi.Name, collaborateurApi.FirstName,
DateTime.ParseExact(collaborateurApi.BirthDate,"dd/MM/yyyy",CultureInfo.InvariantCulture), collaborateurApi.Gender.ToEnumGenreSql(), collaborateurApi.Status.ToEnumStatutSql(), collaborateurApi.ChildrenNumber,
collaborateurApi.Address, collaborateurApi.Telephone, collaborateurApi.PersonalMail, collaborateurApi.ApsideMail,
DateTime.ParseExact(collaborateurApi.ResignationDate, "dd/MM/yyyy", CultureInfo.InvariantCulture), collaborateurApi.ReferrerId, collaborateurApi.BusinessUnitId);
}
public static CollaborateurSqlDto ToSql(this CollaborateurApiDto collaborateurApi)
{
return new CollaborateurSqlDto((int)collaborateurApi.Id, collaborateurApi.Name, collaborateurApi.FirstName,
DateTime.ParseExact(collaborateurApi.BirthDate, "dd/MM/yyyy", CultureInfo.InvariantCulture), collaborateurApi.Gender.ToEnumGenreSql(), collaborateurApi.Status.ToEnumStatutSql(), collaborateurApi.ChildrenNumber,
collaborateurApi.Address, collaborateurApi.Telephone, collaborateurApi.PersonalMail, collaborateurApi.ApsideMail,
DateTime.ParseExact(collaborateurApi.ResignationDate, "dd/MM/yyyy", CultureInfo.InvariantCulture), collaborateurApi.ReferrerId, collaborateurApi.BusinessUnitId);
}
}
}

@ -1,30 +1,29 @@
using espacecollab.backend.appservices.dtos.Values;
using espacecollab.backend.infrastructure.sql.dtos.Values;
namespace espacecollab.backend.appservices.dtos.Mappers
namespace espacecollab.backend.appservices.dtos.Mappers;
public static class EnumGenreMapper
{
public static class EnumGenreMapper
public static EnumGenreApi ToEnumGenreApi(this EnumGenreSql enumGenreSql)
{
public static EnumGenreApi ToEnumGenreApi(this EnumGenreSql enumGenreSql)
return enumGenreSql switch
{
return enumGenreSql switch
{
EnumGenreSql.MASCULIN => EnumGenreApi.MASCULIN,
EnumGenreSql.FEMININ => EnumGenreApi.FEMININ,
EnumGenreSql.AUTRE => EnumGenreApi.AUTRE,
_ => EnumGenreApi.AUTRE,
};
}
EnumGenreSql.MASCULIN => EnumGenreApi.MASCULIN,
EnumGenreSql.FEMININ => EnumGenreApi.FEMININ,
EnumGenreSql.AUTRE => EnumGenreApi.AUTRE,
_ => EnumGenreApi.AUTRE,
};
}
public static EnumGenreSql ToEnumGenreSql(this EnumGenreApi enumGenreApi)
public static EnumGenreSql ToEnumGenreSql(this EnumGenreApi enumGenreApi)
{
return enumGenreApi switch
{
return enumGenreApi switch
{
EnumGenreApi.MASCULIN => EnumGenreSql.MASCULIN,
EnumGenreApi.FEMININ => EnumGenreSql.FEMININ,
EnumGenreApi.AUTRE => EnumGenreSql.AUTRE,
_ => EnumGenreSql.AUTRE,
};
}
EnumGenreApi.MASCULIN => EnumGenreSql.MASCULIN,
EnumGenreApi.FEMININ => EnumGenreSql.FEMININ,
EnumGenreApi.AUTRE => EnumGenreSql.AUTRE,
_ => EnumGenreSql.AUTRE,
};
}
}
}

@ -1,32 +1,31 @@
using espacecollab.backend.appservices.dtos.Values;
using espacecollab.backend.infrastructure.sql.dtos.Values;
namespace espacecollab.backend.appservices.dtos.Mappers
namespace espacecollab.backend.appservices.dtos.Mappers;
public static class EnumStatutMapper
{
public static class EnumStatutMapper
public static EnumStatutApi ToEnumStatutApi(this EnumStatutSql enumStatutSql)
{
public static EnumStatutApi ToEnumStatutApi(this EnumStatutSql enumStatutSql)
return enumStatutSql switch
{
return enumStatutSql switch
{
EnumStatutSql.STAGIAIRE => EnumStatutApi.STAGIAIRE,
EnumStatutSql.NONCADRE => EnumStatutApi.NONCADRE,
EnumStatutSql.CADRE => EnumStatutApi.CADRE,
EnumStatutSql.ALTERNANT => EnumStatutApi.ALTERNANT,
_ => EnumStatutApi.NONCADRE,
};
}
EnumStatutSql.STAGIAIRE => EnumStatutApi.STAGIAIRE,
EnumStatutSql.NONCADRE => EnumStatutApi.NONCADRE,
EnumStatutSql.CADRE => EnumStatutApi.CADRE,
EnumStatutSql.ALTERNANT => EnumStatutApi.ALTERNANT,
_ => EnumStatutApi.NONCADRE,
};
}
public static EnumStatutSql ToEnumStatutSql(this EnumStatutApi enumStatutApi)
public static EnumStatutSql ToEnumStatutSql(this EnumStatutApi enumStatutApi)
{
return enumStatutApi switch
{
return enumStatutApi switch
{
EnumStatutApi.STAGIAIRE => EnumStatutSql.STAGIAIRE,
EnumStatutApi.NONCADRE => EnumStatutSql.NONCADRE,
EnumStatutApi.CADRE => EnumStatutSql.CADRE,
EnumStatutApi.ALTERNANT => EnumStatutSql.ALTERNANT,
_ => EnumStatutSql.NONCADRE,
};
}
EnumStatutApi.STAGIAIRE => EnumStatutSql.STAGIAIRE,
EnumStatutApi.NONCADRE => EnumStatutSql.NONCADRE,
EnumStatutApi.CADRE => EnumStatutSql.CADRE,
EnumStatutApi.ALTERNANT => EnumStatutSql.ALTERNANT,
_ => EnumStatutSql.NONCADRE,
};
}
}
}

@ -1,4 +1,5 @@
using espacecollab.backend.infrastructure.sql.dtos;
using espacecollab.backend.appservices.dtos.Values;
using espacecollab.backend.infrastructure.sql.dtos;
using espacecollab.backend.infrastructure.sql.dtos.Values;
namespace espacecollab.backend.appservices.dtos.Mappers;

@ -1,5 +1,5 @@
using espacecollab.backend.appservices.dtos.Interfaces;
using espacecollab.backend.infrastructure.sql.dtos.Values;
using espacecollab.backend.appservices.dtos.Values;
namespace espacecollab.backend.appservices.dtos;

@ -1,9 +1,8 @@
namespace espacecollab.backend.appservices.dtos.Values
namespace espacecollab.backend.appservices.dtos.Values;
public enum EnumGenreApi
{
public enum EnumGenreApi
{
MASCULIN,
FEMININ,
AUTRE
}
}
MASCULIN,
FEMININ,
AUTRE
}

@ -1,11 +1,10 @@
namespace espacecollab.backend.infrastructure.sql.dtos.Values
namespace espacecollab.backend.appservices.dtos.Values;
public enum EnumIssueApi
{
public enum EnumIssueApi
{
VALIDEE,
PROLONGEE_COLLAB,
PROLONGEE_APSIDE,
ARRETEE_COLLAB,
ARRETEE_APSIDE
}
}
VALIDEE,
PROLONGEE_COLLAB,
PROLONGEE_APSIDE,
ARRETEE_COLLAB,
ARRETEE_APSIDE
}

@ -1,10 +1,9 @@
namespace espacecollab.backend.appservices.dtos.Values
namespace espacecollab.backend.appservices.dtos.Values;
public enum EnumStatutApi
{
public enum EnumStatutApi
{
CADRE,
NONCADRE,
ALTERNANT,
STAGIAIRE
}
CADRE,
NONCADRE,
ALTERNANT,
STAGIAIRE
}

@ -1,17 +1,16 @@
using espacecollab.backend.appservices.dtos.Interfaces;
namespace espacecollab.backend.appservices.interfaces
namespace espacecollab.backend.appservices.interfaces;
public interface IGenericsServices<T> where T : class, IGenericIdApiDto
{
public interface IGenericsServices<T> where T : class, IGenericIdApiDto
{
T? Add(T apiDto);
T? Add(T apiDto);
IEnumerable<T> GetAll();
IEnumerable<T> GetAll();
T? GetById(uint id);
T? GetById(uint id);
T? Update(T apiDto);
T? Update(T apiDto);
bool Delete(uint apiDtoId);
}
}
bool Delete(uint apiDtoId);
}

@ -8,7 +8,7 @@ namespace espacecollab.backend.appservices;
public class AgenceService : GenericsServices<AgenceSqlDto, AgenceApiDto>
{
public AgenceService(IAgenceRepository agenceRepository)
:base(agenceRepository, AgenceMapper.ToApi, AgenceMapper.ToSql)
: base(agenceRepository, AgenceMapper.ToApi, AgenceMapper.ToSql)
{
}
}

@ -1,4 +1,5 @@
using espacecollab.backend.appservices.dtos.Mappers;
using espacecollab.backend.appservices.dtos;
using espacecollab.backend.appservices.dtos.Mappers;
using espacecollab.backend.infrastructure.interfaces;
using espacecollab.backend.infrastructure.sql.dtos;

@ -3,34 +3,33 @@ using espacecollab.backend.appservices.dtos.Mappers;
using espacecollab.backend.infrastructure.interfaces;
using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.appservices
namespace espacecollab.backend.appservices;
public class CollaborateursService : GenericsServices<CollaborateurSqlDto, CollaborateurApiDto>
{
public class CollaborateursService : GenericsServices<CollaborateurSqlDto, CollaborateurApiDto>
{
private ICollaborateurRepository CollaborateurRepository { get; }
private ICollaborateurRepository CollaborateurRepository { get; }
public CollaborateursService(ICollaborateurRepository collaborateurRepository)
: base(collaborateurRepository, CollaborateurMapper.ToApi, CollaborateurMapper.ToSql)
{
CollaborateurRepository = collaborateurRepository;
}
public CollaborateursService(ICollaborateurRepository collaborateurRepository)
: base(collaborateurRepository, CollaborateurMapper.ToApi, CollaborateurMapper.ToSql)
{
CollaborateurRepository = collaborateurRepository;
}
public IEnumerable<CollaborateurApiDto> GetCollaborateursByBusinessUnit(uint businessUnitId)
{
return CollaborateurRepository.GetCollaborateursByBusinessUnit((int)businessUnitId).Select(collaborateurSql => collaborateurSql.ToApi());
}
public IEnumerable<CollaborateurApiDto> GetCollaborateursByBusinessUnit(uint businessUnitId)
{
return CollaborateurRepository.GetCollaborateursByBusinessUnit((int)businessUnitId).Select(collaborateurSql => collaborateurSql.ToApi());
}
public IEnumerable<CollaborateurApiDto> GetCollaborateursByReferrer(uint referrerId)
{
return CollaborateurRepository.GetCollaborateursByReferrer((int)referrerId).Select(collaborateurSql => collaborateurSql.ToApi());
}
public IEnumerable<CollaborateurApiDto> GetCollaborateursByReferrer(uint referrerId)
{
return CollaborateurRepository.GetCollaborateursByReferrer((int)referrerId).Select(collaborateurSql => collaborateurSql.ToApi());
}
public CollaborateurApiDto? GetCollaborateurByApsideMail(string apsideMail)
{
if (string.IsNullOrEmpty(apsideMail))
return null;
public CollaborateurApiDto? GetCollaborateurByApsideMail(string apsideMail)
{
if (string.IsNullOrEmpty(apsideMail))
return null;
return CollaborateurRepository.GetCollaborateurByApsideMail(apsideMail)?.ToApi();
}
return CollaborateurRepository.GetCollaborateurByApsideMail(apsideMail)?.ToApi();
}
}
}

@ -3,65 +3,64 @@ using espacecollab.backend.appservices.interfaces;
using espacecollab.backend.infrastructure.interfaces;
using espacecollab.backend.infrastructure.sql.dtos.Interfaces;
namespace espacecollab.backend.appservices
namespace espacecollab.backend.appservices;
public abstract class GenericsServices<T, TO> : IGenericsServices<TO> where T : class, IGenericIdSqlDto
where TO : class, IGenericIdApiDto
{
public abstract class GenericsServices<T, TO> : IGenericsServices<TO> where T : class, IGenericIdSqlDto
where TO : class, IGenericIdApiDto
{
private Func<T, TO> MapperToApiDto { get; }
private Func<TO, T> MapperToSqlDto { get; }
private IGenericRepository<T> GenericRepository { get; }
private Func<T, TO> MapperToApiDto { get; }
private Func<TO, T> MapperToSqlDto { get; }
protected GenericsServices(IGenericRepository<T> genericRepository, Func<T, TO> mapperToApiDto, Func<TO, T> mapperToSqlDto)
{
GenericRepository = genericRepository;
MapperToApiDto = mapperToApiDto;
MapperToSqlDto = mapperToSqlDto;
}
private IGenericRepository<T> GenericRepository { get; }
public IEnumerable<TO> GetAll()
{
return GenericRepository.GetAll().Select(entity => MapperToApiDto(entity)).ToList();
}
protected GenericsServices(IGenericRepository<T> genericRepository, Func<T, TO> mapperToApiDto, Func<TO, T> mapperToSqlDto)
{
GenericRepository = genericRepository;
MapperToApiDto = mapperToApiDto;
MapperToSqlDto = mapperToSqlDto;
}
public IEnumerable<TO> GetAll()
{
return GenericRepository.GetAll().Select(entity => MapperToApiDto(entity)).ToList();
}
public TO? GetById(uint id)
{
T? entity = GenericRepository.GetById((int)id);
if (entity == null)
return null;
public TO? GetById(uint id)
{
T? entity = GenericRepository.GetById((int)id);
if (entity == null)
return null;
return MapperToApiDto(entity);
}
return MapperToApiDto(entity);
}
public TO? Add(TO apiDto)
{
T sqlDto = MapperToSqlDto(apiDto);
public TO? Add(TO apiDto)
{
T sqlDto = MapperToSqlDto(apiDto);
T? entitySqlValidation = GenericRepository.Add(sqlDto);
if (entitySqlValidation == null)
return null;
T? entitySqlValidation = GenericRepository.Add(sqlDto);
if (entitySqlValidation == null)
return null;
return MapperToApiDto(entitySqlValidation);
}
return MapperToApiDto(entitySqlValidation);
}
public TO? Update(TO apiDto)
{
if (GetById(apiDto.Id) == null)
return null;
public TO? Update(TO apiDto)
{
if (GetById(apiDto.Id) == null)
return null;
T sqlDto = MapperToSqlDto(apiDto);
T? sqlDtoValidation = GenericRepository.Update(sqlDto);
T sqlDto = MapperToSqlDto(apiDto);
T? sqlDtoValidation = GenericRepository.Update(sqlDto);
if (sqlDtoValidation == null)
return null;
if (sqlDtoValidation == null)
return null;
return MapperToApiDto(sqlDtoValidation);
}
return MapperToApiDto(sqlDtoValidation);
}
public bool Delete(uint apiDtoId)
{
return GenericRepository.Delete((int)apiDtoId);
}
public bool Delete(uint apiDtoId)
{
return GenericRepository.Delete((int)apiDtoId);
}
}
}

@ -11,5 +11,4 @@ public class PeriodeEssaiService : GenericsServices<PeriodeEssaiSqlDto, PeriodeE
: base(agenceRepository, PeriodeEssaiMapper.ToApi, PeriodeEssaiMapper.ToSql)
{
}
}

@ -1,18 +1,16 @@
using espacecollab.backend.infrastructure.interfaces;
using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.infrastructure.fake
namespace espacecollab.backend.infrastructure.fake;
public class FakeAgenceRepository : GenericFakeRepository<AgenceSqlDto>, IAgenceRepository
{
public class FakeAgenceRepository : GenericFakeRepository<AgenceSqlDto>, IAgenceRepository
public FakeAgenceRepository()
{
public FakeAgenceRepository()
Context = new List<AgenceSqlDto>
{
Context = new List<AgenceSqlDto>
{
new(1, "Tours"),
new(2, "Clermont-Ferrand")
};
}
new(1, "Tours"),
new(2, "Clermont-Ferrand")
};
}
}
}

@ -1,18 +1,16 @@
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 class FakeBusinessUnitRepository : GenericFakeRepository<BusinessUnitSqlDto>, IBusinessUnitRepository
public FakeBusinessUnitRepository()
{
public FakeBusinessUnitRepository()
Context = new List<BusinessUnitSqlDto>
{
Context = new List<BusinessUnitSqlDto>
{
new(1, "BU 1", 1),
new(2, "BU 2", 1)
};
}
new(1, "BU 1", 1),
new(2, "BU 2", 1)
};
}
}
}

@ -2,41 +2,39 @@
using espacecollab.backend.infrastructure.sql.dtos;
using espacecollab.backend.infrastructure.sql.dtos.Values;
namespace espacecollab.backend.infrastructure.fake
namespace espacecollab.backend.infrastructure.fake;
public class FakeCollaborateurRepository : GenericFakeRepository<CollaborateurSqlDto>, ICollaborateurRepository
{
public class FakeCollaborateurRepository : GenericFakeRepository<CollaborateurSqlDto>, ICollaborateurRepository
public FakeCollaborateurRepository()
{
public FakeCollaborateurRepository()
Context = new List<CollaborateurSqlDto>
{
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)
};
}
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
#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 IList<CollaborateurSqlDto> GetCollaborateursByBusinessUnit(int businessUnitId)
{
return Context.Where(entity => entity.BusinessUnitId == businessUnitId).ToList();
}
public CollaborateurSqlDto GetCollaborateurByApsideMail(string apsideMail)
{
return Context.First(entity => entity.ApsideMail == apsideMail);
}
public IList<CollaborateurSqlDto> GetCollaborateursByReferrer(int referrerId)
{
return Context.Where(entity => entity.ReferrerId == referrerId).ToList();
}
#endregion
public CollaborateurSqlDto GetCollaborateurByApsideMail(string apsideMail)
{
return Context.First(entity => entity.ApsideMail == apsideMail);
}
}
#endregion
}

@ -10,7 +10,6 @@ public class FakeFonctionRepository : GenericFakeRepository<FonctionSqlDto>, IFo
Context = new List<FonctionSqlDto>
{
new(1, "Fonction 1"),
new(2, "Fonction 2")
};
}

@ -11,7 +11,6 @@ public class FakePeriodeEssaiRepository : GenericFakeRepository<PeriodeEssaiSqlD
Context = new List<PeriodeEssaiSqlDto>
{
new(1, new DateTime(2021, 10, 1), new DateTime(2021, 12, 1), new DateTime(2022, 1, 1), "A voir", EnumIssueSql.VALIDEE, 1),
new(2, new DateTime(2021, 10, 1), new DateTime(2021, 12, 1), new DateTime(2022, 1, 1), "Ne pas donner suite", EnumIssueSql.ARRETEE_APSIDE, 2)
};
}

@ -1,49 +1,48 @@
using espacecollab.backend.infrastructure.interfaces;
using espacecollab.backend.infrastructure.sql.dtos.Interfaces;
namespace espacecollab.backend.infrastructure.fake
namespace espacecollab.backend.infrastructure.fake;
public class GenericFakeRepository<T> : IGenericRepository<T> where T : class, IGenericIdSqlDto
{
public class GenericFakeRepository<T> : IGenericRepository<T> where T : class, IGenericIdSqlDto
protected List<T> Context { get; set; } = new();
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(int entityId)
{
T? entity = GetById(entityId);
if (entity == null) return false;
return Context.Remove(entity);
}
public virtual IEnumerable<T> GetAll()
{
protected List<T> Context { get; set; } = new();
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(int entityId)
{
T? entity = GetById(entityId);
if (entity == null) return false;
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);
}
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);
}
}
}

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

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

@ -1,11 +1,10 @@
using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.infrastructure.interfaces
namespace espacecollab.backend.infrastructure.interfaces;
public interface ICollaborateurRepository : IGenericRepository<CollaborateurSqlDto>
{
public interface ICollaborateurRepository : IGenericRepository<CollaborateurSqlDto>
{
CollaborateurSqlDto? GetCollaborateurByApsideMail(string apsideMail);
IList<CollaborateurSqlDto> GetCollaborateursByBusinessUnit(int businessUnitId);
IList<CollaborateurSqlDto> GetCollaborateursByReferrer(int referrerId);
}
CollaborateurSqlDto? GetCollaborateurByApsideMail(string apsideMail);
IList<CollaborateurSqlDto> GetCollaborateursByBusinessUnit(int businessUnitId);
IList<CollaborateurSqlDto> GetCollaborateursByReferrer(int referrerId);
}

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

@ -1,9 +1,8 @@
using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.infrastructure.interfaces
namespace espacecollab.backend.infrastructure.interfaces;
public interface IProjetRepository : IGenericRepository<ProjetSqlDto>
{
public interface IProjetRepository : IGenericRepository<ProjetSqlDto>
{
IList<ProjetSqlDto> GetProjetsByClient(string client);
}
IList<ProjetSqlDto> GetProjetsByClient(string client);
}

@ -1,10 +1,9 @@
using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.infrastructure.interfaces
namespace espacecollab.backend.infrastructure.interfaces;
public interface IReferencementRepository : IGenericRepository<ReferencementSqlDto>
{
public interface IReferencementRepository : IGenericRepository<ReferencementSqlDto>
{
IList<CollaborateurSqlDto>? GetReferrersByCollaborateurId(int collaborateurId);
IList<CollaborateurSqlDto>? GetReferrersByCollaborateurApsideMail(string apsideMail);
}
IList<CollaborateurSqlDto>? GetReferrersByCollaborateurId(int collaborateurId);
IList<CollaborateurSqlDto>? GetReferrersByCollaborateurApsideMail(string apsideMail);
}

@ -1,24 +1,21 @@
using System.Diagnostics.CodeAnalysis;
namespace espacecollab.backend.infrastructure.sql.dtos
{
public class CollaborateurAppartientBusinessUnitSqlDto
{
public int CollaborateurId { get; set; }
public int BusinessUnitId { get; set; }
namespace espacecollab.backend.infrastructure.sql.dtos;
public class CollaborateurAppartientBusinessUnitSqlDto
{
public int CollaborateurId { get; set; }
public int BusinessUnitId { get; set; }
[ExcludeFromCodeCoverage]
private CollaborateurAppartientBusinessUnitSqlDto()
{
}
public CollaborateurAppartientBusinessUnitSqlDto(int collaborateurId, int businessUnitId)
{
CollaborateurId = collaborateurId;
BusinessUnitId = businessUnitId;
}
[ExcludeFromCodeCoverage]
private CollaborateurAppartientBusinessUnitSqlDto()
{
}
public CollaborateurAppartientBusinessUnitSqlDto(int collaborateurId, int businessUnitId)
{
CollaborateurId = collaborateurId;
BusinessUnitId = businessUnitId;
}
}
}

@ -1,24 +1,22 @@
using System.Diagnostics.CodeAnalysis;
namespace espacecollab.backend.infrastructure.sql.dtos
{
public class CollaborateurCollaboreProjetSqlDto
{
public int CollaborateurId { get; set; }
public int ProjetId { get; set; }
public bool IsManager { get; set; }
namespace espacecollab.backend.infrastructure.sql.dtos;
[ExcludeFromCodeCoverage]
private CollaborateurCollaboreProjetSqlDto()
{
}
public class CollaborateurCollaboreProjetSqlDto
{
public int CollaborateurId { get; set; }
public int ProjetId { get; set; }
public bool IsManager { get; set; }
public CollaborateurCollaboreProjetSqlDto(int collaborateurId, int projetId, bool isManager)
{
CollaborateurId = collaborateurId;
ProjetId = projetId;
IsManager = isManager;
}
[ExcludeFromCodeCoverage]
private CollaborateurCollaboreProjetSqlDto()
{
}
public CollaborateurCollaboreProjetSqlDto(int collaborateurId, int projetId, bool isManager)
{
CollaborateurId = collaborateurId;
ProjetId = projetId;
IsManager = isManager;
}
}
}

@ -1,23 +1,20 @@
using System.Diagnostics.CodeAnalysis;
namespace espacecollab.backend.infrastructure.sql.dtos
{
public class CollaborateurEstFonctionSqlDto
{
public int CollaborateurId { get; set; }
public int FonctionId { get; set; }
namespace espacecollab.backend.infrastructure.sql.dtos;
[ExcludeFromCodeCoverage]
private CollaborateurEstFonctionSqlDto()
{
}
public CollaborateurEstFonctionSqlDto(int collaborateurId, int fonctionId)
{
CollaborateurId = collaborateurId;
FonctionId = fonctionId;
}
public class CollaborateurEstFonctionSqlDto
{
public int CollaborateurId { get; set; }
public int FonctionId { get; set; }
[ExcludeFromCodeCoverage]
private CollaborateurEstFonctionSqlDto()
{
}
public CollaborateurEstFonctionSqlDto(int collaborateurId, int fonctionId)
{
CollaborateurId = collaborateurId;
FonctionId = fonctionId;
}
}
}

@ -18,5 +18,4 @@ public class FonctionSqlDto : IGenericIdSqlDto
Id = id;
Name = name;
}
}

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

@ -1,30 +1,29 @@
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 : IGenericIdSqlDto
{
public class ProjetSqlDto : IGenericIdSqlDto
{
public int Id { get; set; }
public string Name { get; set; }
public string Client { get; set; }
public string Description { get; set; }
public DateTime StartingDate { get; set; }
public DateTime EndingDate { get; set; }
public int Id { get; set; }
public string Name { get; set; }
public string Client { get; set; }
public string Description { get; set; }
public DateTime StartingDate { get; set; }
public DateTime EndingDate { get; set; }
[ExcludeFromCodeCoverage]
private ProjetSqlDto()
{
}
[ExcludeFromCodeCoverage]
private ProjetSqlDto()
{
}
public ProjetSqlDto(int id, string name, string client, string description, DateTime startingDate, DateTime endingDate)
{
Id = id;
Name = name;
Client = client;
Description = description;
StartingDate = startingDate;
EndingDate = endingDate;
}
public ProjetSqlDto(int id, string name, string client, string description, DateTime startingDate, DateTime endingDate)
{
Id = id;
Name = name;
Client = client;
Description = description;
StartingDate = startingDate;
EndingDate = endingDate;
}
}
}

@ -1,21 +1,20 @@
using System.Diagnostics.CodeAnalysis;
namespace espacecollab.backend.infrastructure.sql.dtos
namespace espacecollab.backend.infrastructure.sql.dtos;
public class ProjetUtiliseTechnologieSqlDto
{
public class ProjetUtiliseTechnologieSqlDto
{
public int ProjetId { get; set; }
public int TechnologieId { get; set; }
public int ProjetId { get; set; }
public int TechnologieId { get; set; }
[ExcludeFromCodeCoverage]
private ProjetUtiliseTechnologieSqlDto()
{
}
[ExcludeFromCodeCoverage]
private ProjetUtiliseTechnologieSqlDto()
{
}
public ProjetUtiliseTechnologieSqlDto(int projetId, int technologieId)
{
ProjetId = projetId;
TechnologieId = technologieId;
}
public ProjetUtiliseTechnologieSqlDto(int projetId, int technologieId)
{
ProjetId = projetId;
TechnologieId = technologieId;
}
}
}

@ -1,28 +1,27 @@
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 : IGenericIdSqlDto
{
public class ReferencementSqlDto : IGenericIdSqlDto
{
public int Id { get; set; }
public DateTime StartingDate { get; set; }
public DateTime EndingDate { get; set; }
public int ReferredId { get; set; }
public int ReferrerId { get; set; }
public int Id { get; set; }
public DateTime StartingDate { get; set; }
public DateTime EndingDate { get; set; }
public int ReferredId { get; set; }
public int ReferrerId { get; set; }
[ExcludeFromCodeCoverage]
private ReferencementSqlDto()
{
}
[ExcludeFromCodeCoverage]
private ReferencementSqlDto()
{
}
public ReferencementSqlDto(int id, DateTime startingDate, DateTime endingDate, int referredId, int referrerId)
{
Id = id;
StartingDate = startingDate;
EndingDate = endingDate;
ReferredId = referredId;
ReferrerId = referrerId;
}
public ReferencementSqlDto(int id, DateTime startingDate, DateTime endingDate, int referredId, int referrerId)
{
Id = id;
StartingDate = startingDate;
EndingDate = endingDate;
ReferredId = referredId;
ReferrerId = referrerId;
}
}
}

@ -1,24 +1,20 @@
using System.Diagnostics.CodeAnalysis;
namespace espacecollab.backend.infrastructure.sql.dtos
{
public class SiteDeveloppeProjetSqlDto
{
public int SiteId { get; set; }
public int ProjetId { get; set; }
[ExcludeFromCodeCoverage]
private SiteDeveloppeProjetSqlDto()
{
}
public SiteDeveloppeProjetSqlDto(int siteId, int projetId)
{
SiteId = siteId;
ProjetId = projetId;
}
namespace espacecollab.backend.infrastructure.sql.dtos;
public class SiteDeveloppeProjetSqlDto
{
public int SiteId { get; set; }
public int ProjetId { get; set; }
[ExcludeFromCodeCoverage]
private SiteDeveloppeProjetSqlDto()
{
}
public SiteDeveloppeProjetSqlDto(int siteId, int projetId)
{
SiteId = siteId;
ProjetId = projetId;
}
}
}

@ -1,29 +1,25 @@
using System.Diagnostics.CodeAnalysis;
using espacecollab.backend.infrastructure.sql.dtos.Interfaces;
namespace espacecollab.backend.infrastructure.sql.dtos
{
public class SiteSqlDto : IGenericIdSqlDto
{
public int Id { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public int BusinessUnitId { get; set; }
[ExcludeFromCodeCoverage]
private SiteSqlDto()
{
}
public SiteSqlDto(int id, string name, string address, int businessUnitId)
{
Id = id;
Name = name;
Address = address;
BusinessUnitId = businessUnitId;
}
namespace espacecollab.backend.infrastructure.sql.dtos;
public class SiteSqlDto : IGenericIdSqlDto
{
public int Id { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public int BusinessUnitId { get; set; }
[ExcludeFromCodeCoverage]
private SiteSqlDto()
{
}
public SiteSqlDto(int id, string name, string address, int businessUnitId)
{
Id = id;
Name = name;
Address = address;
BusinessUnitId = businessUnitId;
}
}
}

@ -1,23 +1,21 @@
using System.Diagnostics.CodeAnalysis;
using espacecollab.backend.infrastructure.sql.dtos.Interfaces;
using espacecollab.backend.infrastructure.sql.dtos.Interfaces;
using System.Diagnostics.CodeAnalysis;
namespace espacecollab.backend.infrastructure.sql.dtos
{
public class TechnologieSqlDto : IGenericIdSqlDto
{
public int Id { get; set; }
public string Name { get; set; }
namespace espacecollab.backend.infrastructure.sql.dtos;
[ExcludeFromCodeCoverage]
private TechnologieSqlDto()
{
}
public class TechnologieSqlDto : IGenericIdSqlDto
{
public int Id { get; set; }
public string Name { get; set; }
public TechnologieSqlDto(int id, string name)
{
Id = id;
Name = name;
}
[ExcludeFromCodeCoverage]
private TechnologieSqlDto()
{
}
public TechnologieSqlDto(int id, string name)
{
Id = id;
Name = name;
}
}
}

@ -1,9 +1,8 @@
namespace espacecollab.backend.infrastructure.sql.dtos.Values
namespace espacecollab.backend.infrastructure.sql.dtos.Values;
public enum EnumGenreSql
{
public enum EnumGenreSql
{
MASCULIN,
FEMININ,
AUTRE
}
}
MASCULIN,
FEMININ,
AUTRE
}

@ -1,11 +1,10 @@
namespace espacecollab.backend.infrastructure.sql.dtos.Values
namespace espacecollab.backend.infrastructure.sql.dtos.Values;
public enum EnumIssueSql
{
public enum EnumIssueSql
{
VALIDEE,
PROLONGEE_COLLAB,
PROLONGEE_APSIDE,
ARRETEE_COLLAB,
ARRETEE_APSIDE
}
}
VALIDEE,
PROLONGEE_COLLAB,
PROLONGEE_APSIDE,
ARRETEE_COLLAB,
ARRETEE_APSIDE
}

@ -1,10 +1,9 @@
namespace espacecollab.backend.infrastructure.sql.dtos.Values
namespace espacecollab.backend.infrastructure.sql.dtos.Values;
public enum EnumStatutSql
{
public enum EnumStatutSql
{
CADRE,
NONCADRE,
ALTERNANT,
STAGIAIRE
}
}
CADRE,
NONCADRE,
ALTERNANT,
STAGIAIRE
}

@ -2,36 +2,35 @@
using espacecollab.backend.infrastructure.sql.Options;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
namespace espacecollab.backend.infrastructure.sql
namespace espacecollab.backend.infrastructure.sql;
public class MainDbContext : DbContext
{
public class MainDbContext : DbContext
{
private IOptions<SqlOption> SqlSettings { get; }
private DbSet<CollaborateurSqlDto>? Collaborateur { get; set; }
private IOptions<SqlOption> SqlSettings { get; }
public MainDbContext(IOptions<SqlOption> sqlSettings)
{
SqlSettings = sqlSettings;
}
public MainDbContext(IOptions<SqlOption> sqlSettings)
{
SqlSettings = sqlSettings;
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseMySql(SqlSettings.Value.ConnectionString,
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseMySql(SqlSettings.Value.ConnectionString,
ServerVersion.AutoDetect(SqlSettings.Value.ConnectionString))
.EnableSensitiveDataLogging();
}
.EnableSensitiveDataLogging();
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<CollaborateurSqlDto>().Property(p=> p.Id).UseMySqlIdentityColumn();
modelBuilder
.Entity<CollaborateurSqlDto>()
.Property(e => e.Gender)
.HasConversion<string>();
modelBuilder
.Entity<CollaborateurSqlDto>()
.Property(e => e.Status)
.HasConversion<string>();
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<CollaborateurSqlDto>().Property(p => p.Id).UseMySqlIdentityColumn();
modelBuilder
.Entity<CollaborateurSqlDto>()
.Property(e => e.Gender)
.HasConversion<string>();
modelBuilder
.Entity<CollaborateurSqlDto>()
.Property(e => e.Status)
.HasConversion<string>();
}
}
}

@ -1,14 +1,13 @@
namespace espacecollab.backend.infrastructure.sql.Options
namespace espacecollab.backend.infrastructure.sql.Options;
public class SqlOption
{
public class SqlOption
{
public static string Key => "Sql";
public bool LoadFake { get; set; }
public string ConnectionString { get; set; }
public static string Key => "Sql";
public bool LoadFake { get; set; }
public string ConnectionString { get; set; }
public SqlOption()
{
ConnectionString = string.Empty;
}
public SqlOption()
{
ConnectionString = string.Empty;
}
}
}

@ -1,22 +1,21 @@
using espacecollab.backend.infrastructure.interfaces;
using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.infrastructure.sql.Repository
namespace espacecollab.backend.infrastructure.sql.Repository;
public class CollaborateurSqlRepository : GenericSqlRepository<CollaborateurSqlDto>, ICollaborateurRepository
{
public class CollaborateurSqlRepository : GenericSqlRepository<CollaborateurSqlDto>, ICollaborateurRepository
public CollaborateurSqlRepository(MainDbContext context) : base(context)
{
public CollaborateurSqlRepository(MainDbContext context) : base(context)
{
Context = context;
}
Context = context;
}
public IList<CollaborateurSqlDto> GetCollaborateursByBusinessUnit(int businessUnitId)
=> Context.Set<CollaborateurSqlDto>().Where(collaborateur => collaborateur.BusinessUnitId == businessUnitId).ToList();
public IList<CollaborateurSqlDto> GetCollaborateursByBusinessUnit(int businessUnitId)
=> Context.Set<CollaborateurSqlDto>().Where(collaborateur => collaborateur.BusinessUnitId == businessUnitId).ToList();
public IList<CollaborateurSqlDto> GetCollaborateursByReferrer(int referrerId)
=> Context.Set<CollaborateurSqlDto>().Where(collaborateur => collaborateur.ReferrerId == referrerId).ToList();
public IList<CollaborateurSqlDto> GetCollaborateursByReferrer(int referrerId)
=> Context.Set<CollaborateurSqlDto>().Where(collaborateur => collaborateur.ReferrerId == referrerId).ToList();
public CollaborateurSqlDto? GetCollaborateurByApsideMail(string apsideMail)
=> Context?.Set<CollaborateurSqlDto>().SingleOrDefault(collaborateur => collaborateur.ApsideMail == apsideMail);
}
}
public CollaborateurSqlDto? GetCollaborateurByApsideMail(string apsideMail)
=> Context?.Set<CollaborateurSqlDto>().SingleOrDefault(collaborateur => collaborateur.ApsideMail == apsideMail);
}

@ -1,50 +1,51 @@
using espacecollab.backend.infrastructure.interfaces;
using espacecollab.backend.infrastructure.sql.dtos.Interfaces;
using Microsoft.EntityFrameworkCore;
namespace espacecollab.backend.infrastructure.sql.Repository
namespace espacecollab.backend.infrastructure.sql.Repository;
public class GenericSqlRepository<T> : IGenericRepository<T> where T : class, IGenericIdSqlDto
{
public class GenericSqlRepository<T> : IGenericRepository<T> where T : class, IGenericIdSqlDto
protected MainDbContext Context { get; set; }
public GenericSqlRepository(MainDbContext context)
{
Context = context;
}
public virtual T? Add(T entity)
{
protected MainDbContext Context { get; set; }
public GenericSqlRepository(MainDbContext context)
{
Context = context;
}
public virtual T? Add(T entity)
{
Context.Set<T>().Add(entity);
Context.SaveChanges();
return 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;
}
public virtual IEnumerable<T> GetAll()
{
return Context.Set<T>().ToList();
}
public virtual T? GetById(int id)
{
return Context.Set<T>().FirstOrDefault(entity => entity.Id == id);
}
public virtual T? Update(T entity)
{
Context.Set<T>().Update(entity);
Context.SaveChanges();
return Context.Set<T>().FirstOrDefault(e => e.Id == entity.Id);
}
Context.Set<T>().Add(entity);
Context.SaveChanges();
return 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;
}
public virtual IEnumerable<T> GetAll()
{
return Context.Set<T>().ToList();
}
public virtual T? GetById(int id)
{
return Context.Set<T>().SingleOrDefault(entity => entity.Id == id);
}
public virtual T? Update(T entity)
{
Context.Set<T>().Update(entity);
Context.SaveChanges();
return GetById(entity.Id);
}
}
}
Loading…
Cancel
Save