Mise en place d'entités #4

Merged
AlexandreRuiz merged 17 commits from task/tu into develop 3 years ago
  1. 64
      Collaborateur_Epa_Back/espacecollab.backend.api.tests/BaseControllerTest.cs
  2. 24
      Collaborateur_Epa_Back/espacecollab.backend.api.tests/CollaborateursControllerTest.cs
  3. 28
      Collaborateur_Epa_Back/espacecollab.backend.api.tests/espacecollab.backend.api.tests.csproj
  4. 11
      Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/AgencesController.cs
  5. 2
      Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/BaseController.cs
  6. 11
      Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/BusinessUnitController.cs
  7. 28
      Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/BusinessUnitsController.cs
  8. 79
      Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs
  9. 11
      Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/FonctionController.cs
  10. 4
      Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/FonctionsController.cs
  11. 17
      Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/IBaseController.cs
  12. 11
      Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/PeriodeEssaiController.cs
  13. 12
      Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/TechnologiesController.cs
  14. 27
      Collaborateur_Epa_Back/espacecollab.backend.api/Program.cs
  15. 12
      Collaborateur_Epa_Back/espacecollab.backend.api/Register.cs
  16. 87
      Collaborateur_Epa_Back/espacecollab.backend.api/Startup.cs
  17. 8
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/BusinessUnitApiDto.cs
  18. 14
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs
  19. 9
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/EnumGenreApi.cs
  20. 10
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/EnumStatutApi.cs
  21. 8
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/FonctionApiDto.cs
  22. 6
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Interfaces/IGenericIdApiDto.cs
  23. 7
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Interfaces/IGenericIdSqlDto.cs
  24. 15
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/BusinessUnitMapper.cs
  25. 34
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/CollaborateurApiDtoMapper.cs
  26. 44
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/EnumGenreMapper.cs
  27. 48
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/EnumStatutMapper.cs
  28. 15
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/FonctionMapper.cs
  29. 22
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/PeriodeEssaiMapper.cs
  30. 15
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/TechnologieMapper.cs
  31. 9
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/PeriodeEssaiApiDto.cs
  32. 8
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/TechnologieApiDto.cs
  33. 8
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Values/EnumGenreApi.cs
  34. 10
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Values/EnumIssueApi.cs
  35. 9
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Values/EnumStatutApi.cs
  36. 19
      Collaborateur_Epa_Back/espacecollab.backend.appservices.interfaces/IGenericsServices.cs
  37. 2
      Collaborateur_Epa_Back/espacecollab.backend.appservices/AgenceService.cs
  38. 20
      Collaborateur_Epa_Back/espacecollab.backend.appservices/BusinessUnitService.cs
  39. 35
      Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursService.cs
  40. 36
      Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs
  41. 14
      Collaborateur_Epa_Back/espacecollab.backend.appservices/FonctionService.cs
  42. 92
      Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs
  43. 14
      Collaborateur_Epa_Back/espacecollab.backend.appservices/PeriodeEssaiService.cs
  44. 14
      Collaborateur_Epa_Back/espacecollab.backend.appservices/TechnologieServices.cs
  45. 20
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeAgenceRepository.cs
  46. 21
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeBusinessUnitRepository.cs
  47. 58
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeCollaborateurRepository.cs
  48. 16
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeFonctionRepository.cs
  49. 17
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakePeriodeEssaiRepository.cs
  50. 85
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/GenericFakeRepository.cs
  51. 7
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IAgenceRepository.cs
  52. 8
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IBusinessUnitRepository.cs
  53. 13
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/ICollaborateurRepository.cs
  54. 8
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IFonctionRepository.cs
  55. 18
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IGenericRepository.cs
  56. 7
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IPeriodeEssaiRepository.cs
  57. 9
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IProjetRepository.cs
  58. 11
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IReferencementRepository.cs
  59. 8
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/ITechnologieRepository.cs
  60. 30
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/AgenceSqlDto.cs
  61. 35
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/BusinessUnitSqlDto.cs
  62. 31
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurAppartientBusinessUnitSqlDto.cs
  63. 34
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurCollaboreProjetSqlDto.cs
  64. 31
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurEstFonctionSqlDto.cs
  65. 92
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurSqlDto.cs
  66. 14
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/FonctionSqlDto.cs
  67. 11
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/Interfaces/IGenericIdSqlDto.cs
  68. 51
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/PeriodeEssaiSqlDto.cs
  69. 45
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetSqlDto.cs
  70. 29
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetUtiliseTechnologieSqlDto.cs
  71. 41
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ReferencementSqlDto.cs
  72. 32
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteDeveloppeProjetSqlDto.cs
  73. 40
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteSqlDto.cs
  74. 34
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/TechnologieSqlDto.cs
  75. 15
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/Values/EnumGenreSql.cs
  76. 19
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/Values/EnumIssueSql.cs
  77. 17
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/Values/EnumStatutSql.cs
  78. 61
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/MainDbContext.cs
  79. 21
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Options/SqlOption.cs
  80. 14
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/BusinessUnitSqlRepository.cs
  81. 27
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/CollaborateurSqlRepository.cs
  82. 11
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/FonctionSqlRepository.cs
  83. 89
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/GenericSqlRepository.cs
  84. 11
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/PeriodeEssaiSqlRepository.cs
  85. 11
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/TechnologieSqlRepository.cs
  86. 9
      Collaborateur_Epa_Back/espacecollab.backend.sln

