Ajout de controller, service et repository + généricité + fix de program et startup et settings

pull/2/head
Clement FERRERE 3 years ago
parent 7b7bd77e6e
commit faf2cccee7
  1. 25
      Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs
  2. 43
      Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/GenericsController.cs
  3. 1
      Collaborateur_Epa_Back/espacecollab.backend.api/Program.cs
  4. 12
      Collaborateur_Epa_Back/espacecollab.backend.api/Startup.cs
  5. 2
      Collaborateur_Epa_Back/espacecollab.backend.api/appsettings.json
  6. 5
      Collaborateur_Epa_Back/espacecollab.backend.api/espacecollab.backend.api.csproj
  7. 42
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs
  8. 9
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/EnumGenreApi.cs
  9. 10
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/EnumStatutApi.cs
  10. 15
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/CollaborateurApiDtoMapper.cs
  11. 23
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/EnumGenreMapper.cs
  12. 24
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/EnumStatutMapper.cs
  13. 6
      Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/espacecollab.backend.appservices.dtos.csproj
  14. 21
      Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs
  15. 42
      Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs
  16. 5
      Collaborateur_Epa_Back/espacecollab.backend.appservices/espacecollab.backend.appservices.csproj
  17. 6
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurSqlDto.cs
  18. 2
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/EnumGenreSql.cs
  19. 2
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/EnumIssueSql.cs
  20. 2
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/EnumStatutSql.cs
  21. 4
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/PeriodeEssaiSqlDto.cs
  22. 5
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/MainDbContext.cs
  23. 36
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/GenericRepository.cs
  24. 7
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/IGenericEntity.cs
  25. 4
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IBusinessUnitRepository.cs
  26. 15
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IGenericRepository.cs
  27. 11
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/INotGenericRepository.cs
  28. 12
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IPeriodeEssaiRepository.cs
  29. 26
      Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/db/db_1_0_0.sql

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

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

@ -11,7 +11,6 @@ namespace Api
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}

@ -1,5 +1,8 @@
using espacecollab.backend.infrastructure.sql;
using espacecollab.backend.appservices;
using espacecollab.backend.infrastructure.sql;
using espacecollab.backend.infrastructure.sql.Options;
using espacecollab.backend.infrastructure.sql.SqlRepo;
using espacecollab.backend.infrastructure.sql.SqlRepo.Interface;
namespace Api
{
@ -18,12 +21,17 @@ namespace Api
IConfigurationSection sqlSection = Configuration.GetSection(SqlOption.Key);
services.Configure<SqlOption>(sqlSection);
SqlOption contextOptions = sqlSection.Get<SqlOption>();
services.AddControllers();
services.AddRouting(options => options.LowercaseUrls = true);
services.AddScoped<ICollaborateurRepository, CollaborateurRepository>();
services.AddScoped<IGenericRepository, GenericRepository>();
services.AddScoped<CollaborateursServices>();
services.AddScoped<MainDbContext>();
services.AddEndpointsApiExplorer();

@ -8,6 +8,6 @@
"AllowedHosts": "*",
"Sql": {
"LoadFake": false,
"ConnectionString": "Server=localhost;Database=collaborateur_epa;Uid=root;Pwd=root;"
"ConnectionString": "server=127.0.0.1;uid=root;pwd=root;database=collaborateur_epa"
}
}

@ -11,10 +11,7 @@
</ItemGroup>
<ItemGroup>
<Folder Include="Controllers\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\espacecollab.backend.appservices\espacecollab.backend.appservices.csproj" />
<ProjectReference Include="..\espacecollab.backend.infrastructure.sql\espacecollab.backend.infrastructure.sql.csproj" />
</ItemGroup>

@ -0,0 +1,42 @@
namespace espacecollab.backend.appservices.dtos
{
public class CollaborateurApiDto
{
public Guid Id { get; set; }
public string Name { get; set; }
public string FirstName { get; set; }
public DateTime BirthDate { get; set; }
public EnumGenreApi Gender { get; set; }
public EnumStatutApi 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 Guid ReferrerId { get; set; }
public Guid BusinessUnitId { get; set; }
private CollaborateurApiDto()
{
}
public CollaborateurApiDto(Guid id, string name, string firstName, DateTime birthDate, EnumGenreApi gender, EnumStatutApi status, int childrenNumber, string address, string telephone, string personalMail, string apsideMail, DateTime resignationDate, Guid referrerId, Guid businessUnitId)
{
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;
}
}
}

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

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

@ -0,0 +1,15 @@
using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.appservices.dtos.Mappers
{
public static class CollaborateurApiDtoMapper
{
public static CollaborateurApiDto ToCollaborateurApi(this CollaborateurSqlDto collaborateurSql)
{
return new CollaborateurApiDto(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);
}
}
}