@ -0,0 +1,64 @@
using System.Collections.Generic;
using espacecollab.backend.api.Controllers;
using espacecollab.backend.appservices.dtos.Interfaces;
using FluentAssertions;
using Microsoft.AspNetCore.Mvc;
using Xunit;
namespace espacecollab.backend.api.tests;
public abstract class BaseControllerTest<T, TO> where T : IBaseController<TO>
where TO : class, IGenericIdApiDto
{
protected T Controller { get; set; }
protected TO NewApiDo { get; set; }
protected TO UpdateApiDo { get; set; }
[Fact]
public void GetAllTest()
{
ActionResult<IEnumerable<TO>> actionResult = Controller.GetAll();
OkObjectResult result = actionResult.Result.Should().BeOfType<OkObjectResult>().Subject;
result.Value.Should().BeOfType<List<TO>>();
}
[Fact]
public void GetByIdTest()
{
uint id = 1;
ActionResult<TO> actionResult = Controller.GetById(id);
OkObjectResult result = actionResult.Result.Should().BeOfType<OkObjectResult>().Subject;
result.Value.Should().BeOfType<TO>();
}
[Fact]
public void AddTest()
{
ActionResult<TO> actionResult = Controller.Add(NewApiDo);
OkObjectResult result = actionResult.Result.Should().BeOfType<OkObjectResult>().Subject;
result.Value.Should().BeOfType<TO>().Subject.Id.Should().NotBe(0);
}
[Fact]
public void DeleteTest()
{
uint id = 1;
ActionResult<TO> actionResult = Controller.Delete(id);
actionResult.Result.Should().BeOfType<OkResult>();
}
[Fact]
public void UpdateTest()
{
ActionResult<TO> actionResult = Controller.Update(UpdateApiDo.Id, UpdateApiDo);
OkObjectResult result = actionResult.Result.Should().BeOfType<OkObjectResult>().Subject;
result.Value.Should().BeOfType<TO>().Subject.Id.Should().Be(UpdateApiDo.Id);
}
}

@ -0,0 +1,24 @@
using espacecollab.backend.api.Controllers;
using espacecollab.backend.appservices;
using espacecollab.backend.appservices.dtos;
using espacecollab.backend.appservices.dtos.Values;
using espacecollab.backend.infrastructure.fake;
using System;
namespace espacecollab.backend.api.tests;
public class CollaborateursControllerTest : BaseControllerTest<CollaborateursController, CollaborateurApiDto>
{
public CollaborateursControllerTest()
{
Controller = new CollaborateursController(new CollaborateursService(new FakeCollaborateurRepository()));
NewApiDo = new CollaborateurApiDto(0, "Dupont", "Jean", new DateTime(1980, 12, 10),
EnumGenreApi.MASCULIN, EnumStatutApi.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);
UpdateApiDo = new CollaborateurApiDto(1, "Dupont 2", "Jean", new DateTime(1980, 12, 10),
EnumGenreApi.MASCULIN, EnumStatutApi.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);
}
}

@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.3.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\espacecollab.backend.api\espacecollab.backend.api.csproj" />
</ItemGroup>
</Project>

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

@ -6,7 +6,7 @@ namespace espacecollab.backend.api.Controllers
{
[Route("api/[controller]")]
[ApiController]
public abstract class BaseController<TO> : Controller where TO : class, IGenericIdApiDto
public abstract class BaseController<TO> : Controller, IBaseController<TO> where TO : class, IGenericIdApiDto
{
protected IGenericsServices<TO> Services { get; }

@ -0,0 +1,11 @@
using espacecollab.backend.appservices;
using espacecollab.backend.appservices.dtos;
namespace espacecollab.backend.api.Controllers;
public class BusinessUnitController : BaseController<BusinessUnitApiDto>
{
public BusinessUnitController(BusinessUnitService businessUnitService) : base(businessUnitService)
{
}
}

@ -0,0 +1,28 @@
using espacecollab.backend.appservices;
using espacecollab.backend.appservices.dtos;
using Microsoft.AspNetCore.Mvc;
namespace espacecollab.backend.api.Controllers
{
//[Route("api/[controller]")]
//[ApiController]
public class BusinessUnitsController : BaseController<BusinessUnitApiDto>
{
private BusinessUnitService BusinessUnitServices { get; }
public BusinessUnitsController(BusinessUnitService businessUnitServices) : base(businessUnitServices)
{
BusinessUnitServices = businessUnitServices;
}
[HttpGet("agence/{agenceId:int:min(1)}")]
public ActionResult<IEnumerable<BusinessUnitApiDto>> GetBusinessUnitsByAgence(uint agenceId)
{
IEnumerable<BusinessUnitApiDto> businessUnits = BusinessUnitServices.GetBusinessUnitsByAgence(agenceId);
if (!businessUnits.Any())
return NotFound();
return Ok(businessUnits);
}
}
}

@ -2,47 +2,44 @@
using espacecollab.backend.appservices.dtos;
using Microsoft.AspNetCore.Mvc;
namespace espacecollab.backend.api.Controllers
namespace espacecollab.backend.api.Controllers;
public class CollaborateursController : BaseController<CollaborateurApiDto>
{
//[Route("api/[controller]")]
//[ApiController]
public class CollaborateursController : BaseController<CollaborateurApiDto>
private CollaborateursService CollaborateursServices { get; }
public CollaborateursController(CollaborateursService collaborateursServices) : base(collaborateursServices)
{
CollaborateursServices = collaborateursServices;
}
[HttpGet("businessunit/{businessUnitId:int:min(1)}")]
public ActionResult<IEnumerable<CollaborateurApiDto>> GetCollaborateursByBusinessUnit(uint businessUnitId)
{
IEnumerable<CollaborateurApiDto> collaborateurs = CollaborateursServices.GetCollaborateursByBusinessUnit(businessUnitId);
if (!collaborateurs.Any())
return NotFound();
return Ok(collaborateurs);
}
[HttpGet("referrer/{referrerId:int:min(1)}")]
public ActionResult<IEnumerable<CollaborateurApiDto>> GetCollaborateursByReferrer(uint referrerId)
{
private CollaborateursServices CollaborateursServices { get; }
public CollaborateursController(CollaborateursServices collaborateursServices) : base(collaborateursServices)
{
CollaborateursServices = collaborateursServices;
}
[HttpGet("businessunit/{businessUnitId:int:min(1)}")]
public ActionResult<IEnumerable<CollaborateurApiDto>> GetCollaborateursByBusinessUnit(uint businessUnitId)
{
IEnumerable<CollaborateurApiDto> collaborateurs = CollaborateursServices.GetCollaborateursByBusinessUnit(businessUnitId);
if (!collaborateurs.Any())
return NotFound();
return Ok(collaborateurs);
}
[HttpGet("referrer/{referrerId:int:min(1)}")]
public ActionResult<IEnumerable<CollaborateurApiDto>> GetCollaborateursByReferrer(uint referrerId)
{
IEnumerable<CollaborateurApiDto> collaborateurs = CollaborateursServices.GetCollaborateursByReferrer(referrerId);
if (!collaborateurs.Any())
return NotFound();
return Ok(collaborateurs);
}
[HttpGet("apsidemail/{apsideMail:minlength(1):regex(^\\S.*)}")]
public ActionResult<CollaborateurApiDto> GetCollaborateurByApsideMail(string apsideMail)
{
CollaborateurApiDto? collaborateur = CollaborateursServices.GetCollaborateurByApsideMail(apsideMail);
if (collaborateur == null)
return NotFound();
return Ok(collaborateur);
}
IEnumerable<CollaborateurApiDto> collaborateurs = CollaborateursServices.GetCollaborateursByReferrer(referrerId);
if (!collaborateurs.Any())
return NotFound();
return Ok(collaborateurs);
}
[HttpGet("apsidemail/{apsideMail:minlength(1):regex(^\\S.*)}")]
public ActionResult<CollaborateurApiDto> GetCollaborateurByApsideMail(string apsideMail)
{
CollaborateurApiDto? collaborateur = CollaborateursServices.GetCollaborateurByApsideMail(apsideMail);
if (collaborateur == null)
return NotFound();
return Ok(collaborateur);
}
}
}

@ -0,0 +1,11 @@
using espacecollab.backend.appservices;
using espacecollab.backend.appservices.dtos;
namespace espacecollab.backend.api.Controllers;
public class FonctionController : BaseController<FonctionApiDto>
{
public FonctionController(FonctionService fonctionService) : base(fonctionService)
{
}
}

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

@ -0,0 +1,17 @@
using espacecollab.backend.appservices.dtos.Interfaces;
using Microsoft.AspNetCore.Mvc;
namespace espacecollab.backend.api.Controllers;
public interface IBaseController<TO> where TO : class, IGenericIdApiDto
{
ActionResult<IEnumerable<TO>> GetAll();
ActionResult<TO> GetById(uint id);
ActionResult<TO> Add(TO apiDto);
ActionResult Delete(uint id);
ActionResult<TO> Update(uint id, TO apiDto);
}

@ -0,0 +1,11 @@
using espacecollab.backend.appservices;
using espacecollab.backend.appservices.dtos;
namespace espacecollab.backend.api.Controllers;
public class PeriodeEssaiController : BaseController<PeriodeEssaiApiDto>
{
public PeriodeEssaiController(PeriodeEssaiService periodeEssaiService) : base(periodeEssaiService)
{
}
}

@ -0,0 +1,12 @@
using espacecollab.backend.appservices;
using espacecollab.backend.appservices.dtos;
namespace espacecollab.backend.api.Controllers
{
public class TechnologiesController : BaseController<TechnologieApiDto>
{
public TechnologiesController(TechnologieServices technologieServices) : base(technologieServices)
{
}
}
}

@ -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,19 +12,29 @@ 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>();
services.AddScoped<PeriodeEssaiService>();
if (contextOptions.LoadFake)
{
services.AddSingleton<ICollaborateurRepository, FakeCollaborateurRepository>();
services.AddSingleton<IAgenceRepository, FakeAgenceRepository>();
services.AddSingleton<IBusinessUnitRepository, FakeBusinessUnitRepository>();
services.AddSingleton<IFonctionRepository, FakeFonctionRepository>();
services.AddSingleton<IPeriodeEssaiRepository, FakePeriodeEssaiRepository>();
}
else
{
services.AddScoped<MainDbContext>();
services.AddScoped<ICollaborateurRepository, CollaborateurSqlRepository>();
services.AddScoped<IAgenceRepository, AgenceSqlRepository>();
services.AddScoped<IBusinessUnitRepository, BusinessUnitSqlRepository>();
services.AddScoped<IFonctionRepository, FonctionSqlRepository>();
services.AddScoped<ITechnologieRepository, TechnologieSqlRepository>();
services.AddScoped<IPeriodeEssaiRepository, PeriodeEssaiSqlRepository>();
}
}
}