@ -0,0 +1,23 @@
using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.appservices.dtos.Mappers
{
public static class EnumGenreMapper
{
public static EnumGenreApi ToEnumGenreApi(this EnumGenreSql enumGenreSql)
{
switch (enumGenreSql)
{
case EnumGenreSql.MASCULIN:
return EnumGenreApi.MASCULIN;
case EnumGenreSql.FEMININ:
return EnumGenreApi.FEMININ;
case EnumGenreSql.AUTRE:
return EnumGenreApi.AUTRE;
default:
return EnumGenreApi.AUTRE;
}
}
}
}

@ -0,0 +1,24 @@
using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.appservices.dtos.Mappers
{
public static class EnumStatutMapper
{
public static EnumStatutApi ToEnumStatutApi(this EnumStatutSql enumStatutSql)
{
switch (enumStatutSql)
{
case EnumStatutSql.STAGIAIRE:
return EnumStatutApi.STAGIAIRE;
case EnumStatutSql.NONCADRE:
return EnumStatutApi.NONCADRE;
case EnumStatutSql.CADRE:
return EnumStatutApi.CADRE;
case EnumStatutSql.ALTERNANT:
return EnumStatutApi.ALTERNANT;
default: return EnumStatutApi.NONCADRE;
}
}
}
}

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

@ -0,0 +1,21 @@
using espacecollab.backend.appservices.dtos;
using espacecollab.backend.appservices.dtos.Mappers;
using espacecollab.backend.infrastructure.sql.SqlRepo.Interface;
namespace espacecollab.backend.appservices
{
public class CollaborateursServices
{
private ICollaborateurRepository CollaborateurRepository { get; }
public CollaborateursServices(ICollaborateurRepository collaborateurRepository)
{
CollaborateurRepository = collaborateurRepository;
}
public IEnumerable<CollaborateurApiDto> GetCollaborateurs()
{
return CollaborateurRepository.GetAllCollaborateurs().Select(collaborateurSql => collaborateurSql.ToCollaborateurApi());
}
}
}

@ -0,0 +1,42 @@
using espacecollab.backend.infrastructure.sql.SqlRepo;
using espacecollab.backend.infrastructure.sql.SqlRepo.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace espacecollab.backend.appservices
{
public class GenericsServices
{
private IGenericRepository genericRepository { get; }
public GenericsServices(IGenericRepository genericRepository)
{
this.genericRepository = genericRepository;
}
public T? Add<T>(T entity) where T : class
{
return genericRepository.Add<T>(entity);
}
public IEnumerable<T> GetAll<T>() where T : class
{
return genericRepository.GetAll<T>();
}
public T? GetById<T>(Guid id) where T : class, IGenericEntity
{
return genericRepository.GetById<T>(id);
}
public T? Update<T>(T entity) where T : class, IGenericEntity
{
return genericRepository.Update<T>(entity);
}
}
}

@ -6,4 +6,9 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\espacecollab.backend.appservices.dtos\espacecollab.backend.appservices.dtos.csproj" />
<ProjectReference Include="..\espacecollab.backend.infrastructure.sql\espacecollab.backend.infrastructure.sql.csproj" />
</ItemGroup>
</Project>