@ -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();
});
}
}
}

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

@ -1,10 +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, DateTime BirthDate, EnumGenreApi Gender, EnumStatutApi Status, int ChildrenNumber, string Address,
string Telephone, string PersonalMail, string ApsideMail, DateTime 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,9 +0,0 @@
namespace espacecollab.backend.appservices.dtos
{
public enum EnumGenreApi
{
MASCULIN,
FEMININ,
AUTRE
}
}

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

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

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

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

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

@ -1,24 +1,22 @@
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, collaborateurSql.Gender.ToEnumGenreApi(), collaborateurSql.Status.ToEnumStatutApi(), collaborateurSql.ChildrenNumber,
collaborateurSql.Address, collaborateurSql.Telephone, collaborateurSql.PersonalMail, collaborateurSql.ApsideMail,
collaborateurSql.ResignationDate, 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,
collaborateurApi.BirthDate, collaborateurApi.Gender.ToEnumGenreSql(), collaborateurApi.Status.ToEnumStatutSql(), collaborateurApi.ChildrenNumber,
collaborateurApi.Address, collaborateurApi.Telephone, collaborateurApi.PersonalMail, collaborateurApi.ApsideMail,
collaborateurApi.ResignationDate, collaborateurApi.ReferrerId, collaborateurApi.BusinessUnitId);
}
}
}

@ -1,29 +1,29 @@
using espacecollab.backend.infrastructure.sql.dtos.Values;
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,31 +1,31 @@
using espacecollab.backend.infrastructure.sql.dtos.Values;
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,
};
}
}
}

@ -0,0 +1,15 @@
using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.appservices.dtos.Mappers;
public static class FonctionMapper
{
public static FonctionApiDto ToApi(this FonctionSqlDto fonctionSqlDto)
{
return new FonctionApiDto((uint)fonctionSqlDto.Id, fonctionSqlDto.Intitule);
}
public static FonctionSqlDto ToSql(this FonctionApiDto fonctionApiDto)
{
return new FonctionSqlDto((int)fonctionApiDto.Id, fonctionApiDto.Intitule);
}
}

@ -0,0 +1,22 @@
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;
public static class PeriodeEssaiMapper
{
public static PeriodeEssaiApiDto ToApi(this PeriodeEssaiSqlDto periodeEssaiSqlDto)
{
return new PeriodeEssaiApiDto((uint)periodeEssaiSqlDto.Id, periodeEssaiSqlDto.StartingDate,
periodeEssaiSqlDto.PlannedEndingDate, periodeEssaiSqlDto.RealEndingDate, periodeEssaiSqlDto.Comment,
(EnumIssueApi)periodeEssaiSqlDto.Issue, (uint)periodeEssaiSqlDto.CollaborateurId);
}
public static PeriodeEssaiSqlDto ToSql(this PeriodeEssaiApiDto periodeEssaiApiDto)
{
return new PeriodeEssaiSqlDto((int)periodeEssaiApiDto.Id, periodeEssaiApiDto.StartingDate,
periodeEssaiApiDto.PlannedEndingDate, periodeEssaiApiDto.RealEndingDate, periodeEssaiApiDto.Comment,
(EnumIssueSql)periodeEssaiApiDto.Issue, (int)periodeEssaiApiDto.CollaborateurId);
}
}

@ -0,0 +1,15 @@
using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.appservices.dtos.Mappers;
public static class TechnologieMapper
{
public static TechnologieApiDto ToApi(this TechnologieSqlDto technologieSqlDto)
{
return new TechnologieApiDto((uint)technologieSqlDto.Id, technologieSqlDto.Name);
}
public static TechnologieSqlDto ToSql(this TechnologieApiDto technologieApiDto)
{
return new TechnologieSqlDto((int)technologieApiDto.Id, technologieApiDto.Name);
}
}

@ -0,0 +1,9 @@
using espacecollab.backend.appservices.dtos.Interfaces;
using espacecollab.backend.appservices.dtos.Values;
namespace espacecollab.backend.appservices.dtos;
public record PeriodeEssaiApiDto(uint Id, DateTime StartingDate, DateTime PlannedEndingDate, DateTime RealEndingDate, string Comment, EnumIssueApi Issue, uint CollaborateurId) : IGenericIdApiDto
{
public uint Id { get; set; } = Id;
}

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

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

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

@ -0,0 +1,9 @@
namespace espacecollab.backend.appservices.dtos.Values;
public enum EnumStatutApi
{
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)
{
}
}

@ -0,0 +1,20 @@
using espacecollab.backend.appservices.dtos;
using espacecollab.backend.appservices.dtos.Mappers;
using espacecollab.backend.infrastructure.interfaces;
using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.appservices;
public class BusinessUnitService : GenericsServices<BusinessUnitSqlDto, BusinessUnitApiDto>
{
private IBusinessUnitRepository BusinessUnitRepository { get; }
public BusinessUnitService(IBusinessUnitRepository businessUnitRepository)
:base(businessUnitRepository, BusinessUnitMapper.ToApi, BusinessUnitMapper.ToSql)
{}
public IEnumerable<BusinessUnitApiDto> GetBusinessUnitsByAgence(uint agenceId)
{
return BusinessUnitRepository.GetBusinessUnitsByAgence((int)agenceId).Select(bu => bu.ToApi());
}
}

@ -0,0 +1,35 @@
using espacecollab.backend.appservices.dtos;
using espacecollab.backend.appservices.dtos.Mappers;
using espacecollab.backend.infrastructure.interfaces;
using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.appservices;
public class CollaborateursService : GenericsServices<CollaborateurSqlDto, CollaborateurApiDto>
{
private ICollaborateurRepository CollaborateurRepository { get; }
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> GetCollaborateursByReferrer(uint referrerId)
{
return CollaborateurRepository.GetCollaborateursByReferrer((int)referrerId).Select(collaborateurSql => collaborateurSql.ToApi());
}
public CollaborateurApiDto? GetCollaborateurByApsideMail(string apsideMail)
{
if (string.IsNullOrEmpty(apsideMail))
return null;
return CollaborateurRepository.GetCollaborateurByApsideMail(apsideMail)?.ToApi();
}
}