@ -8,8 +8,8 @@ namespace espacecollab.backend.infrastructure.sql.dtos
public string Name { get; set; }
public string FirstName { get; set; }
public DateTime BirthDate { get; set; }
public EnumGenre Gender { get; set; }
public EnumStatut Status { 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; }
@ -24,7 +24,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos
{
}
public CollaborateurSqlDto(Guid id, string name, string firstName, DateTime birthDate, EnumGenre gender, EnumStatut status, int childrenNumber, string address, string telephone, string personalMail, string apsideMail, DateTime resignationDate, Guid referrerId, Guid businessUnitId)
public CollaborateurSqlDto(Guid id, string name, string firstName, DateTime birthDate, EnumGenreSql gender, EnumStatutSql status, int childrenNumber, string address, string telephone, string personalMail, string apsideMail, DateTime resignationDate, Guid referrerId, Guid businessUnitId)
{
Id = id;
Name = name;

@ -1,6 +1,6 @@
namespace espacecollab.backend.infrastructure.sql.dtos
{
public enum EnumGenre
public enum EnumGenreSql
{
MASCULIN,
FEMININ,

@ -1,6 +1,6 @@
namespace espacecollab.backend.infrastructure.sql.dtos
{
public enum EnumIssue
public enum EnumIssueSql
{
VALIDEE,
PROLONGEE_COLLAB,

@ -1,6 +1,6 @@
namespace espacecollab.backend.infrastructure.sql.dtos
{
public enum EnumStatut
public enum EnumStatutSql
{
CADRE,
NONCADRE,

@ -9,7 +9,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos
public DateTime PlannedEndingDate { get; set; }
public DateTime RealEndingDate { get; set; }
public string Comment { get; set; }
public EnumIssue Issue { get; set; }
public EnumIssueSql Issue { get; set; }
public Guid CollaborateurId { get; set; }
[ExcludeFromCodeCoverage]
@ -17,7 +17,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos
{
}
public PeriodeEssaiSqlDto(Guid id, DateTime startingDate, DateTime plannedEndingDate, DateTime realEndingDate, string comment, EnumIssue issue, Guid collaborateurId)
public PeriodeEssaiSqlDto(Guid id, DateTime startingDate, DateTime plannedEndingDate, DateTime realEndingDate, string comment, EnumIssueSql issue, Guid collaborateurId)
{
Id = id;
StartingDate = startingDate;

@ -16,7 +16,10 @@ namespace espacecollab.backend.infrastructure.sql
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(SqlSettings.Value.ConnectionString);
optionsBuilder.UseSqlServer(SqlSettings.Value.ConnectionString, builder =>
{
builder.EnableRetryOnFailure(5, TimeSpan.FromSeconds(10), null);
});
}

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

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

@ -6,7 +6,7 @@ namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface
{
BusinessUnitSqlDto? AddBusinessUnit(BusinessUnitSqlDto newBusinessUnit);
IList<BusinessUnitSqlDto>? GetAllBusinessUnits();
BusinessUnitSqlDto? GetBusinessUnitById(BusinessUnitSqlDto BusinessUnit);
BusinessUnitSqlDto UpdateBusinessUnit(BusinessUnitSqlDto BusinessUnit);
BusinessUnitSqlDto? GetBusinessUnitById(BusinessUnitSqlDto businessUnit);
BusinessUnitSqlDto UpdateBusinessUnit(BusinessUnitSqlDto businessUnit);
}
}

@ -0,0 +1,15 @@
namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface
{
public interface IGenericRepository
{
T? Add<T>(T entity) where T : class;
IList<T> GetAll<T>() where T : class;
T? GetById<T>(Guid id) where T : class, IGenericEntity;
T? Update<T>(T entity) where T : class, IGenericEntity;
}
}

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

@ -0,0 +1,12 @@
using espacecollab.backend.infrastructure.sql.dtos;
namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface
{
public interface IPeriodeEssaiRepository
{
PeriodeEssaiSqlDto? AddPeriodeEssai(PeriodeEssaiSqlDto newPeriodeEssai);
IList<PeriodeEssaiSqlDto>? GetAllPeriodeEssais();
PeriodeEssaiSqlDto? GetPeriodeEssaiById(PeriodeEssaiSqlDto periodeEssai);
PeriodeEssaiSqlDto UpdatePeriodeEssai(PeriodeEssaiSqlDto periodeEssai);
}
}

@ -46,19 +46,6 @@ CREATE TABLE IF NOT EXISTS Technologie(
PRIMARY KEY (Id)
);
DROP TABLE IF EXISTS PeriodeEssai;
CREATE TABLE IF NOT EXISTS PeriodeEssai(
Id int NOT NULL AUTO_INCREMENT,
StartingDate date NOT NULL,
PlannedEndingDate date NOT NULL,
RealEndingDate date NOT NULL,
Comment varchar(100) NOT NULL,
Issue ENUM('VALIDEE','PROLONGEE_COLLAB','PROLONGEE_APSIDE','ARRETEE_COLLAB','ARRETEE_APSIDE') NOT NULL,
PRIMARY KEY (Id)
);
DROP TABLE IF EXISTS Fonction;
CREATE TABLE IF NOT EXISTS Fonction(
Id int NOT NULL UNIQUE,
@ -85,6 +72,19 @@ CREATE TABLE IF NOT EXISTS Collaborateur(
PRIMARY KEY (Id)
);
DROP TABLE IF EXISTS PeriodeEssai;
CREATE TABLE IF NOT EXISTS PeriodeEssai(
Id int NOT NULL AUTO_INCREMENT,
StartingDate date NOT NULL,
PlannedEndingDate date NOT NULL,
RealEndingDate date NOT NULL,
Comment varchar(100) NOT NULL,
Issue ENUM('VALIDEE','PROLONGEE_COLLAB','PROLONGEE_APSIDE','ARRETEE_COLLAB','ARRETEE_APSIDE') NOT NULL,
CollaborateurId int NOT NULL,
CONSTRAINT FK_COLLABORATEUR_PERIODEESSAI FOREIGN KEY (CollaborateurId) REFERENCES Collaborateur(Id),
PRIMARY KEY (Id)
);
DROP TABLE IF EXISTS Referencement;
CREATE TABLE IF NOT EXISTS Referencement(
Id int NOT NULL AUTO_INCREMENT,

Loading…
Cancel
Save