@ -1,36 +0,0 @@
using espacecollab.backend.appservices.dtos;
using espacecollab.backend.appservices.dtos.Mappers;
using espacecollab.backend.infrastructure.interfaces;
using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.appservices
{
public class CollaborateursServices : GenericsServices<CollaborateurSqlDto, CollaborateurApiDto>
{
private ICollaborateurRepository CollaborateurRepository { get; }
public CollaborateursServices(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> GetCollaborateursByReferrer(uint referrerId)
{
return CollaborateurRepository.GetCollaborateursByReferrer((int)referrerId).Select(collaborateurSql => collaborateurSql.ToApi());
}
public CollaborateurApiDto? GetCollaborateurByApsideMail(string apsideMail)
{
if (string.IsNullOrEmpty(apsideMail))
return null;
return CollaborateurRepository.GetCollaborateurByApsideMail(apsideMail)?.ToApi();
}
}
}

@ -0,0 +1,14 @@
using espacecollab.backend.appservices.dtos;
using espacecollab.backend.appservices.dtos.Mappers;
using espacecollab.backend.infrastructure.interfaces;
using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.appservices;
public class FonctionService : GenericsServices<FonctionSqlDto, FonctionApiDto>
{
public FonctionService(IFonctionRepository fonctionRepository)
:base(fonctionRepository, FonctionMapper.ToApi, FonctionMapper.ToSql)
{
}
}

@ -3,62 +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; }
protected GenericsServices(IGenericRepository<T> genericRepository, Func<T, TO> mapperToApiDto, Func<TO, T> mapperToSqlDto)
{
private Func<T, TO> MapperToApiDto { get; }
private Func<TO, T> MapperToSqlDto { get; }
private IGenericRepository<T> GenericRepository { get; }
GenericRepository = genericRepository;
MapperToApiDto = mapperToApiDto;
MapperToSqlDto = mapperToSqlDto;
}
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 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)
{
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);
}
}
}

@ -0,0 +1,14 @@
using espacecollab.backend.appservices.dtos;
using espacecollab.backend.appservices.dtos.Mappers;
using espacecollab.backend.infrastructure.interfaces;
using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.appservices;
public class PeriodeEssaiService : GenericsServices<PeriodeEssaiSqlDto, PeriodeEssaiApiDto>
{
public PeriodeEssaiService(IPeriodeEssaiRepository agenceRepository)
: base(agenceRepository, PeriodeEssaiMapper.ToApi, PeriodeEssaiMapper.ToSql)
{
}
}

@ -0,0 +1,14 @@
using espacecollab.backend.appservices.dtos;
using espacecollab.backend.appservices.dtos.Mappers;
using espacecollab.backend.infrastructure.interfaces;
using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.appservices;
public class TechnologieServices : GenericsServices<TechnologieSqlDto, TechnologieApiDto>
{
public TechnologieServices(ITechnologieRepository technologieRepository)
:base(technologieRepository, TechnologieMapper.ToApi, TechnologieMapper.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")
};
}
}
}

@ -0,0 +1,21 @@
using espacecollab.backend.infrastructure.interfaces;
using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.infrastructure.fake;
public class FakeBusinessUnitRepository : GenericFakeRepository<BusinessUnitSqlDto>, IBusinessUnitRepository
{
public FakeBusinessUnitRepository()
{
Context = new List<BusinessUnitSqlDto>
{
new(1, "BU 1", 1),
new(2, "BU 2", 1)
};
}
public IList<BusinessUnitSqlDto> GetBusinessUnitsByAgence(int agenceId)
{
return Context.Where(c => c.AgenceId == agenceId).ToList();
}
}

@ -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
}

@ -0,0 +1,16 @@
using espacecollab.backend.infrastructure.interfaces;
using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.infrastructure.fake;
public class FakeFonctionRepository : GenericFakeRepository<FonctionSqlDto>, IFonctionRepository
{
public FakeFonctionRepository()
{
Context = new List<FonctionSqlDto>
{
new(1, "Fonction 1"),
new(2, "Fonction 2")
};
}
}

@ -0,0 +1,17 @@
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 FakePeriodeEssaiRepository : GenericFakeRepository<PeriodeEssaiSqlDto>, IPeriodeEssaiRepository
{
public FakePeriodeEssaiRepository()
{
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; }
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,8 @@
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>
{
}
public IList<BusinessUnitSqlDto> GetBusinessUnitsByAgence(int agenceId);
}

@ -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);
}

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

@ -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,8 +1,7 @@
using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.infrastructure.interfaces
namespace espacecollab.backend.infrastructure.interfaces;
public interface IPeriodeEssaiRepository : IGenericRepository<PeriodeEssaiSqlDto>
{
public interface IPeriodeEssaiRepository : IGenericRepository<PeriodeEssaiSqlDto>
{
}
}

@ -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);
}

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

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

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

@ -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;
}
}
}

@ -3,54 +3,52 @@ using System.Diagnostics.CodeAnalysis;
using espacecollab.backend.infrastructure.sql.dtos.Interfaces;
using System.ComponentModel.DataAnnotations;
namespace espacecollab.backend.infrastructure.sql.dtos
{
public class CollaborateurSqlDto : IGenericIdSqlDto
{
[Key]
public int Id { get; set; }
public string Name { get; set; }
public string FirstName { get; set; }
public DateTime BirthDate { get; set; }
public EnumGenreSql Gender { get; set; }
public EnumStatutSql Status { get; set; }
public int ChildrenNumber { get; set; }
public string Address { get; set; }
public string Telephone { get; set; }
public string PersonalMail { get; set; }
public string ApsideMail { get; set; }
public DateTime ResignationDate { get; set; }
public int ReferrerId { get; set; }
public int BusinessUnitId { get; set; }
namespace espacecollab.backend.infrastructure.sql.dtos;
[ExcludeFromCodeCoverage]
private CollaborateurSqlDto()
{
Name = string.Empty;
FirstName = string.Empty;
Address = string.Empty;
Telephone = string.Empty;
PersonalMail = string.Empty;
ApsideMail = string.Empty;
}
public class CollaborateurSqlDto : IGenericIdSqlDto
{
[Key]
public int Id { get; set; }
public string Name { get; set; }
public string FirstName { get; set; }
public DateTime BirthDate { get; set; }
public EnumGenreSql Gender { get; set; }
public EnumStatutSql Status { get; set; }
public int ChildrenNumber { get; set; }
public string Address { get; set; }
public string Telephone { get; set; }
public string PersonalMail { get; set; }
public string ApsideMail { get; set; }
public DateTime ResignationDate { get; set; }
public int ReferrerId { get; set; }
public int BusinessUnitId { get; set; }
public CollaborateurSqlDto(int id, string name, string firstName, DateTime birthDate, EnumGenreSql gender, EnumStatutSql status, int childrenNumber, string address, string telephone, string personalMail, string apsideMail, DateTime resignationDate, int referrerId, int businessUnitId)
{
Id = id;
Name = name;
FirstName = firstName;
BirthDate = birthDate;
Gender = gender;
Status = status;
ChildrenNumber = childrenNumber;
Address = address;
Telephone = telephone;
PersonalMail = personalMail;
ApsideMail = apsideMail;
ResignationDate = resignationDate;
ReferrerId = referrerId;
BusinessUnitId = businessUnitId;
}
[ExcludeFromCodeCoverage]
private CollaborateurSqlDto()
{
Name = string.Empty;
FirstName = string.Empty;
Address = string.Empty;
Telephone = string.Empty;
PersonalMail = string.Empty;
ApsideMail = string.Empty;
}
public CollaborateurSqlDto(int id, string name, string firstName, DateTime birthDate, EnumGenreSql gender, EnumStatutSql status, int childrenNumber, string address, string telephone, string personalMail, string apsideMail, DateTime resignationDate, int referrerId, int businessUnitId)
{
Id = id;
Name = name;
FirstName = firstName;
BirthDate = birthDate;
Gender = gender;
Status = status;
ChildrenNumber = childrenNumber;
Address = address;
Telephone = telephone;
PersonalMail = personalMail;
ApsideMail = apsideMail;
ResignationDate = resignationDate;
ReferrerId = referrerId;
BusinessUnitId = businessUnitId;
}
}
}

@ -6,17 +6,17 @@ namespace espacecollab.backend.infrastructure.sql.dtos
public class FonctionSqlDto : IGenericIdSqlDto
{
public int Id { get; set; }
public string Name { get; set; }
public string Intitule { get; set; }
[ExcludeFromCodeCoverage]
private FonctionSqlDto()
{
}
[ExcludeFromCodeCoverage]
private FonctionSqlDto()
{
}
public FonctionSqlDto(int id, string name)
public FonctionSqlDto(int id, string intitule)
{
Id = id;
Name = name;
Intitule = intitule;
}

@ -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; }
}

@ -2,33 +2,32 @@
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 : IGenericIdSqlDto
{
public class PeriodeEssaiSqlDto : IGenericIdSqlDto
{
public int Id { get; set; }
public DateTime StartingDate { get; set; }
public DateTime PlannedEndingDate { get; set; }
public DateTime RealEndingDate { get; set; }
public string Comment { get; set; }
public EnumIssueSql Issue { get; set; }
public int CollaborateurId { get; set; }
public int Id { get; set; }
public DateTime StartingDate { get; set; }
public DateTime PlannedEndingDate { get; set; }
public DateTime RealEndingDate { get; set; }
public string Comment { get; set; }
public EnumIssueSql Issue { get; set; }
public int CollaborateurId { get; set; }
[ExcludeFromCodeCoverage]
private PeriodeEssaiSqlDto()
{
Comment = string.Empty;
}
[ExcludeFromCodeCoverage]
private PeriodeEssaiSqlDto()
{
Comment = string.Empty;
}
public PeriodeEssaiSqlDto(int id, DateTime startingDate, DateTime plannedEndingDate, DateTime realEndingDate, string comment, EnumIssueSql issue, int collaborateurId)
{
Id = id;
StartingDate = startingDate;
PlannedEndingDate = plannedEndingDate;
RealEndingDate = realEndingDate;
Comment = comment;
Issue = issue;
CollaborateurId = collaborateurId;
}
public PeriodeEssaiSqlDto(int id, DateTime startingDate, DateTime plannedEndingDate, DateTime realEndingDate, string comment, EnumIssueSql issue, int collaborateurId)
{
Id = id;
StartingDate = startingDate;
PlannedEndingDate = plannedEndingDate;
RealEndingDate = realEndingDate;
Comment = comment;
Issue = issue;
CollaborateurId = collaborateurId;
}
}
}

@ -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,38 +2,41 @@
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 DbSet<AgenceSqlDto>? Agence { 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<BusinessUnitSqlDto>().Property(p => p.Id).UseMySqlIdentityColumn();
modelBuilder.Entity<AgenceSqlDto>().Property(p => p.Id).UseMySqlIdentityColumn();
modelBuilder.Entity<FonctionSqlDto>().Property(p => p.Id).UseMySqlIdentityColumn();
modelBuilder.Entity<TechnologieSqlDto>().Property(p => p.Id).UseMySqlIdentityColumn();
modelBuilder.Entity<CollaborateurSqlDto>().Property(p => p.Id).UseMySqlIdentityColumn();
modelBuilder
.Entity<CollaborateurSqlDto>()
.Property(e => e.Gender)
.HasConversion<string>();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<AgenceSqlDto>().Property(p => p.Id).UseMySqlIdentityColumn();
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>();
}
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;
}
}
}

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

@ -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);
}

@ -0,0 +1,11 @@
using espacecollab.backend.infrastructure.interfaces;
using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.infrastructure.sql.Repository;
public class FonctionSqlRepository : GenericSqlRepository<FonctionSqlDto>, IFonctionRepository
{
public FonctionSqlRepository(MainDbContext context) : base(context)
{
}
}

@ -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);
}
}
}

@ -0,0 +1,11 @@
using espacecollab.backend.infrastructure.interfaces;
using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.infrastructure.sql.Repository;
public class PeriodeEssaiSqlRepository: GenericSqlRepository<PeriodeEssaiSqlDto>, IPeriodeEssaiRepository
{
public PeriodeEssaiSqlRepository(MainDbContext context) : base(context)
{
}
}

@ -0,0 +1,11 @@
using espacecollab.backend.infrastructure.interfaces;
using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.infrastructure.sql.Repository;
public class TechnologieSqlRepository : GenericSqlRepository<TechnologieSqlDto>, ITechnologieRepository
{
public TechnologieSqlRepository(MainDbContext context) : base(context)
{
}
}

@ -23,7 +23,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "espacecollab.backend.infras
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "espacecollab.backend.infrastructure.fake", "espacecollab.backend.infrastructure.fake\espacecollab.backend.infrastructure.fake.csproj", "{48253B9B-9B42-48CF-A95F-358171BABA74}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "espacecollab.backend.appservices.interfaces", "espacecollab.backend.appservices.interfaces\espacecollab.backend.appservices.interfaces.csproj", "{7872657E-46E2-44A1-AFA6-0D3B9E45084A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "espacecollab.backend.appservices.interfaces", "espacecollab.backend.appservices.interfaces\espacecollab.backend.appservices.interfaces.csproj", "{7872657E-46E2-44A1-AFA6-0D3B9E45084A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "espacecollab.backend.api.tests", "espacecollab.backend.api.tests\espacecollab.backend.api.tests.csproj", "{5EA7CAB6-B7A8-4A54-8A1D-774A376974CB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -63,6 +65,10 @@ Global
{7872657E-46E2-44A1-AFA6-0D3B9E45084A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7872657E-46E2-44A1-AFA6-0D3B9E45084A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7872657E-46E2-44A1-AFA6-0D3B9E45084A}.Release|Any CPU.Build.0 = Release|Any CPU
{5EA7CAB6-B7A8-4A54-8A1D-774A376974CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5EA7CAB6-B7A8-4A54-8A1D-774A376974CB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5EA7CAB6-B7A8-4A54-8A1D-774A376974CB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5EA7CAB6-B7A8-4A54-8A1D-774A376974CB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -76,6 +82,7 @@ Global
{3E9E4801-D686-4581-8051-E0E1B036AC70} = {E29F5CA9-ABAF-4437-8633-49FF27110E6D}
{48253B9B-9B42-48CF-A95F-358171BABA74} = {E29F5CA9-ABAF-4437-8633-49FF27110E6D}
{7872657E-46E2-44A1-AFA6-0D3B9E45084A} = {CE5199B3-E423-46C1-B141-18C46473D964}
{5EA7CAB6-B7A8-4A54-8A1D-774A376974CB} = {19237F76-6CA9-47DF-87F8-8027C78070C9}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0A56A44C-135E-4CE4-834B-8DFDF69DC415}

Loading…
Cancel
Save