From fcdff5d56665feeda47ae6773066aecbeddc8ef9 Mon Sep 17 00:00:00 2001 From: Clement FERRERE Date: Mon, 22 Nov 2021 16:06:11 +0100 Subject: [PATCH 01/19] =?UTF-8?q?Cr=C3=A9ation=20du=20repository=20collabo?= =?UTF-8?q?rateur=20selon=20les=20routes=20de=20la=20doc=20swagger.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + .../espacecollab.backend.api/Program.cs | 39 ++++++------- .../espacecollab.backend.api/Startup.cs | 56 +++++++++++++++++++ .../espacecollab.backend.api/appsettings.json | 6 +- .../espacecollab.backend.api.csproj | 4 ++ .../CollaborateurSqlDto.cs | 7 ++- .../EnumGenre.cs | 2 +- .../EnumStatut.cs | 2 +- .../TechnologieSqlDto.cs | 4 +- .../MainDbContext.cs | 24 ++++++++ .../Options/SqlOption.cs | 14 +++++ .../SqlRepo/CollaborateurRepository.cs | 52 +++++++++++++++++ .../Interface/ICollaborateurRepository.cs | 15 +++++ .../db/db_1_0_0.sql | 2 +- ...cecollab.backend.infrastructure.sql.csproj | 16 +++++- 15 files changed, 213 insertions(+), 32 deletions(-) create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.api/Startup.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/MainDbContext.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Options/SqlOption.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/CollaborateurRepository.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/ICollaborateurRepository.cs diff --git a/.gitignore b/.gitignore index ade385a..af8f539 100644 --- a/.gitignore +++ b/.gitignore @@ -387,4 +387,6 @@ FodyWeavers.xsd .idea/ *.sln.iml +appsettings.Development.json +*.Development *.Development.json \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Program.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Program.cs index 48863a6..cd1ba0a 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/Program.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Program.cs @@ -1,25 +1,18 @@ -var builder = WebApplication.CreateBuilder(args); - -// Add services to the container. - -builder.Services.AddControllers(); -// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle -builder.Services.AddEndpointsApiExplorer(); -builder.Services.AddSwaggerGen(); - -var app = builder.Build(); - -// Configure the HTTP request pipeline. -if (app.Environment.IsDevelopment()) +namespace Api { - app.UseSwagger(); - app.UseSwaggerUI(); + public static class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + + webBuilder.UseStartup(); + }); + } } - -app.UseHttpsRedirection(); - -app.UseAuthorization(); - -app.MapControllers(); - -app.Run(); diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Startup.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Startup.cs new file mode 100644 index 0000000..3a242e4 --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Startup.cs @@ -0,0 +1,56 @@ +using espacecollab.backend.infrastructure.sql; +using espacecollab.backend.infrastructure.sql.Options; + +namespace Api +{ + public class Startup + { + public IConfiguration Configuration { get; } + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + // 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(sqlSection); + + SqlOption contextOptions = sqlSection.Get(); + + services.AddControllers(); + services.AddRouting(options => options.LowercaseUrls = true); + + services.AddScoped(); + + services.AddEndpointsApiExplorer(); + services.AddSwaggerGen(); + } + + // 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.UseSwagger(); + app.UseSwaggerUI(); + + app.UseHttpsRedirection(); + + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/appsettings.json b/Collaborateur_Epa_Back/espacecollab.backend.api/appsettings.json index 10f68b8..2c9c17d 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/appsettings.json +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/appsettings.json @@ -5,5 +5,9 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" + "AllowedHosts": "*", + "Sql": { + "LoadFake": false, + "ConnectionString": "Server=localhost;Database=collaborateur_epa;Uid=root;Pwd=root;" + } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/espacecollab.backend.api.csproj b/Collaborateur_Epa_Back/espacecollab.backend.api/espacecollab.backend.api.csproj index 14554a8..19cd919 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/espacecollab.backend.api.csproj +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/espacecollab.backend.api.csproj @@ -14,4 +14,8 @@ + + + + diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurSqlDto.cs index b7917d2..3c84b33 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurSqlDto.cs @@ -1,5 +1,4 @@ -using espacecollab.backend.infrastructure.sql.dtos.Enums; -using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.CodeAnalysis; namespace espacecollab.backend.infrastructure.sql.dtos { @@ -18,13 +17,14 @@ namespace espacecollab.backend.infrastructure.sql.dtos public string ApsideMail { get; set; } public DateTime ResignationDate { get; set; } public Guid ReferrerId { get; set; } + public Guid BusinessUnitId { get; set; } [ExcludeFromCodeCoverage] private CollaborateurSqlDto() { } - 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) + 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) { Id = id; Name = name; @@ -39,6 +39,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos ApsideMail = apsideMail; ResignationDate = resignationDate; ReferrerId = referrerId; + BusinessUnitId = businessUnitId; } } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/EnumGenre.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/EnumGenre.cs index 83c9bef..2170465 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/EnumGenre.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/EnumGenre.cs @@ -1,4 +1,4 @@ -namespace espacecollab.backend.infrastructure.sql.dtos.Enums +namespace espacecollab.backend.infrastructure.sql.dtos { public enum EnumGenre { diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/EnumStatut.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/EnumStatut.cs index 2db3de5..1f1d737 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/EnumStatut.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/EnumStatut.cs @@ -1,4 +1,4 @@ -namespace espacecollab.backend.infrastructure.sql.dtos.Enums +namespace espacecollab.backend.infrastructure.sql.dtos { public enum EnumStatut { diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/TechnologieSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/TechnologieSqlDto.cs index 73f5028..21fa7e5 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/TechnologieSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/TechnologieSqlDto.cs @@ -1,4 +1,6 @@ -namespace espacecollab.backend.infrastructure.sql.dtos +using System.Diagnostics.CodeAnalysis; + +namespace espacecollab.backend.infrastructure.sql.dtos { public class TechnologieSqlDto { diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/MainDbContext.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/MainDbContext.cs new file mode 100644 index 0000000..2688dd6 --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/MainDbContext.cs @@ -0,0 +1,24 @@ +using espacecollab.backend.infrastructure.sql.dtos; +using espacecollab.backend.infrastructure.sql.Options; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Options; +namespace espacecollab.backend.infrastructure.sql +{ + public class MainDbContext : DbContext + { + private IOptions SqlSettings { get; } + + public DbSet? Collaborateur { get; set; } + + public MainDbContext(IOptions sqlSettings) + { + SqlSettings = sqlSettings; + } + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + optionsBuilder.UseSqlServer(SqlSettings.Value.ConnectionString); + } + + + } +} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Options/SqlOption.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Options/SqlOption.cs new file mode 100644 index 0000000..f741343 --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Options/SqlOption.cs @@ -0,0 +1,14 @@ +namespace espacecollab.backend.infrastructure.sql.Options +{ + public class SqlOption + { + public static string Key => "Sql"; + public bool LoadFake { get; set; } + public string ConnectionString { get; set; } + + public SqlOption() + { + ConnectionString = string.Empty; + } + } +} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/CollaborateurRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/CollaborateurRepository.cs new file mode 100644 index 0000000..e0161ec --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/CollaborateurRepository.cs @@ -0,0 +1,52 @@ +using espacecollab.backend.infrastructure.sql.dtos; +using espacecollab.backend.infrastructure.sql.SqlRepo.Interface; + +namespace espacecollab.backend.infrastructure.sql.SqlRepo +{ + public class CollaborateurRepository : ICollaborateurRepository + { + private MainDbContext Context { get; } + + public CollaborateurRepository(MainDbContext context) + { + Context = context; + } + + /* TODO Récupération des collaborateurs par agence directement dans le service Collaborateur */ + + public CollaborateurSqlDto? AddCollaborateur(CollaborateurSqlDto newCollaborateur) + { + CollaborateurSqlDto? collaborateurAlreadyExists = Context.Collaborateur?.FirstOrDefault(c => c.Id == newCollaborateur.Id); + if (collaborateurAlreadyExists != null) + return null; + + Context.Set().Add(newCollaborateur); + Context.SaveChanges(); + + return Context.Set().FirstOrDefault(c => c.Id == newCollaborateur.Id); + } + + public IList? GetAllCollaborateurs() + => Context.Set().ToList(); + + public IList? GetCollaborateursByBusinessUnit(Guid businessUnitId) + => Context.Set().Where(collaborateur => collaborateur.BusinessUnitId == businessUnitId).ToList(); + + public IList? GetCollaborateursByReferrer(Guid referrerId) + => Context.Set().Where(collaborateur => collaborateur.ReferrerId == referrerId).ToList(); + + public CollaborateurSqlDto? GetCollaborateurById(Guid id) + => Context?.Set().SingleOrDefault(collaborateur => collaborateur.Id == id); + + public CollaborateurSqlDto? GetCollaborateurByApsideMail(string apsideMail) + => Context?.Set().SingleOrDefault(collaborateur => collaborateur.ApsideMail == apsideMail); + + public CollaborateurSqlDto? UpdateCollaborateur(CollaborateurSqlDto newCollaborateur) + { + Context.Set().Update(newCollaborateur); + Context.SaveChanges(); + + return Context.Set().FirstOrDefault(c => c.Id == newCollaborateur.Id); + } + } +} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/ICollaborateurRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/ICollaborateurRepository.cs new file mode 100644 index 0000000..7271a87 --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/ICollaborateurRepository.cs @@ -0,0 +1,15 @@ +using espacecollab.backend.infrastructure.sql.dtos; + +namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface +{ + public interface ICollaborateurRepository + { + CollaborateurSqlDto? AddCollaborateur(CollaborateurSqlDto newCollaborateur); + IList? GetAllCollaborateurs(); + CollaborateurSqlDto? GetCollaborateurByApsideMail(string apsideMail); + CollaborateurSqlDto? GetCollaborateurById(Guid id); + IList? GetCollaborateursByBusinessUnit(Guid businessUnitId); + IList? GetCollaborateursByReferrer(Guid referrerId); + CollaborateurSqlDto? UpdateCollaborateur(CollaborateurSqlDto newCollaborateur); + } +} \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/db/db_1_0_0.sql b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/db/db_1_0_0.sql index 344c6bd..5aaeeb4 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/db/db_1_0_0.sql +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/db/db_1_0_0.sql @@ -69,7 +69,7 @@ CREATE TABLE IF NOT EXISTS Fonction( DROP TABLE IF EXISTS Collaborateur; CREATE TABLE IF NOT EXISTS Collaborateur( Id int NOT NULL AUTO_INCREMENT, - Name varchar(100) NOT NULL UNIQUE, + Name varchar(100) NOT NULL, FirstName varchar(100) NOT NULL, BirthDate date NOT NULL, Gender ENUM('MASCULIN','FEMININ','AUTRE') NOT NULL, diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/espacecollab.backend.infrastructure.sql.csproj b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/espacecollab.backend.infrastructure.sql.csproj index 132c02c..d919b65 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/espacecollab.backend.infrastructure.sql.csproj +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/espacecollab.backend.infrastructure.sql.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -6,4 +6,18 @@ enable + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + -- 2.36.3 From 7b7bd77e6e71532e2237e69d3e26c84fe24c3876 Mon Sep 17 00:00:00 2001 From: Clement FERRERE Date: Mon, 22 Nov 2021 16:53:07 +0100 Subject: [PATCH 02/19] =?UTF-8?q?Cr=C3=A9ation=20des=20interfaces=20pour?= =?UTF-8?q?=20autres=20repos.=20Agence=20incompl=C3=A8te,=20P=C3=A9riode?= =?UTF-8?q?=20Essai=20=C3=A0=20voir?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...CollaborateurEffectuePeriodeEssaiSqlDto.cs | 21 ------------------- .../CollaborateurEstFonctionSqlDto.cs | 2 +- .../PeriodeEssaiSqlDto.cs | 4 +++- .../SqlRepo/CollaborateurRepository.cs | 2 +- .../SqlRepo/Interface/IAgenceRepository.cs | 12 +++++++++++ .../Interface/IBusinessUnitRepository.cs | 12 +++++++++++ .../SqlRepo/Interface/IProjetRepository.cs | 13 ++++++++++++ .../Interface/IReferencementRepository.cs | 13 ++++++++++++ 8 files changed, 55 insertions(+), 24 deletions(-) delete mode 100644 Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurEffectuePeriodeEssaiSqlDto.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IAgenceRepository.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IBusinessUnitRepository.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IProjetRepository.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IReferencementRepository.cs diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurEffectuePeriodeEssaiSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurEffectuePeriodeEssaiSqlDto.cs deleted file mode 100644 index bfe853b..0000000 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurEffectuePeriodeEssaiSqlDto.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.Diagnostics.CodeAnalysis; - -namespace espacecollab.backend.infrastructure.sql.dtos.Associations -{ - public class CollaborateurEffectuePeriodeEssaiSqlDto - { - public Guid CollaborateurId { get; set; } - public Guid PeriodeEssaiId { get; set;} - - [ExcludeFromCodeCoverage] - private CollaborateurEffectuePeriodeEssaiSqlDto() - { - } - - public CollaborateurEffectuePeriodeEssaiSqlDto(Guid collaborateurId, Guid periodeEssaiId) - { - CollaborateurId = collaborateurId; - PeriodeEssaiId = periodeEssaiId; - } - } -} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurEstFonctionSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurEstFonctionSqlDto.cs index be2ecde..909ec84 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurEstFonctionSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurEstFonctionSqlDto.cs @@ -5,7 +5,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos.Associations public class CollaborateurEstFonctionSqlDto { public Guid CollaborateurId { get; set; } - public Guid FonctionId { get; set;} + public Guid FonctionId { get; set; } [ExcludeFromCodeCoverage] private CollaborateurEstFonctionSqlDto() diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/PeriodeEssaiSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/PeriodeEssaiSqlDto.cs index 118637a..ead65f7 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/PeriodeEssaiSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/PeriodeEssaiSqlDto.cs @@ -10,13 +10,14 @@ namespace espacecollab.backend.infrastructure.sql.dtos public DateTime RealEndingDate { get; set; } public string Comment { get; set; } public EnumIssue Issue { get; set; } + public Guid CollaborateurId { get; set; } [ExcludeFromCodeCoverage] private PeriodeEssaiSqlDto() { } - public PeriodeEssaiSqlDto(Guid id, DateTime startingDate, DateTime plannedEndingDate, DateTime realEndingDate, string comment, EnumIssue issue) + public PeriodeEssaiSqlDto(Guid id, DateTime startingDate, DateTime plannedEndingDate, DateTime realEndingDate, string comment, EnumIssue issue, Guid collaborateurId) { Id = id; StartingDate = startingDate; @@ -24,6 +25,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos RealEndingDate = realEndingDate; Comment = comment; Issue = issue; + CollaborateurId = collaborateurId; } } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/CollaborateurRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/CollaborateurRepository.cs index e0161ec..67ffd1b 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/CollaborateurRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/CollaborateurRepository.cs @@ -19,7 +19,7 @@ namespace espacecollab.backend.infrastructure.sql.SqlRepo CollaborateurSqlDto? collaborateurAlreadyExists = Context.Collaborateur?.FirstOrDefault(c => c.Id == newCollaborateur.Id); if (collaborateurAlreadyExists != null) return null; - + Context.Set().Add(newCollaborateur); Context.SaveChanges(); diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IAgenceRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IAgenceRepository.cs new file mode 100644 index 0000000..f0470bc --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IAgenceRepository.cs @@ -0,0 +1,12 @@ +using espacecollab.backend.infrastructure.sql.dtos; + +namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface +{ + public interface IAgenceRepository + { + AgenceSqlDto? AddAgence(AgenceSqlDto newAgence); + IList? GetAllAgences(); + AgenceSqlDto? GetAgenceById(AgenceSqlDto agence); + AgenceSqlDto UpdateAgence(AgenceSqlDto agence); + } +} \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IBusinessUnitRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IBusinessUnitRepository.cs new file mode 100644 index 0000000..3ccc5ea --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IBusinessUnitRepository.cs @@ -0,0 +1,12 @@ +using espacecollab.backend.infrastructure.sql.dtos; + +namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface +{ + public interface IBusinessUnitRepository + { + BusinessUnitSqlDto? AddBusinessUnit(BusinessUnitSqlDto newBusinessUnit); + IList? GetAllBusinessUnits(); + BusinessUnitSqlDto? GetBusinessUnitById(BusinessUnitSqlDto BusinessUnit); + BusinessUnitSqlDto UpdateBusinessUnit(BusinessUnitSqlDto BusinessUnit); + } +} \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IProjetRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IProjetRepository.cs new file mode 100644 index 0000000..b2fa7a3 --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IProjetRepository.cs @@ -0,0 +1,13 @@ +using espacecollab.backend.infrastructure.sql.dtos; + +namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface +{ + public interface IProjetRepository + { + ProjetSqlDto? AddProjet(ProjetSqlDto newProjet); + IList? GetAllProjets(); + IList? GetProjetsByClient(string client); + ProjetSqlDto? GetProjetById(ProjetSqlDto projet); + ProjetSqlDto UpdateProjet(ProjetSqlDto projet); + } +} \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IReferencementRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IReferencementRepository.cs new file mode 100644 index 0000000..43810f3 --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IReferencementRepository.cs @@ -0,0 +1,13 @@ +using espacecollab.backend.infrastructure.sql.dtos; + +namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface +{ + public interface IReferencementRepository + { + IList? GetReferrersByCollaborateurId(Guid collaborateurId); + IList? GetReferrersByCollaborateurApsideMail(string apsideMail); + + //TODO Voir les attentes concernant "le référent ayant le plus suivi depuis une date" + + } +} \ No newline at end of file -- 2.36.3 From faf2cccee7794ee590fad30d42a716521bfeb1e3 Mon Sep 17 00:00:00 2001 From: Clement FERRERE Date: Wed, 24 Nov 2021 11:59:03 +0100 Subject: [PATCH 03/19] =?UTF-8?q?Ajout=20de=20controller,=20service=20et?= =?UTF-8?q?=20repository=20+=20g=C3=A9n=C3=A9ricit=C3=A9=20+=20fix=20de=20?= =?UTF-8?q?program=20et=20startup=20et=20settings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/CollaborateursController.cs | 25 +++++++++++ .../Controllers/GenericsController.cs | 43 +++++++++++++++++++ .../espacecollab.backend.api/Program.cs | 1 - .../espacecollab.backend.api/Startup.cs | 12 +++++- .../espacecollab.backend.api/appsettings.json | 2 +- .../espacecollab.backend.api.csproj | 5 +-- .../CollaborateurApiDto.cs | 42 ++++++++++++++++++ .../EnumGenreApi.cs | 9 ++++ .../EnumStatutApi.cs | 10 +++++ .../Mappers/CollaborateurApiDtoMapper.cs | 15 +++++++ .../Mappers/EnumGenreMapper.cs | 23 ++++++++++ .../Mappers/EnumStatutMapper.cs | 24 +++++++++++ ...pacecollab.backend.appservices.dtos.csproj | 6 ++- .../CollaborateursServices.cs | 21 +++++++++ .../GenericsServices.cs | 42 ++++++++++++++++++ .../espacecollab.backend.appservices.csproj | 5 +++ .../CollaborateurSqlDto.cs | 6 +-- .../{EnumGenre.cs => EnumGenreSql.cs} | 2 +- .../{EnumIssue.cs => EnumIssueSql.cs} | 2 +- .../{EnumStatut.cs => EnumStatutSql.cs} | 2 +- .../PeriodeEssaiSqlDto.cs | 4 +- .../MainDbContext.cs | 5 ++- .../SqlRepo/GenericRepository.cs | 36 ++++++++++++++++ .../SqlRepo/IGenericEntity.cs | 7 +++ .../Interface/IBusinessUnitRepository.cs | 4 +- .../SqlRepo/Interface/IGenericRepository.cs | 15 +++++++ .../Interface/INotGenericRepository.cs | 11 +++++ .../Interface/IPeriodeEssaiRepository.cs | 12 ++++++ .../db/db_1_0_0.sql | 26 +++++------ 29 files changed, 384 insertions(+), 33 deletions(-) create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/GenericsController.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/EnumGenreApi.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/EnumStatutApi.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/CollaborateurApiDtoMapper.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/EnumGenreMapper.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/EnumStatutMapper.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs rename Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/{EnumGenre.cs => EnumGenreSql.cs} (80%) rename Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/{EnumIssue.cs => EnumIssueSql.cs} (86%) rename Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/{EnumStatut.cs => EnumStatutSql.cs} (82%) create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/GenericRepository.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/IGenericEntity.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IGenericRepository.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/INotGenericRepository.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IPeriodeEssaiRepository.cs diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs new file mode 100644 index 0000000..426c042 --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs @@ -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 GetCollaborateurs() + { + return CollaborateursServices.GetCollaborateurs(); + } + } +} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/GenericsController.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/GenericsController.cs new file mode 100644 index 0000000..2502c62 --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/GenericsController.cs @@ -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 GetAll() where T : class + { + return GenericsServices.GetAll(); + } + + [HttpGet] + public T? GetById(Guid id) where T : class, IGenericEntity + { + return GenericsServices.GetById(id); + } + + [HttpPost] + public T? Update(T entity) where T : class, IGenericEntity + { + return GenericsServices.Update(entity); + } + + [HttpPost] + public T? Add(T entity) where T : class + { + return GenericsServices.Add(entity); + } + } +} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Program.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Program.cs index cd1ba0a..5520279 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/Program.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Program.cs @@ -11,7 +11,6 @@ namespace Api Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { - webBuilder.UseStartup(); }); } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Startup.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Startup.cs index 3a242e4..91d17f2 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/Startup.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Startup.cs @@ -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(sqlSection); - SqlOption contextOptions = sqlSection.Get(); services.AddControllers(); services.AddRouting(options => options.LowercaseUrls = true); + + services.AddScoped(); + services.AddScoped(); + + services.AddScoped(); + services.AddScoped(); services.AddEndpointsApiExplorer(); diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/appsettings.json b/Collaborateur_Epa_Back/espacecollab.backend.api/appsettings.json index 2c9c17d..4a29edc 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/appsettings.json +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/appsettings.json @@ -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" } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/espacecollab.backend.api.csproj b/Collaborateur_Epa_Back/espacecollab.backend.api/espacecollab.backend.api.csproj index 19cd919..348965b 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/espacecollab.backend.api.csproj +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/espacecollab.backend.api.csproj @@ -11,10 +11,7 @@ - - - - + diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs new file mode 100644 index 0000000..6bbbb9d --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs @@ -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; + } + } +} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/EnumGenreApi.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/EnumGenreApi.cs new file mode 100644 index 0000000..9414526 --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/EnumGenreApi.cs @@ -0,0 +1,9 @@ +namespace espacecollab.backend.appservices.dtos +{ + public enum EnumGenreApi + { + MASCULIN, + FEMININ, + AUTRE + } +} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/EnumStatutApi.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/EnumStatutApi.cs new file mode 100644 index 0000000..35c7d70 --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/EnumStatutApi.cs @@ -0,0 +1,10 @@ +namespace espacecollab.backend.appservices.dtos +{ + public enum EnumStatutApi + { + CADRE, + NONCADRE, + ALTERNANT, + STAGIAIRE + } +} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/CollaborateurApiDtoMapper.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/CollaborateurApiDtoMapper.cs new file mode 100644 index 0000000..715bc1d --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/CollaborateurApiDtoMapper.cs @@ -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); + } + } +} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/EnumGenreMapper.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/EnumGenreMapper.cs new file mode 100644 index 0000000..9fb595c --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/EnumGenreMapper.cs @@ -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; + } + + } + } +} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/EnumStatutMapper.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/EnumStatutMapper.cs new file mode 100644 index 0000000..c940f38 --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/EnumStatutMapper.cs @@ -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; + } + + } + } +} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/espacecollab.backend.appservices.dtos.csproj b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/espacecollab.backend.appservices.dtos.csproj index 132c02c..26c891b 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/espacecollab.backend.appservices.dtos.csproj +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/espacecollab.backend.appservices.dtos.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -6,4 +6,8 @@ enable + + + + diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs new file mode 100644 index 0000000..24d92c9 --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs @@ -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 GetCollaborateurs() + { + return CollaborateurRepository.GetAllCollaborateurs().Select(collaborateurSql => collaborateurSql.ToCollaborateurApi()); + } + } +} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs new file mode 100644 index 0000000..c17df44 --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs @@ -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 entity) where T : class + { + return genericRepository.Add(entity); + } + + public IEnumerable GetAll() where T : class + { + return genericRepository.GetAll(); + } + + public T? GetById(Guid id) where T : class, IGenericEntity + { + return genericRepository.GetById(id); + } + + public T? Update(T entity) where T : class, IGenericEntity + { + return genericRepository.Update(entity); + } + + + } +} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices/espacecollab.backend.appservices.csproj b/Collaborateur_Epa_Back/espacecollab.backend.appservices/espacecollab.backend.appservices.csproj index 132c02c..69235a9 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices/espacecollab.backend.appservices.csproj +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices/espacecollab.backend.appservices.csproj @@ -6,4 +6,9 @@ enable + + + + + diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurSqlDto.cs index 3c84b33..89d774d 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurSqlDto.cs @@ -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; diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/EnumGenre.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/EnumGenreSql.cs similarity index 80% rename from Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/EnumGenre.cs rename to Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/EnumGenreSql.cs index 2170465..0fc889b 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/EnumGenre.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/EnumGenreSql.cs @@ -1,6 +1,6 @@ namespace espacecollab.backend.infrastructure.sql.dtos { - public enum EnumGenre + public enum EnumGenreSql { MASCULIN, FEMININ, diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/EnumIssue.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/EnumIssueSql.cs similarity index 86% rename from Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/EnumIssue.cs rename to Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/EnumIssueSql.cs index faf7bd1..2945779 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/EnumIssue.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/EnumIssueSql.cs @@ -1,6 +1,6 @@ namespace espacecollab.backend.infrastructure.sql.dtos { - public enum EnumIssue + public enum EnumIssueSql { VALIDEE, PROLONGEE_COLLAB, diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/EnumStatut.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/EnumStatutSql.cs similarity index 82% rename from Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/EnumStatut.cs rename to Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/EnumStatutSql.cs index 1f1d737..9e57875 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/EnumStatut.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/EnumStatutSql.cs @@ -1,6 +1,6 @@ namespace espacecollab.backend.infrastructure.sql.dtos { - public enum EnumStatut + public enum EnumStatutSql { CADRE, NONCADRE, diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/PeriodeEssaiSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/PeriodeEssaiSqlDto.cs index ead65f7..5d9a9e5 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/PeriodeEssaiSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/PeriodeEssaiSqlDto.cs @@ -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; diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/MainDbContext.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/MainDbContext.cs index 2688dd6..25204d2 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/MainDbContext.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/MainDbContext.cs @@ -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); + }); } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/GenericRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/GenericRepository.cs new file mode 100644 index 0000000..57d7d78 --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/GenericRepository.cs @@ -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 entity) where T : class + { + return Context.Set().Add(entity) as T; + } + + public IList GetAll() where T : class + { + return Context.Set().ToList(); + } + + public T? GetById(Guid id) where T : class,IGenericEntity + { + return Context.Set().FirstOrDefault(entity => entity.Id == id); + } + + public T? Update(T entity) where T : class, IGenericEntity + { + Context.Set().Update(entity); + Context.SaveChanges(); + return Context.Set().FirstOrDefault(e => e.Id == entity.Id); + } + } +} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/IGenericEntity.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/IGenericEntity.cs new file mode 100644 index 0000000..3c43b76 --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/IGenericEntity.cs @@ -0,0 +1,7 @@ +namespace espacecollab.backend.infrastructure.sql.SqlRepo +{ + public interface IGenericEntity + { + public Guid Id { get; set; } + } +} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IBusinessUnitRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IBusinessUnitRepository.cs index 3ccc5ea..db3600b 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IBusinessUnitRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IBusinessUnitRepository.cs @@ -6,7 +6,7 @@ namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface { BusinessUnitSqlDto? AddBusinessUnit(BusinessUnitSqlDto newBusinessUnit); IList? GetAllBusinessUnits(); - BusinessUnitSqlDto? GetBusinessUnitById(BusinessUnitSqlDto BusinessUnit); - BusinessUnitSqlDto UpdateBusinessUnit(BusinessUnitSqlDto BusinessUnit); + BusinessUnitSqlDto? GetBusinessUnitById(BusinessUnitSqlDto businessUnit); + BusinessUnitSqlDto UpdateBusinessUnit(BusinessUnitSqlDto businessUnit); } } \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IGenericRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IGenericRepository.cs new file mode 100644 index 0000000..e9a8feb --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IGenericRepository.cs @@ -0,0 +1,15 @@ +namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface +{ + public interface IGenericRepository + { + T? Add(T entity) where T : class; + IList GetAll() where T : class; + T? GetById(Guid id) where T : class, IGenericEntity; + T? Update(T entity) where T : class, IGenericEntity; + + + + + + } +} \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/INotGenericRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/INotGenericRepository.cs new file mode 100644 index 0000000..c816bd1 --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/INotGenericRepository.cs @@ -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? GetCollaborateursByBusinessUnit(Guid businessUnitId); + IList? GetCollaborateursByReferrer(Guid referrerId); + } +} \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IPeriodeEssaiRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IPeriodeEssaiRepository.cs new file mode 100644 index 0000000..4b63c0a --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IPeriodeEssaiRepository.cs @@ -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? GetAllPeriodeEssais(); + PeriodeEssaiSqlDto? GetPeriodeEssaiById(PeriodeEssaiSqlDto periodeEssai); + PeriodeEssaiSqlDto UpdatePeriodeEssai(PeriodeEssaiSqlDto periodeEssai); + } +} \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/db/db_1_0_0.sql b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/db/db_1_0_0.sql index 5aaeeb4..aa2f461 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/db/db_1_0_0.sql +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/db/db_1_0_0.sql @@ -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, -- 2.36.3 From 15d9b039faba555cedafc50a19c5405195d45da4 Mon Sep 17 00:00:00 2001 From: Clement FERRERE Date: Tue, 30 Nov 2021 17:22:36 +0100 Subject: [PATCH 04/19] GetAll fonctionnel avec Fake Datas --- .../CollaborateursControllerTestGeneric.cs | 26 ++++++ .../Controllers/GenericsController.cs | 43 ---------- .../espacecollab.backend.api/Startup.cs | 19 ++++- .../espacecollab.backend.api/appsettings.json | 2 +- .../CollaborateurApiDto.cs | 23 +++++- .../GenericApiDtoBase.cs | 17 ++++ .../Mappers/CollaborateurApiDtoMapper.cs | 12 ++- .../Mappers/EnumGenreMapper.cs | 26 +++--- .../Mappers/EnumStatutMapper.cs | 29 ++++--- .../CollaborateursServices.cs | 73 ++++++++++++++++- .../GenericsServices.cs | 81 ++++++++++--------- .../IGenericsServices.cs | 15 ++++ .../AgenceSqlDto.cs | 3 +- .../BusinessUnitSqlDto.cs | 4 +- ...llaborateurAppartientBusinessUnitSqlDto.cs | 3 + .../CollaborateurCollaboreProjetSqlDto.cs | 1 + .../CollaborateurEstFonctionSqlDto.cs | 4 +- .../CollaborateurSqlDto.cs | 3 +- .../FonctionSqlDto.cs | 4 +- .../IGenericSqlDto.cs | 8 ++ .../PeriodeEssaiSqlDto.cs | 4 +- .../ProjetSqlDto.cs | 3 +- .../ProjetUtiliseTechnologieSqlDto.cs | 1 + .../ReferencementSqlDto.cs | 4 +- .../SiteDeveloppeProjetSqlDto.cs | 3 + .../SiteSqlDto.cs | 5 +- .../TechnologieSqlDto.cs | 3 +- .../FakeRepo/FakeCollaborateurRepository.cs | 81 +++++++++++++++++++ .../SqlRepo/CollaborateurRepository.cs | 34 +------- .../SqlRepo/GenericRepository.cs | 24 ++++-- .../SqlRepo/IGenericEntity.cs | 7 -- .../SqlRepo/Interface/IAgenceRepository.cs | 1 + .../Interface/IBusinessUnitRepository.cs | 1 + .../Interface/ICollaborateurRepository.cs | 6 +- .../SqlRepo/Interface/IGenericRepository.cs | 15 ++-- .../Interface/INotGenericRepository.cs | 11 --- .../Interface/IPeriodeEssaiRepository.cs | 1 + .../SqlRepo/Interface/IProjetRepository.cs | 4 - 38 files changed, 411 insertions(+), 193 deletions(-) create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursControllerTestGeneric.cs delete mode 100644 Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/GenericsController.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/GenericApiDtoBase.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.appservices/IGenericsServices.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/IGenericSqlDto.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/FakeRepo/FakeCollaborateurRepository.cs delete mode 100644 Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/IGenericEntity.cs delete mode 100644 Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/INotGenericRepository.cs diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursControllerTestGeneric.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursControllerTestGeneric.cs new file mode 100644 index 0000000..b926d16 --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursControllerTestGeneric.cs @@ -0,0 +1,26 @@ +using espacecollab.backend.appservices; +using espacecollab.backend.appservices.dtos; +using Microsoft.AspNetCore.Mvc; + +namespace espacecollab.backend.api.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class CollaborateursControllerTestGeneric : ControllerBase + { + private CollaborateursServices CollaborateursServices { get; } + + public CollaborateursControllerTestGeneric(CollaborateursServices collaborateursServices) + { + CollaborateursServices = collaborateursServices; + } + + // GET: api/collaborateurs + //[HttpGet] + //public ActionResult> GetCollaborateurs() + //{ + // return CollaborateursServices.GetAll(); + + //} + } +} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/GenericsController.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/GenericsController.cs deleted file mode 100644 index 2502c62..0000000 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/GenericsController.cs +++ /dev/null @@ -1,43 +0,0 @@ -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 GetAll() where T : class - { - return GenericsServices.GetAll(); - } - - [HttpGet] - public T? GetById(Guid id) where T : class, IGenericEntity - { - return GenericsServices.GetById(id); - } - - [HttpPost] - public T? Update(T entity) where T : class, IGenericEntity - { - return GenericsServices.Update(entity); - } - - [HttpPost] - public T? Add(T entity) where T : class - { - return GenericsServices.Add(entity); - } - } -} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Startup.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Startup.cs index 91d17f2..cc606b5 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/Startup.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Startup.cs @@ -1,5 +1,7 @@ using espacecollab.backend.appservices; using espacecollab.backend.infrastructure.sql; +using espacecollab.backend.infrastructure.sql.dtos; +using espacecollab.backend.infrastructure.sql.FakeRepo; using espacecollab.backend.infrastructure.sql.Options; using espacecollab.backend.infrastructure.sql.SqlRepo; using espacecollab.backend.infrastructure.sql.SqlRepo.Interface; @@ -26,11 +28,20 @@ namespace Api services.AddControllers(); services.AddRouting(options => options.LowercaseUrls = true); - - services.AddScoped(); - services.AddScoped(); - + if (contextOptions.LoadFake) + { + + + } + else + { + //services.AddScoped(); + } + //services.AddScoped, GenericRepository>(); + //services.AddScoped, FakeCollaborateurRepository>(); + services.AddScoped(); services.AddScoped(); + services.AddScoped(); diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/appsettings.json b/Collaborateur_Epa_Back/espacecollab.backend.api/appsettings.json index 4a29edc..eb754e8 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/appsettings.json +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/appsettings.json @@ -7,7 +7,7 @@ }, "AllowedHosts": "*", "Sql": { - "LoadFake": false, + "LoadFake": true, "ConnectionString": "server=127.0.0.1;uid=root;pwd=root;database=collaborateur_epa" } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs index 6bbbb9d..eae4f66 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs @@ -1,4 +1,7 @@ -namespace espacecollab.backend.appservices.dtos +using espacecollab.backend.appservices.dtos.Mappers; +using espacecollab.backend.infrastructure.sql.dtos; + +namespace espacecollab.backend.appservices.dtos { public class CollaborateurApiDto { @@ -17,8 +20,9 @@ public Guid ReferrerId { get; set; } public Guid BusinessUnitId { get; set; } - private CollaborateurApiDto() + public 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) @@ -38,5 +42,20 @@ ReferrerId = referrerId; BusinessUnitId = businessUnitId; } + + public CollaborateurApiDto(CollaborateurSqlDto entity) + { + } + + //public override CollaborateurSqlDto ToEntity() + //{ + // return new CollaborateurSqlDto(Id, Name, FirstName, BirthDate, Gender.ToEnumGenreSql(), Status.ToEnumStatutSql(), ChildrenNumber, + // Address, Telephone, PersonalMail, ApsideMail, ResignationDate, ReferrerId, BusinessUnitId); + //} + + //public override CollaborateurApiDto FromEntity(CollaborateurSqlDto entity) + //{ + // return this; + //} } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/GenericApiDtoBase.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/GenericApiDtoBase.cs new file mode 100644 index 0000000..6f54298 --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/GenericApiDtoBase.cs @@ -0,0 +1,17 @@ +using espacecollab.backend.infrastructure.sql.dtos; + +namespace espacecollab.backend.appservices.dtos +{ + public abstract class GenericApiDtoBase where T : class, IGenericSqlDto + where To : GenericApiDtoBase + { + public abstract T ToEntity(); + + public abstract To FromEntity(T entity); + + public GenericApiDtoBase(T entity) + { + FromEntity(entity); + } + } +} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/CollaborateurApiDtoMapper.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/CollaborateurApiDtoMapper.cs index 715bc1d..7a72dab 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/CollaborateurApiDtoMapper.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/CollaborateurApiDtoMapper.cs @@ -2,14 +2,22 @@ namespace espacecollab.backend.appservices.dtos.Mappers { - public static class CollaborateurApiDtoMapper + public static class CollaborateurMapper { - public static CollaborateurApiDto ToCollaborateurApi(this CollaborateurSqlDto collaborateurSql) + public static CollaborateurApiDto ToApi(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); } + + public static CollaborateurSqlDto ToSql(this CollaborateurApiDto collaborateurApi) + { + return new CollaborateurSqlDto(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); + } } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/EnumGenreMapper.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/EnumGenreMapper.cs index 9fb595c..b7eb349 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/EnumGenreMapper.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/EnumGenreMapper.cs @@ -6,18 +6,24 @@ namespace espacecollab.backend.appservices.dtos.Mappers { public static EnumGenreApi ToEnumGenreApi(this EnumGenreSql enumGenreSql) { - switch (enumGenreSql) + return enumGenreSql switch { - case EnumGenreSql.MASCULIN: - return EnumGenreApi.MASCULIN; - case EnumGenreSql.FEMININ: - return EnumGenreApi.FEMININ; - case EnumGenreSql.AUTRE: - return EnumGenreApi.AUTRE; - default: - return EnumGenreApi.AUTRE; - } + EnumGenreSql.MASCULIN => EnumGenreApi.MASCULIN, + EnumGenreSql.FEMININ => EnumGenreApi.FEMININ, + EnumGenreSql.AUTRE => EnumGenreApi.AUTRE, + _ => EnumGenreApi.AUTRE, + }; + } + public static EnumGenreSql ToEnumGenreSql(this EnumGenreApi enumGenreApi) + { + return enumGenreApi switch + { + EnumGenreApi.MASCULIN => EnumGenreSql.MASCULIN, + EnumGenreApi.FEMININ => EnumGenreSql.FEMININ, + EnumGenreApi.AUTRE => EnumGenreSql.AUTRE, + _ => EnumGenreSql.AUTRE, + }; } } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/EnumStatutMapper.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/EnumStatutMapper.cs index c940f38..cde5356 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/EnumStatutMapper.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/EnumStatutMapper.cs @@ -6,19 +6,26 @@ namespace espacecollab.backend.appservices.dtos.Mappers { public static EnumStatutApi ToEnumStatutApi(this EnumStatutSql enumStatutSql) { - switch (enumStatutSql) + return enumStatutSql switch { - 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; - } + 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) + { + return enumStatutApi switch + { + EnumStatutApi.STAGIAIRE => EnumStatutSql.STAGIAIRE, + EnumStatutApi.NONCADRE => EnumStatutSql.NONCADRE, + EnumStatutApi.CADRE => EnumStatutSql.CADRE, + EnumStatutApi.ALTERNANT => EnumStatutSql.ALTERNANT, + _ => EnumStatutSql.NONCADRE, + }; } } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs index 24d92c9..df4d4b3 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs @@ -1,5 +1,8 @@ using espacecollab.backend.appservices.dtos; using espacecollab.backend.appservices.dtos.Mappers; +using espacecollab.backend.infrastructure.sql.dtos; +using espacecollab.backend.infrastructure.sql.FakeRepo; +using espacecollab.backend.infrastructure.sql.SqlRepo; using espacecollab.backend.infrastructure.sql.SqlRepo.Interface; namespace espacecollab.backend.appservices @@ -8,14 +11,78 @@ namespace espacecollab.backend.appservices { private ICollaborateurRepository CollaborateurRepository { get; } - public CollaborateursServices(ICollaborateurRepository collaborateurRepository) + public CollaborateursServices(ICollaborateurRepository collaborateur) { - CollaborateurRepository = collaborateurRepository; + CollaborateurRepository = collaborateur; } public IEnumerable GetCollaborateurs() { - return CollaborateurRepository.GetAllCollaborateurs().Select(collaborateurSql => collaborateurSql.ToCollaborateurApi()); + return CollaborateurRepository.GetAll().Select(collaborateurSql => collaborateurSql.ToApi()); } + + public CollaborateurApiDto? GetCollaborateurById(Guid id) + { + return CollaborateurRepository.GetById(id)?.ToApi(); + } + + public CollaborateurApiDto? AddCollaborateur(CollaborateurApiDto collaborateurApi) + { + CollaborateurSqlDto collaborateurSql = collaborateurApi.ToSql(); + if (collaborateurSql == null) + return null; + CollaborateurRepository.Add(collaborateurSql); + return collaborateurApi; + } + + public CollaborateurApiDto? DeleteCollaborateur(CollaborateurApiDto collaborateurApi) + { + CollaborateurSqlDto collaborateurSql = collaborateurApi.ToSql(); + if (collaborateurSql == null) + return null; + CollaborateurRepository.Delete(collaborateurSql); + return collaborateurApi; + } + + //public new CollaborateurSqlDto? Delete(CollaborateurSqlDto entity) + //{ + // Collaborateurs.Remove(entity); + // return entity; + //} + + //public new IEnumerable GetAll() + //{ + // return Collaborateurs; + //} + + //public new CollaborateurSqlDto? Update(CollaborateurSqlDto collaborateur) + //{ + // CollaborateurSqlDto? oldCollab = Collaborateurs.FirstOrDefault(entity => entity.Id == collaborateur.Id); + // if (oldCollab == null) + // { + // Collaborateurs.Add(collaborateur); + // return collaborateur; + // } + // Collaborateurs.Remove(oldCollab); + // Collaborateurs.Add(collaborateur); + // return collaborateur; + //} + + ////méthodes spécifiques à l'interface ICollaborateurRepository + //public IList? GetCollaborateursByBusinessUnit(Guid businessUnitId) + //{ + // return Collaborateurs.Where(entity => entity.BusinessUnitId == businessUnitId).ToList(); + //} + + + //public IList? GetCollaborateursByReferrer(Guid referrerId) + //{ + // return Collaborateurs.Where(entity => entity.ReferrerId == referrerId).ToList(); + //} + + //public CollaborateurSqlDto? GetCollaborateurByApsideMail(string apsideMail) + //{ + // return Collaborateurs.FirstOrDefault(entity => entity.ApsideMail == apsideMail); + //} } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs index c17df44..494ce31 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs @@ -1,42 +1,49 @@ -using espacecollab.backend.infrastructure.sql.SqlRepo; +using espacecollab.backend.appservices.dtos; +using espacecollab.backend.infrastructure.sql.dtos; 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 entity) where T : class - { - return genericRepository.Add(entity); - } - - public IEnumerable GetAll() where T : class - { - return genericRepository.GetAll(); - } - - public T? GetById(Guid id) where T : class, IGenericEntity - { - return genericRepository.GetById(id); - } - - public T? Update(T entity) where T : class, IGenericEntity - { - return genericRepository.Update(entity); - } - - - } + //public abstract class GenericsServices where T : class, IGenericSqlDto + // where To : GenericApiDtoBase, new() + //{ + // private IGenericRepository GenericRepository { get; } + + // public GenericsServices(IGenericRepository genericRepository) + // { + // GenericRepository = genericRepository; + // } + + // public To? Add(To apiDto) + // { + // T? entity = GenericRepository.Add(apiDto.ToEntity()); + // if (entity == null) + // return null; + + // return new To().FromEntity(entity); + // } + + // public IEnumerable GetAll() where T : class, IGenericSqlDto + // { + // return GenericRepository.GetAll(); + // } + + // public To? GetById(Guid id) where T : class, IGenericSqlDto + // { + // T? entity = GenericRepository.GetById(id); + // if (entity == null) + // return null; + + // return new To().FromEntity(entity); + // } + + // public To? Update(To apiDto) + // { + // T? entity = GenericRepository.Update(apiDto.ToEntity()); + // if (entity == null) + // return null; + + // return new To().FromEntity(entity); + // } + //} } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices/IGenericsServices.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices/IGenericsServices.cs new file mode 100644 index 0000000..90cff2b --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices/IGenericsServices.cs @@ -0,0 +1,15 @@ +using espacecollab.backend.infrastructure.sql.dtos; + +namespace espacecollab.backend.appservices +{ + public interface IGenericsServices where T : class, IGenericSqlDto + { + To? Add(T entity); + + IEnumerable GetAll(); + + To? GetById(Guid id); + + To? Update(T entity); + } +} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/AgenceSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/AgenceSqlDto.cs index 7914345..42de69b 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/AgenceSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/AgenceSqlDto.cs @@ -2,7 +2,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos { - public class AgenceSqlDto + public class AgenceSqlDto : IGenericSqlDto { public Guid Id { get; set; } public string Name { get; set; } @@ -18,5 +18,6 @@ namespace espacecollab.backend.infrastructure.sql.dtos Id = id; Name = name; } + } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/BusinessUnitSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/BusinessUnitSqlDto.cs index 04b205b..0b055ff 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/BusinessUnitSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/BusinessUnitSqlDto.cs @@ -2,7 +2,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos { - public class BusinessUnitSqlDto + public class BusinessUnitSqlDto : IGenericSqlDto { public Guid Id { get; set; } public string Name { get; set; } @@ -20,5 +20,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos Name = name; AgenceId = agenceId; } + + } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurAppartientBusinessUnitSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurAppartientBusinessUnitSqlDto.cs index c9858c5..ff4beed 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurAppartientBusinessUnitSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurAppartientBusinessUnitSqlDto.cs @@ -7,6 +7,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos.Associations public Guid CollaborateurId { get; set; } public Guid BusinessUnitId { get; set; } + [ExcludeFromCodeCoverage] private CollaborateurAppartientBusinessUnitSqlDto() { @@ -17,5 +18,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos.Associations CollaborateurId = collaborateurId; BusinessUnitId = businessUnitId; } + + } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurCollaboreProjetSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurCollaboreProjetSqlDto.cs index ad03f99..2f9d323 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurCollaboreProjetSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurCollaboreProjetSqlDto.cs @@ -19,5 +19,6 @@ namespace espacecollab.backend.infrastructure.sql.dtos ProjetId = projetId; IsManager = isManager; } + } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurEstFonctionSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurEstFonctionSqlDto.cs index 909ec84..705427d 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurEstFonctionSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurEstFonctionSqlDto.cs @@ -2,7 +2,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos.Associations { - public class CollaborateurEstFonctionSqlDto + public class CollaborateurEstFonctionSqlDto { public Guid CollaborateurId { get; set; } public Guid FonctionId { get; set; } @@ -17,5 +17,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos.Associations CollaborateurId = collaborateurId; FonctionId = fonctionId; } + + } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurSqlDto.cs index 89d774d..04dd16c 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurSqlDto.cs @@ -2,7 +2,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos { - public class CollaborateurSqlDto + public class CollaborateurSqlDto : IGenericSqlDto { public Guid Id { get; set; } public string Name { get; set; } @@ -41,5 +41,6 @@ namespace espacecollab.backend.infrastructure.sql.dtos ReferrerId = referrerId; BusinessUnitId = businessUnitId; } + } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/FonctionSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/FonctionSqlDto.cs index 748ad5f..066eafe 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/FonctionSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/FonctionSqlDto.cs @@ -2,7 +2,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos { - public class FonctionSqlDto + public class FonctionSqlDto : IGenericSqlDto { public Guid Id { get; set; } public string Name { get; set; } @@ -17,5 +17,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos Id = id; Name = name; } + + } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/IGenericSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/IGenericSqlDto.cs new file mode 100644 index 0000000..6d34bb2 --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/IGenericSqlDto.cs @@ -0,0 +1,8 @@ +namespace espacecollab.backend.infrastructure.sql.dtos +{ + public interface IGenericSqlDto + { + public Guid Id { get; set; } + + } +} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/PeriodeEssaiSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/PeriodeEssaiSqlDto.cs index 5d9a9e5..7d0482a 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/PeriodeEssaiSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/PeriodeEssaiSqlDto.cs @@ -2,7 +2,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos { - public class PeriodeEssaiSqlDto + public class PeriodeEssaiSqlDto : IGenericSqlDto { public Guid Id { get; set; } public DateTime StartingDate { get; set; } @@ -27,5 +27,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos Issue = issue; CollaborateurId = collaborateurId; } + + } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetSqlDto.cs index 11080af..2ba06aa 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetSqlDto.cs @@ -2,7 +2,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos { - public class ProjetSqlDto + public class ProjetSqlDto : IGenericSqlDto { public Guid Id { get; set; } public string Name { get; set; } @@ -25,5 +25,6 @@ namespace espacecollab.backend.infrastructure.sql.dtos StartingDate = startingDate; EndingDate = endingDate; } + } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetUtiliseTechnologieSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetUtiliseTechnologieSqlDto.cs index e8bd1d6..513ce2d 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetUtiliseTechnologieSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetUtiliseTechnologieSqlDto.cs @@ -17,5 +17,6 @@ namespace espacecollab.backend.infrastructure.sql.dtos ProjetId = projetId; TechnologieId = technologieId; } + } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ReferencementSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ReferencementSqlDto.cs index 06e3253..a6fb391 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ReferencementSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ReferencementSqlDto.cs @@ -2,7 +2,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos { - public class ReferencementSqlDto + public class ReferencementSqlDto : IGenericSqlDto { public Guid Id { get; set; } public DateTime StartingDate { get; set; } @@ -23,5 +23,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos ReferredId = referredId; ReferrerId = referrerId; } + + } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteDeveloppeProjetSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteDeveloppeProjetSqlDto.cs index 4d03c62..1fe9942 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteDeveloppeProjetSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteDeveloppeProjetSqlDto.cs @@ -17,5 +17,8 @@ namespace espacecollab.backend.infrastructure.sql.dtos SiteId = siteId; ProjetId = projetId; } + + + } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteSqlDto.cs index 2962b45..08088fc 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteSqlDto.cs @@ -2,7 +2,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos { - public class SiteSqlDto + public class SiteSqlDto : IGenericSqlDto { public Guid Id { get; set; } public string Name { get; set; } @@ -21,5 +21,8 @@ namespace espacecollab.backend.infrastructure.sql.dtos Address = address; BusinessUnitId = businessUnitId; } + + + } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/TechnologieSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/TechnologieSqlDto.cs index 21fa7e5..e37f529 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/TechnologieSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/TechnologieSqlDto.cs @@ -2,7 +2,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos { - public class TechnologieSqlDto + public class TechnologieSqlDto : IGenericSqlDto { public Guid Id { get; set; } public string Name { get; set; } @@ -17,5 +17,6 @@ namespace espacecollab.backend.infrastructure.sql.dtos Id = id; Name = name; } + } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/FakeRepo/FakeCollaborateurRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/FakeRepo/FakeCollaborateurRepository.cs new file mode 100644 index 0000000..99edec0 --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/FakeRepo/FakeCollaborateurRepository.cs @@ -0,0 +1,81 @@ +using espacecollab.backend.infrastructure.sql.dtos; +using espacecollab.backend.infrastructure.sql.SqlRepo; +using espacecollab.backend.infrastructure.sql.SqlRepo.Interface; + +namespace espacecollab.backend.infrastructure.sql.FakeRepo +{ + public class FakeCollaborateurRepository : GenericRepository, ICollaborateurRepository + { + + private List Collaborateurs { get; set; } + + + //Context obligatoire car le Generic Repository en a un. + public FakeCollaborateurRepository() + { + + Collaborateurs = new List + { + new CollaborateurSqlDto(new Guid(), "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), new Guid(), new Guid()), + new CollaborateurSqlDto(new Guid(), "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), new Guid(), new Guid()) + }; + } + + //redéfinition des méthodes du GenericRepository pour fonctionner avec Fake + public new CollaborateurSqlDto? GetById(Guid id) + { + return Collaborateurs.FirstOrDefault(entity => entity.Id == id); + } + + public new CollaborateurSqlDto? Add(CollaborateurSqlDto entity) + { + Collaborateurs.Add(entity); + return entity; + } + + public new CollaborateurSqlDto? Delete(CollaborateurSqlDto entity) + { + Collaborateurs.Remove(entity); + return entity; + } + + public new IEnumerable GetAll() + { + return Collaborateurs; + } + + public new CollaborateurSqlDto? Update(CollaborateurSqlDto collaborateur) + { + CollaborateurSqlDto? oldCollab = Collaborateurs.FirstOrDefault(entity => entity.Id == collaborateur.Id); + if (oldCollab == null) + { + Collaborateurs.Add(collaborateur); + return collaborateur; + } + Collaborateurs.Remove(oldCollab); + Collaborateurs.Add(collaborateur); + return collaborateur; + } + + //méthodes spécifiques à l'interface ICollaborateurRepository + public IList? GetCollaborateursByBusinessUnit(Guid businessUnitId) + { + return Collaborateurs.Where(entity => entity.BusinessUnitId == businessUnitId).ToList(); + } + + + public IList? GetCollaborateursByReferrer(Guid referrerId) + { + return Collaborateurs.Where(entity => entity.ReferrerId == referrerId).ToList(); + } + + public CollaborateurSqlDto? GetCollaborateurByApsideMail(string apsideMail) + { + return Collaborateurs.FirstOrDefault(entity => entity.ApsideMail == apsideMail); + } + } +} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/CollaborateurRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/CollaborateurRepository.cs index 67ffd1b..2221b72 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/CollaborateurRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/CollaborateurRepository.cs @@ -3,50 +3,22 @@ using espacecollab.backend.infrastructure.sql.SqlRepo.Interface; namespace espacecollab.backend.infrastructure.sql.SqlRepo { - public class CollaborateurRepository : ICollaborateurRepository - { + public class CollaborateurRepository : GenericRepository,ICollaborateurRepository + { private MainDbContext Context { get; } - public CollaborateurRepository(MainDbContext context) + public CollaborateurRepository(MainDbContext context) : base(context) { Context = context; } - /* TODO Récupération des collaborateurs par agence directement dans le service Collaborateur */ - - public CollaborateurSqlDto? AddCollaborateur(CollaborateurSqlDto newCollaborateur) - { - CollaborateurSqlDto? collaborateurAlreadyExists = Context.Collaborateur?.FirstOrDefault(c => c.Id == newCollaborateur.Id); - if (collaborateurAlreadyExists != null) - return null; - - Context.Set().Add(newCollaborateur); - Context.SaveChanges(); - - return Context.Set().FirstOrDefault(c => c.Id == newCollaborateur.Id); - } - - public IList? GetAllCollaborateurs() - => Context.Set().ToList(); - public IList? GetCollaborateursByBusinessUnit(Guid businessUnitId) => Context.Set().Where(collaborateur => collaborateur.BusinessUnitId == businessUnitId).ToList(); public IList? GetCollaborateursByReferrer(Guid referrerId) => Context.Set().Where(collaborateur => collaborateur.ReferrerId == referrerId).ToList(); - public CollaborateurSqlDto? GetCollaborateurById(Guid id) - => Context?.Set().SingleOrDefault(collaborateur => collaborateur.Id == id); - public CollaborateurSqlDto? GetCollaborateurByApsideMail(string apsideMail) => Context?.Set().SingleOrDefault(collaborateur => collaborateur.ApsideMail == apsideMail); - - public CollaborateurSqlDto? UpdateCollaborateur(CollaborateurSqlDto newCollaborateur) - { - Context.Set().Update(newCollaborateur); - Context.SaveChanges(); - - return Context.Set().FirstOrDefault(c => c.Id == newCollaborateur.Id); - } } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/GenericRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/GenericRepository.cs index 57d7d78..3ecb794 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/GenericRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/GenericRepository.cs @@ -1,36 +1,48 @@ -using espacecollab.backend.infrastructure.sql.SqlRepo.Interface; +using espacecollab.backend.infrastructure.sql.dtos; +using espacecollab.backend.infrastructure.sql.SqlRepo.Interface; namespace espacecollab.backend.infrastructure.sql.SqlRepo { - public class GenericRepository : IGenericRepository + public class GenericRepository : IGenericRepository where T : class, IGenericSqlDto { private MainDbContext Context { get; } + public GenericRepository() + { + + } + public GenericRepository(MainDbContext context) { Context = context; } - public T? Add(T entity) where T : class + public virtual T? Add(T entity) { return Context.Set().Add(entity) as T; } - public IList GetAll() where T : class + public virtual T? Delete(T entity) + { + return Context.Set().Remove(entity) as T; + } + + public virtual IEnumerable GetAll() { return Context.Set().ToList(); } - public T? GetById(Guid id) where T : class,IGenericEntity + public virtual T? GetById(Guid id) { return Context.Set().FirstOrDefault(entity => entity.Id == id); } - public T? Update(T entity) where T : class, IGenericEntity + public virtual T? Update(T entity) { Context.Set().Update(entity); Context.SaveChanges(); return Context.Set().FirstOrDefault(e => e.Id == entity.Id); } + } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/IGenericEntity.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/IGenericEntity.cs deleted file mode 100644 index 3c43b76..0000000 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/IGenericEntity.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace espacecollab.backend.infrastructure.sql.SqlRepo -{ - public interface IGenericEntity - { - public Guid Id { get; set; } - } -} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IAgenceRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IAgenceRepository.cs index f0470bc..fa96d0b 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IAgenceRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IAgenceRepository.cs @@ -4,6 +4,7 @@ namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface { public interface IAgenceRepository { + //inutile ! AgenceSqlDto? AddAgence(AgenceSqlDto newAgence); IList? GetAllAgences(); AgenceSqlDto? GetAgenceById(AgenceSqlDto agence); diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IBusinessUnitRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IBusinessUnitRepository.cs index db3600b..2912591 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IBusinessUnitRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IBusinessUnitRepository.cs @@ -4,6 +4,7 @@ namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface { public interface IBusinessUnitRepository { + //inutile ! BusinessUnitSqlDto? AddBusinessUnit(BusinessUnitSqlDto newBusinessUnit); IList? GetAllBusinessUnits(); BusinessUnitSqlDto? GetBusinessUnitById(BusinessUnitSqlDto businessUnit); diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/ICollaborateurRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/ICollaborateurRepository.cs index 7271a87..e3b0a26 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/ICollaborateurRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/ICollaborateurRepository.cs @@ -2,14 +2,10 @@ namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface { - public interface ICollaborateurRepository + public interface ICollaborateurRepository : IGenericRepository { - CollaborateurSqlDto? AddCollaborateur(CollaborateurSqlDto newCollaborateur); - IList? GetAllCollaborateurs(); CollaborateurSqlDto? GetCollaborateurByApsideMail(string apsideMail); - CollaborateurSqlDto? GetCollaborateurById(Guid id); IList? GetCollaborateursByBusinessUnit(Guid businessUnitId); IList? GetCollaborateursByReferrer(Guid referrerId); - CollaborateurSqlDto? UpdateCollaborateur(CollaborateurSqlDto newCollaborateur); } } \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IGenericRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IGenericRepository.cs index e9a8feb..56c76e1 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IGenericRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IGenericRepository.cs @@ -1,11 +1,14 @@ -namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface +using espacecollab.backend.infrastructure.sql.dtos; + +namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface { - public interface IGenericRepository + public interface IGenericRepository where T : class, IGenericSqlDto { - T? Add(T entity) where T : class; - IList GetAll() where T : class; - T? GetById(Guid id) where T : class, IGenericEntity; - T? Update(T entity) where T : class, IGenericEntity; + T? Add(T entity); + T? Delete(T entity); + IEnumerable GetAll(); + T? GetById(Guid id); + T? Update(T entity); diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/INotGenericRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/INotGenericRepository.cs deleted file mode 100644 index c816bd1..0000000 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/INotGenericRepository.cs +++ /dev/null @@ -1,11 +0,0 @@ -using espacecollab.backend.infrastructure.sql.dtos; - -namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface -{ - public interface INotGenericRepository - { - CollaborateurSqlDto? GetCollaborateurByApsideMail(string apsideMail); - IList? GetCollaborateursByBusinessUnit(Guid businessUnitId); - IList? GetCollaborateursByReferrer(Guid referrerId); - } -} \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IPeriodeEssaiRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IPeriodeEssaiRepository.cs index 4b63c0a..88aa3e1 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IPeriodeEssaiRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IPeriodeEssaiRepository.cs @@ -4,6 +4,7 @@ namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface { public interface IPeriodeEssaiRepository { + //inutile ! PeriodeEssaiSqlDto? AddPeriodeEssai(PeriodeEssaiSqlDto newPeriodeEssai); IList? GetAllPeriodeEssais(); PeriodeEssaiSqlDto? GetPeriodeEssaiById(PeriodeEssaiSqlDto periodeEssai); diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IProjetRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IProjetRepository.cs index b2fa7a3..4378232 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IProjetRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IProjetRepository.cs @@ -4,10 +4,6 @@ namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface { public interface IProjetRepository { - ProjetSqlDto? AddProjet(ProjetSqlDto newProjet); - IList? GetAllProjets(); IList? GetProjetsByClient(string client); - ProjetSqlDto? GetProjetById(ProjetSqlDto projet); - ProjetSqlDto UpdateProjet(ProjetSqlDto projet); } } \ No newline at end of file -- 2.36.3 From e8beae3b90544f4ecd3d7ce094c220be4844acfe Mon Sep 17 00:00:00 2001 From: Clement FERRERE Date: Wed, 1 Dec 2021 14:55:42 +0100 Subject: [PATCH 05/19] Avancement Controller et Services Collaborateur --- .../Controllers/CollaborateursController.cs | 62 ++++++++++++++++++- .../CollaborateurApiDto.cs | 8 +-- .../CollaborateursServices.cs | 61 +++++++----------- .../GenericsServices.cs | 2 +- .../IGenericsServices.cs | 2 +- .../AgenceSqlDto.cs | 4 +- .../BusinessUnitSqlDto.cs | 6 +- ...llaborateurAppartientBusinessUnitSqlDto.cs | 6 +- .../CollaborateurCollaboreProjetSqlDto.cs | 6 +- .../CollaborateurEstFonctionSqlDto.cs | 6 +- .../CollaborateurSqlDto.cs | 8 +-- .../FonctionSqlDto.cs | 4 +- .../IGenericSqlDto.cs | 2 +- .../PeriodeEssaiSqlDto.cs | 6 +- .../ProjetSqlDto.cs | 4 +- .../ProjetUtiliseTechnologieSqlDto.cs | 6 +- .../ReferencementSqlDto.cs | 8 +-- .../SiteDeveloppeProjetSqlDto.cs | 6 +- .../SiteSqlDto.cs | 6 +- .../TechnologieSqlDto.cs | 4 +- .../FakeRepo/FakeCollaborateurRepository.cs | 18 +++--- .../SqlRepo/CollaborateurRepository.cs | 4 +- .../SqlRepo/GenericRepository.cs | 2 +- .../Interface/ICollaborateurRepository.cs | 6 +- .../SqlRepo/Interface/IGenericRepository.cs | 2 +- .../Interface/IReferencementRepository.cs | 2 +- 26 files changed, 147 insertions(+), 104 deletions(-) diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs index 426c042..a5a0caf 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs @@ -17,9 +17,67 @@ namespace espacecollab.backend.api.Controllers // GET: api/collaborateurs [HttpGet] - public IEnumerable GetCollaborateurs() + public ActionResult> GetCollaborateurs() { - return CollaborateursServices.GetCollaborateurs(); + IEnumerable collaborateurs = CollaborateursServices.GetCollaborateurs(); + if (!collaborateurs.Any()) + { + return NotFound(); + } + return Ok(collaborateurs); } + + [HttpGet("{collaborateurId}")] + public ActionResult GetCollaborateurById(int collaborateurId) + { + CollaborateurApiDto? collaborateur = CollaborateursServices.GetCollaborateurById(collaborateurId); + if (collaborateur == null) + return NotFound(); + return Ok(collaborateur); + } + + //public CollaborateurApiDto? AddCollaborateur(CollaborateurApiDto collaborateurApi) + //{ + // CollaborateurSqlDto collaborateurSql = collaborateurApi.ToSql(); + // if (collaborateurSql == null) + // return null; + // CollaborateurRepository.Add(collaborateurSql); + // return collaborateurApi; + //} + + //public CollaborateurApiDto? DeleteCollaborateur(CollaborateurApiDto collaborateurApi) + //{ + // CollaborateurSqlDto collaborateurSql = collaborateurApi.ToSql(); + // if (collaborateurSql == null) + // return null; + // CollaborateurRepository.Delete(collaborateurSql); + // return collaborateurApi; + //} + + //public CollaborateurApiDto? UpdateCollaborateur(CollaborateurApiDto collaborateurApi) + //{ + // CollaborateurSqlDto collaborateurSql = collaborateurApi.ToSql(); + // if (collaborateurSql == null) + // return null; + // CollaborateurRepository.Update(collaborateurSql); + // return collaborateurApi; + //} + + //public IEnumerable GetCollaborateursByBusinessUnit(int businessUnitId) + //{ + // return CollaborateurRepository.GetCollaborateursByBusinessUnit(businessUnitId).Select(collaborateurSql => collaborateurSql.ToApi()); + //} + + //public IEnumerable GetCollaborateursByReferrer(int referrerId) + //{ + // return CollaborateurRepository.GetCollaborateursByReferrer(referrerId).Select(collaborateurSql => collaborateurSql.ToApi()); + //} + + //public CollaborateurApiDto? GetCollaborateurByApsideMail(string apsideMail) + //{ + // if (string.IsNullOrEmpty(apsideMail)) + // return null; + // return CollaborateurRepository.GetCollaborateurByApsideMail(apsideMail).ToApi(); + //} } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs index eae4f66..aabbb3a 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs @@ -5,7 +5,7 @@ namespace espacecollab.backend.appservices.dtos { public class CollaborateurApiDto { - public Guid Id { get; set; } + public int Id { get; set; } public string Name { get; set; } public string FirstName { get; set; } public DateTime BirthDate { get; set; } @@ -17,15 +17,15 @@ namespace espacecollab.backend.appservices.dtos 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; } + public int ReferrerId { get; set; } + public int BusinessUnitId { get; set; } public 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) + public CollaborateurApiDto(int id, string name, string firstName, DateTime birthDate, EnumGenreApi gender, EnumStatutApi status, int childrenNumber, string address, string telephone, string personalMail, string apsideMail, DateTime resignationDate, int referrerId, int businessUnitId) { Id = id; Name = name; diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs index df4d4b3..3eff512 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs @@ -21,7 +21,7 @@ namespace espacecollab.backend.appservices return CollaborateurRepository.GetAll().Select(collaborateurSql => collaborateurSql.ToApi()); } - public CollaborateurApiDto? GetCollaborateurById(Guid id) + public CollaborateurApiDto? GetCollaborateurById(int id) { return CollaborateurRepository.GetById(id)?.ToApi(); } @@ -44,45 +44,30 @@ namespace espacecollab.backend.appservices return collaborateurApi; } - //public new CollaborateurSqlDto? Delete(CollaborateurSqlDto entity) - //{ - // Collaborateurs.Remove(entity); - // return entity; - //} - - //public new IEnumerable GetAll() - //{ - // return Collaborateurs; - //} - - //public new CollaborateurSqlDto? Update(CollaborateurSqlDto collaborateur) - //{ - // CollaborateurSqlDto? oldCollab = Collaborateurs.FirstOrDefault(entity => entity.Id == collaborateur.Id); - // if (oldCollab == null) - // { - // Collaborateurs.Add(collaborateur); - // return collaborateur; - // } - // Collaborateurs.Remove(oldCollab); - // Collaborateurs.Add(collaborateur); - // return collaborateur; - //} - - ////méthodes spécifiques à l'interface ICollaborateurRepository - //public IList? GetCollaborateursByBusinessUnit(Guid businessUnitId) - //{ - // return Collaborateurs.Where(entity => entity.BusinessUnitId == businessUnitId).ToList(); - //} + public CollaborateurApiDto? UpdateCollaborateur(CollaborateurApiDto collaborateurApi) + { + CollaborateurSqlDto collaborateurSql = collaborateurApi.ToSql(); + if (collaborateurSql == null) + return null; + CollaborateurRepository.Update(collaborateurSql); + return collaborateurApi; + } + public IEnumerable GetCollaborateursByBusinessUnit(int businessUnitId) + { + return CollaborateurRepository.GetCollaborateursByBusinessUnit(businessUnitId).Select(collaborateurSql => collaborateurSql.ToApi()); + } - //public IList? GetCollaborateursByReferrer(Guid referrerId) - //{ - // return Collaborateurs.Where(entity => entity.ReferrerId == referrerId).ToList(); - //} + public IEnumerable GetCollaborateursByReferrer(int referrerId) + { + return CollaborateurRepository.GetCollaborateursByReferrer(referrerId).Select(collaborateurSql => collaborateurSql.ToApi()); + } - //public CollaborateurSqlDto? GetCollaborateurByApsideMail(string apsideMail) - //{ - // return Collaborateurs.FirstOrDefault(entity => entity.ApsideMail == apsideMail); - //} + public CollaborateurApiDto? GetCollaborateurByApsideMail(string apsideMail) + { + if (string.IsNullOrEmpty(apsideMail)) + return null; + return CollaborateurRepository.GetCollaborateurByApsideMail(apsideMail).ToApi(); + } } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs index 494ce31..99a4385 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs @@ -28,7 +28,7 @@ namespace espacecollab.backend.appservices // return GenericRepository.GetAll(); // } - // public To? GetById(Guid id) where T : class, IGenericSqlDto + // public To? GetById(int id) where T : class, IGenericSqlDto // { // T? entity = GenericRepository.GetById(id); // if (entity == null) diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices/IGenericsServices.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices/IGenericsServices.cs index 90cff2b..443a80c 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices/IGenericsServices.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices/IGenericsServices.cs @@ -8,7 +8,7 @@ namespace espacecollab.backend.appservices IEnumerable GetAll(); - To? GetById(Guid id); + To? GetById(int id); To? Update(T entity); } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/AgenceSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/AgenceSqlDto.cs index 42de69b..cbe1ccc 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/AgenceSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/AgenceSqlDto.cs @@ -4,7 +4,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos { public class AgenceSqlDto : IGenericSqlDto { - public Guid Id { get; set; } + public int Id { get; set; } public string Name { get; set; } [ExcludeFromCodeCoverage] @@ -13,7 +13,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos { } - public AgenceSqlDto(Guid id, string name) + public AgenceSqlDto(int id, string name) { Id = id; Name = name; diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/BusinessUnitSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/BusinessUnitSqlDto.cs index 0b055ff..4b20d4a 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/BusinessUnitSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/BusinessUnitSqlDto.cs @@ -4,9 +4,9 @@ namespace espacecollab.backend.infrastructure.sql.dtos { public class BusinessUnitSqlDto : IGenericSqlDto { - public Guid Id { get; set; } + public int Id { get; set; } public string Name { get; set; } - public Guid AgenceId { get; set; } + public int AgenceId { get; set; } [ExcludeFromCodeCoverage] @@ -14,7 +14,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos { } - public BusinessUnitSqlDto(Guid id, string name, Guid agenceId) + public BusinessUnitSqlDto(int id, string name, int agenceId) { Id = id; Name = name; diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurAppartientBusinessUnitSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurAppartientBusinessUnitSqlDto.cs index ff4beed..8eb40da 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurAppartientBusinessUnitSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurAppartientBusinessUnitSqlDto.cs @@ -4,8 +4,8 @@ namespace espacecollab.backend.infrastructure.sql.dtos.Associations { public class CollaborateurAppartientBusinessUnitSqlDto { - public Guid CollaborateurId { get; set; } - public Guid BusinessUnitId { get; set; } + public int CollaborateurId { get; set; } + public int BusinessUnitId { get; set; } [ExcludeFromCodeCoverage] @@ -13,7 +13,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos.Associations { } - public CollaborateurAppartientBusinessUnitSqlDto(Guid collaborateurId, Guid businessUnitId) + public CollaborateurAppartientBusinessUnitSqlDto(int collaborateurId, int businessUnitId) { CollaborateurId = collaborateurId; BusinessUnitId = businessUnitId; diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurCollaboreProjetSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurCollaboreProjetSqlDto.cs index 2f9d323..0c61504 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurCollaboreProjetSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurCollaboreProjetSqlDto.cs @@ -4,8 +4,8 @@ namespace espacecollab.backend.infrastructure.sql.dtos { public class CollaborateurCollaboreProjetSqlDto { - public Guid CollaborateurId { get; set; } - public Guid ProjetId { get; set; } + public int CollaborateurId { get; set; } + public int ProjetId { get; set; } public bool IsManager { get; set; } [ExcludeFromCodeCoverage] @@ -13,7 +13,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos { } - public CollaborateurCollaboreProjetSqlDto(Guid collaborateurId, Guid projetId, bool isManager) + public CollaborateurCollaboreProjetSqlDto(int collaborateurId, int projetId, bool isManager) { CollaborateurId = collaborateurId; ProjetId = projetId; diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurEstFonctionSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurEstFonctionSqlDto.cs index 705427d..a3cdd1a 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurEstFonctionSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurEstFonctionSqlDto.cs @@ -4,15 +4,15 @@ namespace espacecollab.backend.infrastructure.sql.dtos.Associations { public class CollaborateurEstFonctionSqlDto { - public Guid CollaborateurId { get; set; } - public Guid FonctionId { get; set; } + public int CollaborateurId { get; set; } + public int FonctionId { get; set; } [ExcludeFromCodeCoverage] private CollaborateurEstFonctionSqlDto() { } - public CollaborateurEstFonctionSqlDto(Guid collaborateurId, Guid fonctionId) + public CollaborateurEstFonctionSqlDto(int collaborateurId, int fonctionId) { CollaborateurId = collaborateurId; FonctionId = fonctionId; diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurSqlDto.cs index 04dd16c..1ecd821 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurSqlDto.cs @@ -4,7 +4,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos { public class CollaborateurSqlDto : IGenericSqlDto { - public Guid Id { get; set; } + public int Id { get; set; } public string Name { get; set; } public string FirstName { get; set; } public DateTime BirthDate { get; set; } @@ -16,15 +16,15 @@ namespace espacecollab.backend.infrastructure.sql.dtos 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; } + public int ReferrerId { get; set; } + public int BusinessUnitId { get; set; } [ExcludeFromCodeCoverage] private CollaborateurSqlDto() { } - 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) + 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; diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/FonctionSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/FonctionSqlDto.cs index 066eafe..db63bc9 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/FonctionSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/FonctionSqlDto.cs @@ -4,7 +4,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos { public class FonctionSqlDto : IGenericSqlDto { - public Guid Id { get; set; } + public int Id { get; set; } public string Name { get; set; } [ExcludeFromCodeCoverage] @@ -12,7 +12,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos { } - public FonctionSqlDto(Guid id, string name) + public FonctionSqlDto(int id, string name) { Id = id; Name = name; diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/IGenericSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/IGenericSqlDto.cs index 6d34bb2..93547ed 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/IGenericSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/IGenericSqlDto.cs @@ -2,7 +2,7 @@ { public interface IGenericSqlDto { - public Guid Id { get; set; } + public int Id { get; set; } } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/PeriodeEssaiSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/PeriodeEssaiSqlDto.cs index 7d0482a..110ccf7 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/PeriodeEssaiSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/PeriodeEssaiSqlDto.cs @@ -4,20 +4,20 @@ namespace espacecollab.backend.infrastructure.sql.dtos { public class PeriodeEssaiSqlDto : IGenericSqlDto { - public Guid Id { 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 Guid CollaborateurId { get; set; } + public int CollaborateurId { get; set; } [ExcludeFromCodeCoverage] private PeriodeEssaiSqlDto() { } - public PeriodeEssaiSqlDto(Guid id, DateTime startingDate, DateTime plannedEndingDate, DateTime realEndingDate, string comment, EnumIssueSql issue, Guid collaborateurId) + public PeriodeEssaiSqlDto(int id, DateTime startingDate, DateTime plannedEndingDate, DateTime realEndingDate, string comment, EnumIssueSql issue, int collaborateurId) { Id = id; StartingDate = startingDate; diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetSqlDto.cs index 2ba06aa..2e93a0c 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetSqlDto.cs @@ -4,7 +4,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos { public class ProjetSqlDto : IGenericSqlDto { - public Guid Id { get; set; } + public int Id { get; set; } public string Name { get; set; } public string Client { get; set; } public string Description { get; set; } @@ -16,7 +16,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos { } - public ProjetSqlDto(Guid id, string name, string client, string description, DateTime startingDate, DateTime endingDate) + public ProjetSqlDto(int id, string name, string client, string description, DateTime startingDate, DateTime endingDate) { Id = id; Name = name; diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetUtiliseTechnologieSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetUtiliseTechnologieSqlDto.cs index 513ce2d..b3ef497 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetUtiliseTechnologieSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetUtiliseTechnologieSqlDto.cs @@ -4,15 +4,15 @@ namespace espacecollab.backend.infrastructure.sql.dtos { public class ProjetUtiliseTechnologieSqlDto { - public Guid ProjetId { get; set; } - public Guid TechnologieId { get; set; } + public int ProjetId { get; set; } + public int TechnologieId { get; set; } [ExcludeFromCodeCoverage] private ProjetUtiliseTechnologieSqlDto() { } - public ProjetUtiliseTechnologieSqlDto(Guid projetId, Guid technologieId) + public ProjetUtiliseTechnologieSqlDto(int projetId, int technologieId) { ProjetId = projetId; TechnologieId = technologieId; diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ReferencementSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ReferencementSqlDto.cs index a6fb391..d69163d 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ReferencementSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ReferencementSqlDto.cs @@ -4,18 +4,18 @@ namespace espacecollab.backend.infrastructure.sql.dtos { public class ReferencementSqlDto : IGenericSqlDto { - public Guid Id { get; set; } + public int Id { get; set; } public DateTime StartingDate { get; set; } public DateTime EndingDate { get; set; } - public Guid ReferredId { get; set; } - public Guid ReferrerId { get; set; } + public int ReferredId { get; set; } + public int ReferrerId { get; set; } [ExcludeFromCodeCoverage] private ReferencementSqlDto() { } - public ReferencementSqlDto(Guid id, DateTime startingDate, DateTime endingDate, Guid referredId, Guid referrerId) + public ReferencementSqlDto(int id, DateTime startingDate, DateTime endingDate, int referredId, int referrerId) { Id = id; StartingDate = startingDate; diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteDeveloppeProjetSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteDeveloppeProjetSqlDto.cs index 1fe9942..44e4828 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteDeveloppeProjetSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteDeveloppeProjetSqlDto.cs @@ -4,15 +4,15 @@ namespace espacecollab.backend.infrastructure.sql.dtos { public class SiteDeveloppeProjetSqlDto { - public Guid SiteId { get; set; } - public Guid ProjetId { get; set; } + public int SiteId { get; set; } + public int ProjetId { get; set; } [ExcludeFromCodeCoverage] private SiteDeveloppeProjetSqlDto() { } - public SiteDeveloppeProjetSqlDto(Guid siteId, Guid projetId) + public SiteDeveloppeProjetSqlDto(int siteId, int projetId) { SiteId = siteId; ProjetId = projetId; diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteSqlDto.cs index 08088fc..a59f867 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteSqlDto.cs @@ -4,17 +4,17 @@ namespace espacecollab.backend.infrastructure.sql.dtos { public class SiteSqlDto : IGenericSqlDto { - public Guid Id { get; set; } + public int Id { get; set; } public string Name { get; set; } public string Address { get; set; } - public Guid BusinessUnitId { get; set; } + public int BusinessUnitId { get; set; } [ExcludeFromCodeCoverage] private SiteSqlDto() { } - public SiteSqlDto(Guid id, string name, string address, Guid businessUnitId) + public SiteSqlDto(int id, string name, string address, int businessUnitId) { Id = id; Name = name; diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/TechnologieSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/TechnologieSqlDto.cs index e37f529..cf38ed6 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/TechnologieSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/TechnologieSqlDto.cs @@ -4,7 +4,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos { public class TechnologieSqlDto : IGenericSqlDto { - public Guid Id { get; set; } + public int Id { get; set; } public string Name { get; set; } [ExcludeFromCodeCoverage] @@ -12,7 +12,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos { } - public TechnologieSqlDto(Guid id, string name) + public TechnologieSqlDto(int id, string name) { Id = id; Name = name; diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/FakeRepo/FakeCollaborateurRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/FakeRepo/FakeCollaborateurRepository.cs index 99edec0..2a67ee1 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/FakeRepo/FakeCollaborateurRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/FakeRepo/FakeCollaborateurRepository.cs @@ -16,17 +16,17 @@ namespace espacecollab.backend.infrastructure.sql.FakeRepo Collaborateurs = new List { - new CollaborateurSqlDto(new Guid(), "Dupont", "Jean", new DateTime(1980, 12, 10), + new CollaborateurSqlDto(new int(), "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), new Guid(), new Guid()), - new CollaborateurSqlDto(new Guid(), "Michel", "Laura", new DateTime(1985, 08, 12), + "jean.dupont@gmail.com", "jean.dupont@apside-groupe.com", new DateTime(2023, 12, 17), new int(), new int()), + new CollaborateurSqlDto(new int(), "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), new Guid(), new Guid()) + "laura.michel@gmail.com", "laura.michel@apside-groupe.com", new DateTime(2023, 12, 17), new int(), new int()) }; } //redéfinition des méthodes du GenericRepository pour fonctionner avec Fake - public new CollaborateurSqlDto? GetById(Guid id) + public new CollaborateurSqlDto? GetById(int id) { return Collaborateurs.FirstOrDefault(entity => entity.Id == id); } @@ -62,20 +62,20 @@ namespace espacecollab.backend.infrastructure.sql.FakeRepo } //méthodes spécifiques à l'interface ICollaborateurRepository - public IList? GetCollaborateursByBusinessUnit(Guid businessUnitId) + public IList GetCollaborateursByBusinessUnit(int businessUnitId) { return Collaborateurs.Where(entity => entity.BusinessUnitId == businessUnitId).ToList(); } - public IList? GetCollaborateursByReferrer(Guid referrerId) + public IList GetCollaborateursByReferrer(int referrerId) { return Collaborateurs.Where(entity => entity.ReferrerId == referrerId).ToList(); } - public CollaborateurSqlDto? GetCollaborateurByApsideMail(string apsideMail) + public CollaborateurSqlDto GetCollaborateurByApsideMail(string apsideMail) { - return Collaborateurs.FirstOrDefault(entity => entity.ApsideMail == apsideMail); + return Collaborateurs.First(entity => entity.ApsideMail == apsideMail); } } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/CollaborateurRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/CollaborateurRepository.cs index 2221b72..6c3f20f 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/CollaborateurRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/CollaborateurRepository.cs @@ -12,10 +12,10 @@ namespace espacecollab.backend.infrastructure.sql.SqlRepo Context = context; } - public IList? GetCollaborateursByBusinessUnit(Guid businessUnitId) + public IList GetCollaborateursByBusinessUnit(int businessUnitId) => Context.Set().Where(collaborateur => collaborateur.BusinessUnitId == businessUnitId).ToList(); - public IList? GetCollaborateursByReferrer(Guid referrerId) + public IList GetCollaborateursByReferrer(int referrerId) => Context.Set().Where(collaborateur => collaborateur.ReferrerId == referrerId).ToList(); public CollaborateurSqlDto? GetCollaborateurByApsideMail(string apsideMail) diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/GenericRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/GenericRepository.cs index 3ecb794..373b35d 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/GenericRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/GenericRepository.cs @@ -32,7 +32,7 @@ namespace espacecollab.backend.infrastructure.sql.SqlRepo return Context.Set().ToList(); } - public virtual T? GetById(Guid id) + public virtual T? GetById(int id) { return Context.Set().FirstOrDefault(entity => entity.Id == id); } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/ICollaborateurRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/ICollaborateurRepository.cs index e3b0a26..3fef7b3 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/ICollaborateurRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/ICollaborateurRepository.cs @@ -4,8 +4,8 @@ namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface { public interface ICollaborateurRepository : IGenericRepository { - CollaborateurSqlDto? GetCollaborateurByApsideMail(string apsideMail); - IList? GetCollaborateursByBusinessUnit(Guid businessUnitId); - IList? GetCollaborateursByReferrer(Guid referrerId); + CollaborateurSqlDto GetCollaborateurByApsideMail(string apsideMail); + IList GetCollaborateursByBusinessUnit(int businessUnitId); + IList GetCollaborateursByReferrer(int referrerId); } } \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IGenericRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IGenericRepository.cs index 56c76e1..d97622c 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IGenericRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IGenericRepository.cs @@ -7,7 +7,7 @@ namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface T? Add(T entity); T? Delete(T entity); IEnumerable GetAll(); - T? GetById(Guid id); + T? GetById(int id); T? Update(T entity); diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IReferencementRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IReferencementRepository.cs index 43810f3..28926ce 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IReferencementRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IReferencementRepository.cs @@ -4,7 +4,7 @@ namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface { public interface IReferencementRepository { - IList? GetReferrersByCollaborateurId(Guid collaborateurId); + IList? GetReferrersByCollaborateurId(int collaborateurId); IList? GetReferrersByCollaborateurApsideMail(string apsideMail); //TODO Voir les attentes concernant "le référent ayant le plus suivi depuis une date" -- 2.36.3 From f1de70eafae46479693114e7da8cb54d3fe3e09f Mon Sep 17 00:00:00 2001 From: Clement FERRERE Date: Wed, 1 Dec 2021 15:14:47 +0100 Subject: [PATCH 06/19] Generic get by id, refacto par Alex --- .../Controllers/CollaborateursController.cs | 10 +- .../CollaborateursControllerTestGeneric.cs | 26 ------ .../espacecollab.backend.api/Startup.cs | 14 +-- .../Mappers/EnumGenreMapper.cs | 2 +- .../Mappers/EnumStatutMapper.cs | 2 +- .../CollaborateursServices.cs | 22 ++--- .../GenericsServices.cs | 92 ++++++++++--------- .../CollaborateurSqlDto.cs | 9 +- .../PeriodeEssaiSqlDto.cs | 4 +- .../{ => Values}/EnumGenreSql.cs | 2 +- .../{ => Values}/EnumIssueSql.cs | 2 +- .../{ => Values}/EnumStatutSql.cs | 2 +- .../FakeRepo/FakeCollaborateurRepository.cs | 35 +++---- ...itory.cs => CollaborateurSqlRepository.cs} | 4 +- .../SqlRepo/Interface/IAgenceRepository.cs | 7 +- .../Interface/IBusinessUnitRepository.cs | 7 +- .../Interface/ICollaborateurRepository.cs | 2 +- .../SqlRepo/Interface/IGenericRepository.cs | 6 +- .../Interface/IPeriodeEssaiRepository.cs | 7 +- .../SqlRepo/Interface/IProjetRepository.cs | 4 +- .../Interface/IReferencementRepository.cs | 3 +- 21 files changed, 107 insertions(+), 155 deletions(-) delete mode 100644 Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursControllerTestGeneric.cs rename Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/{ => Values}/EnumGenreSql.cs (59%) rename Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/{ => Values}/EnumIssueSql.cs (71%) rename Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/{ => Values}/EnumStatutSql.cs (64%) rename Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/{CollaborateurRepository.cs => CollaborateurSqlRepository.cs} (83%) diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs index a5a0caf..b5ccfb9 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs @@ -19,20 +19,16 @@ namespace espacecollab.backend.api.Controllers [HttpGet] public ActionResult> GetCollaborateurs() { - IEnumerable collaborateurs = CollaborateursServices.GetCollaborateurs(); - if (!collaborateurs.Any()) - { - return NotFound(); - } - return Ok(collaborateurs); + return Ok(CollaborateursServices.GetAll()); } [HttpGet("{collaborateurId}")] public ActionResult GetCollaborateurById(int collaborateurId) { - CollaborateurApiDto? collaborateur = CollaborateursServices.GetCollaborateurById(collaborateurId); + CollaborateurApiDto? collaborateur = CollaborateursServices.GetById(collaborateurId); if (collaborateur == null) return NotFound(); + return Ok(collaborateur); } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursControllerTestGeneric.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursControllerTestGeneric.cs deleted file mode 100644 index b926d16..0000000 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursControllerTestGeneric.cs +++ /dev/null @@ -1,26 +0,0 @@ -using espacecollab.backend.appservices; -using espacecollab.backend.appservices.dtos; -using Microsoft.AspNetCore.Mvc; - -namespace espacecollab.backend.api.Controllers -{ - [Route("api/[controller]")] - [ApiController] - public class CollaborateursControllerTestGeneric : ControllerBase - { - private CollaborateursServices CollaborateursServices { get; } - - public CollaborateursControllerTestGeneric(CollaborateursServices collaborateursServices) - { - CollaborateursServices = collaborateursServices; - } - - // GET: api/collaborateurs - //[HttpGet] - //public ActionResult> GetCollaborateurs() - //{ - // return CollaborateursServices.GetAll(); - - //} - } -} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Startup.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Startup.cs index cc606b5..ad7b864 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/Startup.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Startup.cs @@ -19,8 +19,6 @@ namespace Api // 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(sqlSection); SqlOption contextOptions = sqlSection.Get(); @@ -30,21 +28,17 @@ namespace Api if (contextOptions.LoadFake) { - - + services.AddScoped(); } else { - //services.AddScoped(); + services.AddScoped(); } - //services.AddScoped, GenericRepository>(); - //services.AddScoped, FakeCollaborateurRepository>(); - services.AddScoped(); + services.AddScoped(); - services.AddScoped(); - + services.AddEndpointsApiExplorer(); services.AddSwaggerGen(); } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/EnumGenreMapper.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/EnumGenreMapper.cs index b7eb349..ff142fc 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/EnumGenreMapper.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/EnumGenreMapper.cs @@ -1,4 +1,4 @@ -using espacecollab.backend.infrastructure.sql.dtos; +using espacecollab.backend.infrastructure.sql.dtos.Values; namespace espacecollab.backend.appservices.dtos.Mappers { diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/EnumStatutMapper.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/EnumStatutMapper.cs index cde5356..85a6e5d 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/EnumStatutMapper.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/EnumStatutMapper.cs @@ -1,4 +1,4 @@ -using espacecollab.backend.infrastructure.sql.dtos; +using espacecollab.backend.infrastructure.sql.dtos.Values; namespace espacecollab.backend.appservices.dtos.Mappers { diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs index 3eff512..a5e442d 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs @@ -7,28 +7,19 @@ using espacecollab.backend.infrastructure.sql.SqlRepo.Interface; namespace espacecollab.backend.appservices { - public class CollaborateursServices + public class CollaborateursServices : GenericsServices { private ICollaborateurRepository CollaborateurRepository { get; } - public CollaborateursServices(ICollaborateurRepository collaborateur) + public CollaborateursServices(ICollaborateurRepository collaborateurRepository) + :base(collaborateurRepository, CollaborateurMapper.ToApi, CollaborateurMapper.ToSql) { - CollaborateurRepository = collaborateur; - } - - public IEnumerable GetCollaborateurs() - { - return CollaborateurRepository.GetAll().Select(collaborateurSql => collaborateurSql.ToApi()); - } - - public CollaborateurApiDto? GetCollaborateurById(int id) - { - return CollaborateurRepository.GetById(id)?.ToApi(); + CollaborateurRepository = collaborateurRepository; } public CollaborateurApiDto? AddCollaborateur(CollaborateurApiDto collaborateurApi) { - CollaborateurSqlDto collaborateurSql = collaborateurApi.ToSql(); + CollaborateurSqlDto collaborateurSql = collaborateurApi.ToSql(); if (collaborateurSql == null) return null; CollaborateurRepository.Add(collaborateurSql); @@ -67,7 +58,8 @@ namespace espacecollab.backend.appservices { if (string.IsNullOrEmpty(apsideMail)) return null; - return CollaborateurRepository.GetCollaborateurByApsideMail(apsideMail).ToApi(); + + return CollaborateurRepository.GetCollaborateurByApsideMail(apsideMail)?.ToApi(); } } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs index 99a4385..09778e9 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs @@ -1,49 +1,53 @@ -using espacecollab.backend.appservices.dtos; -using espacecollab.backend.infrastructure.sql.dtos; +using espacecollab.backend.infrastructure.sql.dtos; using espacecollab.backend.infrastructure.sql.SqlRepo.Interface; namespace espacecollab.backend.appservices { - //public abstract class GenericsServices where T : class, IGenericSqlDto - // where To : GenericApiDtoBase, new() - //{ - // private IGenericRepository GenericRepository { get; } - - // public GenericsServices(IGenericRepository genericRepository) - // { - // GenericRepository = genericRepository; - // } - - // public To? Add(To apiDto) - // { - // T? entity = GenericRepository.Add(apiDto.ToEntity()); - // if (entity == null) - // return null; - - // return new To().FromEntity(entity); - // } - - // public IEnumerable GetAll() where T : class, IGenericSqlDto - // { - // return GenericRepository.GetAll(); - // } - - // public To? GetById(int id) where T : class, IGenericSqlDto - // { - // T? entity = GenericRepository.GetById(id); - // if (entity == null) - // return null; - - // return new To().FromEntity(entity); - // } - - // public To? Update(To apiDto) - // { - // T? entity = GenericRepository.Update(apiDto.ToEntity()); - // if (entity == null) - // return null; - - // return new To().FromEntity(entity); - // } - //} + public abstract class GenericsServices where T : class, IGenericSqlDto + where To : class + { + Func MapperToApiDto { get; } + Func MapperToSqlDto { get; } + + private IGenericRepository GenericRepository { get; } + + public GenericsServices(IGenericRepository genericRepository, Func mapperToApiDto, Func mapperToSqlDto) + { + GenericRepository = genericRepository; + MapperToApiDto = mapperToApiDto; + MapperToSqlDto = mapperToSqlDto; + } + + //public To? Add(To apiDto) + //{ + // T? entity = GenericRepository.Add(apiDto.ToEntity()); + // if (entity == null) + // return null; + + // return new To().FromEntity(entity); + //} + + public IEnumerable GetAll() + { + return GenericRepository.GetAll().Select(entity => MapperToApiDto(entity)).ToList(); + } + + public To? GetById(int id) + { + T? entity = GenericRepository.GetById(id); + if (entity == null) + return null; + + return MapperToApiDto(entity); + } + + //public To? Update(To apiDto) + //{ + // T? entity = GenericRepository.Update(apiDto.ToEntity()); + // if (entity == null) + // return null; + + // return new To().FromEntity(entity); + //} + } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurSqlDto.cs index 1ecd821..137764e 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurSqlDto.cs @@ -1,4 +1,5 @@ -using System.Diagnostics.CodeAnalysis; +using espacecollab.backend.infrastructure.sql.dtos.Values; +using System.Diagnostics.CodeAnalysis; namespace espacecollab.backend.infrastructure.sql.dtos { @@ -22,6 +23,12 @@ 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 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) diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/PeriodeEssaiSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/PeriodeEssaiSqlDto.cs index 110ccf7..bcc3d5e 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/PeriodeEssaiSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/PeriodeEssaiSqlDto.cs @@ -1,4 +1,5 @@ -using System.Diagnostics.CodeAnalysis; +using espacecollab.backend.infrastructure.sql.dtos.Values; +using System.Diagnostics.CodeAnalysis; namespace espacecollab.backend.infrastructure.sql.dtos { @@ -15,6 +16,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos [ExcludeFromCodeCoverage] private PeriodeEssaiSqlDto() { + Comment = string.Empty; } public PeriodeEssaiSqlDto(int id, DateTime startingDate, DateTime plannedEndingDate, DateTime realEndingDate, string comment, EnumIssueSql issue, int collaborateurId) diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/EnumGenreSql.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/Values/EnumGenreSql.cs similarity index 59% rename from Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/EnumGenreSql.cs rename to Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/Values/EnumGenreSql.cs index 0fc889b..f3298bc 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/EnumGenreSql.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/Values/EnumGenreSql.cs @@ -1,4 +1,4 @@ -namespace espacecollab.backend.infrastructure.sql.dtos +namespace espacecollab.backend.infrastructure.sql.dtos.Values { public enum EnumGenreSql { diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/EnumIssueSql.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/Values/EnumIssueSql.cs similarity index 71% rename from Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/EnumIssueSql.cs rename to Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/Values/EnumIssueSql.cs index 2945779..63e990c 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/EnumIssueSql.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/Values/EnumIssueSql.cs @@ -1,4 +1,4 @@ -namespace espacecollab.backend.infrastructure.sql.dtos +namespace espacecollab.backend.infrastructure.sql.dtos.Values { public enum EnumIssueSql { diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/EnumStatutSql.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/Values/EnumStatutSql.cs similarity index 64% rename from Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/EnumStatutSql.cs rename to Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/Values/EnumStatutSql.cs index 9e57875..d0284a3 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/EnumStatutSql.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/Values/EnumStatutSql.cs @@ -1,4 +1,4 @@ -namespace espacecollab.backend.infrastructure.sql.dtos +namespace espacecollab.backend.infrastructure.sql.dtos.Values { public enum EnumStatutSql { diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/FakeRepo/FakeCollaborateurRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/FakeRepo/FakeCollaborateurRepository.cs index 2a67ee1..cc89025 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/FakeRepo/FakeCollaborateurRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/FakeRepo/FakeCollaborateurRepository.cs @@ -1,4 +1,5 @@ using espacecollab.backend.infrastructure.sql.dtos; +using espacecollab.backend.infrastructure.sql.dtos.Values; using espacecollab.backend.infrastructure.sql.SqlRepo; using espacecollab.backend.infrastructure.sql.SqlRepo.Interface; @@ -7,30 +8,28 @@ namespace espacecollab.backend.infrastructure.sql.FakeRepo public class FakeCollaborateurRepository : GenericRepository, ICollaborateurRepository { - private List Collaborateurs { get; set; } - - - //Context obligatoire car le Generic Repository en a un. - public FakeCollaborateurRepository() - { - - Collaborateurs = new List + private IList Collaborateurs { get; } = new List { - new CollaborateurSqlDto(new int(), "Dupont", "Jean", new DateTime(1980, 12, 10), + new CollaborateurSqlDto(1, "Dupont", "Jean", new DateTime(1980, 12, 10), EnumGenreSql.MASCULIN, EnumStatutSql.NONCADRE, 0, "1 rue du Louvre, 63000, Clermont-Ferrand", "0660258644", - "jean.dupont@gmail.com", "jean.dupont@apside-groupe.com", new DateTime(2023, 12, 17), new int(), new int()), - new CollaborateurSqlDto(new int(), "Michel", "Laura", new DateTime(1985, 08, 12), + "jean.dupont@gmail.com", "jean.dupont@apside-groupe.com", new DateTime(2023, 12, 17), 2, 1), + + new CollaborateurSqlDto(2, "Michel", "Laura", new DateTime(1985, 08, 12), EnumGenreSql.FEMININ, EnumStatutSql.NONCADRE, 0, "5 rue du Louvre, 63000, Clermont-Ferrand", "0660258644", - "laura.michel@gmail.com", "laura.michel@apside-groupe.com", new DateTime(2023, 12, 17), new int(), new int()) + "laura.michel@gmail.com", "laura.michel@apside-groupe.com", new DateTime(2023, 12, 17), 1, 1) }; + + public FakeCollaborateurRepository() + { } - //redéfinition des méthodes du GenericRepository pour fonctionner avec Fake + #region redéfinition des méthodes du GenericRepository pour fonctionner avec Fake + public new CollaborateurSqlDto? GetById(int id) { return Collaborateurs.FirstOrDefault(entity => entity.Id == id); } - + public new CollaborateurSqlDto? Add(CollaborateurSqlDto entity) { Collaborateurs.Add(entity); @@ -61,13 +60,15 @@ namespace espacecollab.backend.infrastructure.sql.FakeRepo return collaborateur; } - //méthodes spécifiques à l'interface ICollaborateurRepository + #endregion + + #region méthodes spécifiques à l'interface ICollaborateurRepository + public IList GetCollaborateursByBusinessUnit(int businessUnitId) { return Collaborateurs.Where(entity => entity.BusinessUnitId == businessUnitId).ToList(); } - public IList GetCollaborateursByReferrer(int referrerId) { return Collaborateurs.Where(entity => entity.ReferrerId == referrerId).ToList(); @@ -77,5 +78,7 @@ namespace espacecollab.backend.infrastructure.sql.FakeRepo { return Collaborateurs.First(entity => entity.ApsideMail == apsideMail); } + + #endregion } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/CollaborateurRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/CollaborateurSqlRepository.cs similarity index 83% rename from Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/CollaborateurRepository.cs rename to Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/CollaborateurSqlRepository.cs index 6c3f20f..6903f92 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/CollaborateurRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/CollaborateurSqlRepository.cs @@ -3,11 +3,11 @@ using espacecollab.backend.infrastructure.sql.SqlRepo.Interface; namespace espacecollab.backend.infrastructure.sql.SqlRepo { - public class CollaborateurRepository : GenericRepository,ICollaborateurRepository + public class CollaborateurSqlRepository : GenericRepository,ICollaborateurRepository { private MainDbContext Context { get; } - public CollaborateurRepository(MainDbContext context) : base(context) + public CollaborateurSqlRepository(MainDbContext context) : base(context) { Context = context; } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IAgenceRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IAgenceRepository.cs index fa96d0b..15f90be 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IAgenceRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IAgenceRepository.cs @@ -2,12 +2,7 @@ namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface { - public interface IAgenceRepository + public interface IAgenceRepository : IGenericRepository { - //inutile ! - AgenceSqlDto? AddAgence(AgenceSqlDto newAgence); - IList? GetAllAgences(); - AgenceSqlDto? GetAgenceById(AgenceSqlDto agence); - AgenceSqlDto UpdateAgence(AgenceSqlDto agence); } } \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IBusinessUnitRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IBusinessUnitRepository.cs index 2912591..0aadfc4 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IBusinessUnitRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IBusinessUnitRepository.cs @@ -2,12 +2,7 @@ namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface { - public interface IBusinessUnitRepository + public interface IBusinessUnitRepository : IGenericRepository { - //inutile ! - BusinessUnitSqlDto? AddBusinessUnit(BusinessUnitSqlDto newBusinessUnit); - IList? GetAllBusinessUnits(); - BusinessUnitSqlDto? GetBusinessUnitById(BusinessUnitSqlDto businessUnit); - BusinessUnitSqlDto UpdateBusinessUnit(BusinessUnitSqlDto businessUnit); } } \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/ICollaborateurRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/ICollaborateurRepository.cs index 3fef7b3..6eef355 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/ICollaborateurRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/ICollaborateurRepository.cs @@ -4,7 +4,7 @@ namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface { public interface ICollaborateurRepository : IGenericRepository { - CollaborateurSqlDto GetCollaborateurByApsideMail(string apsideMail); + CollaborateurSqlDto? GetCollaborateurByApsideMail(string apsideMail); IList GetCollaborateursByBusinessUnit(int businessUnitId); IList GetCollaborateursByReferrer(int referrerId); } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IGenericRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IGenericRepository.cs index d97622c..13a2f9a 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IGenericRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IGenericRepository.cs @@ -9,10 +9,6 @@ namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface IEnumerable GetAll(); T? GetById(int id); T? Update(T entity); - - - - - + //void GetAll() where T : class, IGenericSqlDto; } } \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IPeriodeEssaiRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IPeriodeEssaiRepository.cs index 88aa3e1..43b4c25 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IPeriodeEssaiRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IPeriodeEssaiRepository.cs @@ -2,12 +2,7 @@ namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface { - public interface IPeriodeEssaiRepository + public interface IPeriodeEssaiRepository : IGenericRepository { - //inutile ! - PeriodeEssaiSqlDto? AddPeriodeEssai(PeriodeEssaiSqlDto newPeriodeEssai); - IList? GetAllPeriodeEssais(); - PeriodeEssaiSqlDto? GetPeriodeEssaiById(PeriodeEssaiSqlDto periodeEssai); - PeriodeEssaiSqlDto UpdatePeriodeEssai(PeriodeEssaiSqlDto periodeEssai); } } \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IProjetRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IProjetRepository.cs index 4378232..2dfb773 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IProjetRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IProjetRepository.cs @@ -2,8 +2,8 @@ namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface { - public interface IProjetRepository + public interface IProjetRepository : IGenericRepository { - IList? GetProjetsByClient(string client); + IList GetProjetsByClient(string client); } } \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IReferencementRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IReferencementRepository.cs index 28926ce..b6f6f75 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IReferencementRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IReferencementRepository.cs @@ -2,12 +2,11 @@ namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface { - public interface IReferencementRepository + public interface IReferencementRepository : IGenericRepository { IList? GetReferrersByCollaborateurId(int collaborateurId); IList? GetReferrersByCollaborateurApsideMail(string apsideMail); //TODO Voir les attentes concernant "le référent ayant le plus suivi depuis une date" - } } \ No newline at end of file -- 2.36.3 From f91c1101cda1c2541bc250cb7822f34b81144f70 Mon Sep 17 00:00:00 2001 From: Clement FERRERE Date: Thu, 2 Dec 2021 09:56:48 +0100 Subject: [PATCH 07/19] =?UTF-8?q?Add=20Generic=20Services=20fonctionnel,?= =?UTF-8?q?=20test=C3=A9=20avec=20collaborateurController?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/CollaborateursController.cs | 17 +++++++++-------- .../GenericsServices.cs | 9 +++++++++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs index b5ccfb9..1c8ca0c 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs @@ -22,6 +22,7 @@ namespace espacecollab.backend.api.Controllers return Ok(CollaborateursServices.GetAll()); } + // GET: api/collaborateurs/{collaborateurId} [HttpGet("{collaborateurId}")] public ActionResult GetCollaborateurById(int collaborateurId) { @@ -32,14 +33,14 @@ namespace espacecollab.backend.api.Controllers return Ok(collaborateur); } - //public CollaborateurApiDto? AddCollaborateur(CollaborateurApiDto collaborateurApi) - //{ - // CollaborateurSqlDto collaborateurSql = collaborateurApi.ToSql(); - // if (collaborateurSql == null) - // return null; - // CollaborateurRepository.Add(collaborateurSql); - // return collaborateurApi; - //} + [HttpPost("add")] + public ActionResult AddCollaborateur(CollaborateurApiDto collaborateurApi) + { + CollaborateurApiDto? addedCollaborateur = CollaborateursServices.Add(collaborateurApi); + if (addedCollaborateur == null) + return BadRequest(); + return Ok(addedCollaborateur); + } //public CollaborateurApiDto? DeleteCollaborateur(CollaborateurApiDto collaborateurApi) //{ diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs index 09778e9..49e7bfb 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs @@ -41,6 +41,15 @@ namespace espacecollab.backend.appservices return MapperToApiDto(entity); } + public To? Add(To entity) + { + T entitySql = MapperToSqlDto(entity); + if (entitySql == null) { return null; } + T? entitySqlValidation = GenericRepository.Add(entitySql); + if (entitySqlValidation == null) { return null; } + return MapperToApiDto(entitySqlValidation); + } + //public To? Update(To apiDto) //{ // T? entity = GenericRepository.Update(apiDto.ToEntity()); -- 2.36.3 From 1191ca7371775d6ab7a0b16ec515faa086e2638f Mon Sep 17 00:00:00 2001 From: Clement FERRERE Date: Thu, 2 Dec 2021 11:40:07 +0100 Subject: [PATCH 08/19] Delete et update generic + collaborateur services --- .../Controllers/CollaborateursController.cs | 32 +++++++------- .../GenericsServices.cs | 43 ++++++++++--------- 2 files changed, 39 insertions(+), 36 deletions(-) diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs index 1c8ca0c..76bd73b 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs @@ -42,23 +42,23 @@ namespace espacecollab.backend.api.Controllers return Ok(addedCollaborateur); } - //public CollaborateurApiDto? DeleteCollaborateur(CollaborateurApiDto collaborateurApi) - //{ - // CollaborateurSqlDto collaborateurSql = collaborateurApi.ToSql(); - // if (collaborateurSql == null) - // return null; - // CollaborateurRepository.Delete(collaborateurSql); - // return collaborateurApi; - //} + [HttpDelete("delete")] + public ActionResult DeleteCollaborateur(CollaborateurApiDto collaborateurApi) + { + CollaborateurApiDto? deletedCollaborateur = CollaborateursServices.Delete(collaborateurApi); + if (deletedCollaborateur == null) + return BadRequest(); + return Ok(deletedCollaborateur); + } - //public CollaborateurApiDto? UpdateCollaborateur(CollaborateurApiDto collaborateurApi) - //{ - // CollaborateurSqlDto collaborateurSql = collaborateurApi.ToSql(); - // if (collaborateurSql == null) - // return null; - // CollaborateurRepository.Update(collaborateurSql); - // return collaborateurApi; - //} + [HttpPut("update")] + public ActionResult UpdateCollaborateur(CollaborateurApiDto collaborateurApi) + { + CollaborateurApiDto? updatedCollaborateur = CollaborateursServices.Update(collaborateurApi); + if (updatedCollaborateur == null) { return BadRequest(); } + return Ok(updatedCollaborateur); + + } //public IEnumerable GetCollaborateursByBusinessUnit(int businessUnitId) //{ diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs index 49e7bfb..f615f15 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs @@ -18,15 +18,6 @@ namespace espacecollab.backend.appservices MapperToSqlDto = mapperToSqlDto; } - //public To? Add(To apiDto) - //{ - // T? entity = GenericRepository.Add(apiDto.ToEntity()); - // if (entity == null) - // return null; - - // return new To().FromEntity(entity); - //} - public IEnumerable GetAll() { return GenericRepository.GetAll().Select(entity => MapperToApiDto(entity)).ToList(); @@ -41,22 +32,34 @@ namespace espacecollab.backend.appservices return MapperToApiDto(entity); } - public To? Add(To entity) + public To? Add(To apiDto) { - T entitySql = MapperToSqlDto(entity); - if (entitySql == null) { return null; } - T? entitySqlValidation = GenericRepository.Add(entitySql); + T sqlDto = MapperToSqlDto(apiDto); + if (sqlDto == null) { return null; } + T? entitySqlValidation = GenericRepository.Add(sqlDto); if (entitySqlValidation == null) { return null; } return MapperToApiDto(entitySqlValidation); } - //public To? Update(To apiDto) - //{ - // T? entity = GenericRepository.Update(apiDto.ToEntity()); - // if (entity == null) - // return null; + public To? Update(To apiDto) + { + T? sqlDto = MapperToSqlDto(apiDto); + if (sqlDto == null) + return null; + T? sqlDtoValidation = GenericRepository.Update(sqlDto); + if (sqlDtoValidation == null) { return null; } + return MapperToApiDto(sqlDtoValidation); + } + public To? Delete(To apiDto) + { + T? sqlDto = MapperToSqlDto(apiDto); + if (sqlDto == null) + return null; + T? sqlDtoValidation = GenericRepository.Delete(sqlDto); + if (sqlDtoValidation == null) { return null; } + return MapperToApiDto(sqlDtoValidation); + } + - // return new To().FromEntity(entity); - //} } } -- 2.36.3 From e5c9c3a85e6187484a17569b07a4778720041f4f Mon Sep 17 00:00:00 2001 From: Clement FERRERE Date: Thu, 2 Dec 2021 15:52:39 +0100 Subject: [PATCH 09/19] Refacto + Generic repos et service complet --- .../Controllers/CollaborateursController.cs | 18 ++-- .../espacecollab.backend.api/Program.cs | 2 +- .../espacecollab.backend.api/Startup.cs | 9 +- .../espacecollab.backend.api.csproj | 1 + .../CollaborateurApiDto.cs | 10 +-- .../EnumStatutApi.cs | 2 +- .../GenericApiDtoBase.cs | 17 ---- .../CollaborateursServices.cs | 4 +- .../GenericsServices.cs | 51 +++++------ .../IGenericsServices.cs | 12 +-- .../FakeCollaborateurRepository.cs | 42 ++++++++++ .../GenericFakeRepository.cs | 47 +++++++++++ ...ecollab.backend.infrastructure.fake.csproj | 14 ++++ .../IAgenceRepository.cs | 2 +- .../IBusinessUnitRepository.cs | 2 +- .../ICollaborateurRepository.cs | 2 +- .../IGenericRepository.cs | 8 +- .../IPeriodeEssaiRepository.cs | 2 +- .../IProjetRepository.cs | 2 +- .../IReferencementRepository.cs | 2 +- ...b.backend.infrastructure.interfaces.csproj | 13 +++ .../AgenceSqlDto.cs | 3 +- .../BusinessUnitSqlDto.cs | 3 +- ...llaborateurAppartientBusinessUnitSqlDto.cs | 2 +- .../CollaborateurEstFonctionSqlDto.cs | 2 +- .../CollaborateurSqlDto.cs | 3 +- .../FonctionSqlDto.cs | 3 +- .../IGenericSqlDto.cs | 8 -- .../Interfaces/IGenericIdSqlDto.cs | 7 ++ .../PeriodeEssaiSqlDto.cs | 5 +- .../ProjetSqlDto.cs | 4 +- .../ProjetUtiliseTechnologieSqlDto.cs | 1 - .../ReferencementSqlDto.cs | 5 +- .../SiteSqlDto.cs | 3 +- .../TechnologieSqlDto.cs | 3 +- .../FakeRepo/FakeCollaborateurRepository.cs | 84 ------------------- .../MainDbContext.cs | 8 +- .../CollaborateurSqlRepository.cs | 8 +- .../GenericSqlRepository.cs} | 23 +++-- ...cecollab.backend.infrastructure.sql.csproj | 1 + .../espacecollab.backend.sln | 37 ++++++-- 41 files changed, 254 insertions(+), 221 deletions(-) delete mode 100644 Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/GenericApiDtoBase.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeCollaborateurRepository.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/GenericFakeRepository.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/espacecollab.backend.infrastructure.fake.csproj rename Collaborateur_Epa_Back/{espacecollab.backend.infrastructure.sql/SqlRepo/Interface => espacecollab.backend.infrastructure.interfaces}/IAgenceRepository.cs (67%) rename Collaborateur_Epa_Back/{espacecollab.backend.infrastructure.sql/SqlRepo/Interface => espacecollab.backend.infrastructure.interfaces}/IBusinessUnitRepository.cs (69%) rename Collaborateur_Epa_Back/{espacecollab.backend.infrastructure.sql/SqlRepo/Interface => espacecollab.backend.infrastructure.interfaces}/ICollaborateurRepository.cs (85%) rename Collaborateur_Epa_Back/{espacecollab.backend.infrastructure.sql/SqlRepo/Interface => espacecollab.backend.infrastructure.interfaces}/IGenericRepository.cs (60%) rename Collaborateur_Epa_Back/{espacecollab.backend.infrastructure.sql/SqlRepo/Interface => espacecollab.backend.infrastructure.interfaces}/IPeriodeEssaiRepository.cs (69%) rename Collaborateur_Epa_Back/{espacecollab.backend.infrastructure.sql/SqlRepo/Interface => espacecollab.backend.infrastructure.interfaces}/IProjetRepository.cs (75%) rename Collaborateur_Epa_Back/{espacecollab.backend.infrastructure.sql/SqlRepo/Interface => espacecollab.backend.infrastructure.interfaces}/IReferencementRepository.cs (86%) create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/espacecollab.backend.infrastructure.interfaces.csproj delete mode 100644 Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/IGenericSqlDto.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/Interfaces/IGenericIdSqlDto.cs delete mode 100644 Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/FakeRepo/FakeCollaborateurRepository.cs rename Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/{SqlRepo => Repository}/CollaborateurSqlRepository.cs (74%) rename Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/{SqlRepo/GenericRepository.cs => Repository/GenericSqlRepository.cs} (60%) diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs index 76bd73b..a249fe4 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs @@ -38,24 +38,28 @@ namespace espacecollab.backend.api.Controllers { CollaborateurApiDto? addedCollaborateur = CollaborateursServices.Add(collaborateurApi); if (addedCollaborateur == null) - return BadRequest(); + return Problem(); + return Ok(addedCollaborateur); } [HttpDelete("delete")] - public ActionResult DeleteCollaborateur(CollaborateurApiDto collaborateurApi) + public ActionResult DeleteCollaborateur(CollaborateurApiDto collaborateurApi) //TODO passé uniquement l'ID { - CollaborateurApiDto? deletedCollaborateur = CollaborateursServices.Delete(collaborateurApi); - if (deletedCollaborateur == null) - return BadRequest(); - return Ok(deletedCollaborateur); + bool isCollaborateurDeleted = CollaborateursServices.Delete(collaborateurApi); + if (!isCollaborateurDeleted) + return Problem(); + + return Ok(); } [HttpPut("update")] public ActionResult UpdateCollaborateur(CollaborateurApiDto collaborateurApi) { CollaborateurApiDto? updatedCollaborateur = CollaborateursServices.Update(collaborateurApi); - if (updatedCollaborateur == null) { return BadRequest(); } + if (updatedCollaborateur == null) + return Problem(); + return Ok(updatedCollaborateur); } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Program.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Program.cs index 5520279..edf6cfb 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/Program.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Program.cs @@ -1,4 +1,4 @@ -namespace Api +namespace espacecollab.backend.api { public static class Program { diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Startup.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Startup.cs index ad7b864..0748fcf 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/Startup.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Startup.cs @@ -1,12 +1,11 @@ using espacecollab.backend.appservices; +using espacecollab.backend.infrastructure.fake; +using espacecollab.backend.infrastructure.interfaces; using espacecollab.backend.infrastructure.sql; -using espacecollab.backend.infrastructure.sql.dtos; -using espacecollab.backend.infrastructure.sql.FakeRepo; using espacecollab.backend.infrastructure.sql.Options; -using espacecollab.backend.infrastructure.sql.SqlRepo; -using espacecollab.backend.infrastructure.sql.SqlRepo.Interface; +using espacecollab.backend.infrastructure.sql.Repository; -namespace Api +namespace espacecollab.backend.api { public class Startup { diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/espacecollab.backend.api.csproj b/Collaborateur_Epa_Back/espacecollab.backend.api/espacecollab.backend.api.csproj index 348965b..eacb4b7 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/espacecollab.backend.api.csproj +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/espacecollab.backend.api.csproj @@ -12,6 +12,7 @@ + diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs index aabbb3a..d974894 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs @@ -1,7 +1,4 @@ -using espacecollab.backend.appservices.dtos.Mappers; -using espacecollab.backend.infrastructure.sql.dtos; - -namespace espacecollab.backend.appservices.dtos +namespace espacecollab.backend.appservices.dtos { public class CollaborateurApiDto { @@ -22,7 +19,6 @@ namespace espacecollab.backend.appservices.dtos public CollaborateurApiDto() { - } public CollaborateurApiDto(int id, string name, string firstName, DateTime birthDate, EnumGenreApi gender, EnumStatutApi status, int childrenNumber, string address, string telephone, string personalMail, string apsideMail, DateTime resignationDate, int referrerId, int businessUnitId) @@ -43,10 +39,6 @@ namespace espacecollab.backend.appservices.dtos BusinessUnitId = businessUnitId; } - public CollaborateurApiDto(CollaborateurSqlDto entity) - { - } - //public override CollaborateurSqlDto ToEntity() //{ // return new CollaborateurSqlDto(Id, Name, FirstName, BirthDate, Gender.ToEnumGenreSql(), Status.ToEnumStatutSql(), ChildrenNumber, diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/EnumStatutApi.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/EnumStatutApi.cs index 35c7d70..0cad417 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/EnumStatutApi.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/EnumStatutApi.cs @@ -7,4 +7,4 @@ ALTERNANT, STAGIAIRE } -} +} \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/GenericApiDtoBase.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/GenericApiDtoBase.cs deleted file mode 100644 index 6f54298..0000000 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/GenericApiDtoBase.cs +++ /dev/null @@ -1,17 +0,0 @@ -using espacecollab.backend.infrastructure.sql.dtos; - -namespace espacecollab.backend.appservices.dtos -{ - public abstract class GenericApiDtoBase where T : class, IGenericSqlDto - where To : GenericApiDtoBase - { - public abstract T ToEntity(); - - public abstract To FromEntity(T entity); - - public GenericApiDtoBase(T entity) - { - FromEntity(entity); - } - } -} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs index a5e442d..9255799 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs @@ -1,9 +1,7 @@ using espacecollab.backend.appservices.dtos; using espacecollab.backend.appservices.dtos.Mappers; +using espacecollab.backend.infrastructure.interfaces; using espacecollab.backend.infrastructure.sql.dtos; -using espacecollab.backend.infrastructure.sql.FakeRepo; -using espacecollab.backend.infrastructure.sql.SqlRepo; -using espacecollab.backend.infrastructure.sql.SqlRepo.Interface; namespace espacecollab.backend.appservices { diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs index f615f15..f4e0bcb 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs @@ -1,29 +1,29 @@ -using espacecollab.backend.infrastructure.sql.dtos; -using espacecollab.backend.infrastructure.sql.SqlRepo.Interface; +using espacecollab.backend.infrastructure.interfaces; +using espacecollab.backend.infrastructure.sql.dtos.Interfaces; namespace espacecollab.backend.appservices { - public abstract class GenericsServices where T : class, IGenericSqlDto - where To : class + public abstract class GenericsServices where T : class, IGenericIdSqlDto + where TO : class { - Func MapperToApiDto { get; } - Func MapperToSqlDto { get; } + Func MapperToApiDto { get; } + Func MapperToSqlDto { get; } private IGenericRepository GenericRepository { get; } - public GenericsServices(IGenericRepository genericRepository, Func mapperToApiDto, Func mapperToSqlDto) + protected GenericsServices(IGenericRepository genericRepository, Func mapperToApiDto, Func mapperToSqlDto) { GenericRepository = genericRepository; MapperToApiDto = mapperToApiDto; MapperToSqlDto = mapperToSqlDto; } - public IEnumerable GetAll() + public IEnumerable GetAll() { return GenericRepository.GetAll().Select(entity => MapperToApiDto(entity)).ToList(); } - public To? GetById(int id) + public TO? GetById(int id) { T? entity = GenericRepository.GetById(id); if (entity == null) @@ -32,34 +32,35 @@ namespace espacecollab.backend.appservices return MapperToApiDto(entity); } - public To? Add(To apiDto) + public TO? Add(TO apiDto) { T sqlDto = MapperToSqlDto(apiDto); - if (sqlDto == null) { return null; } + T? entitySqlValidation = GenericRepository.Add(sqlDto); - if (entitySqlValidation == null) { return null; } + if (entitySqlValidation == null) + return null; + return MapperToApiDto(entitySqlValidation); } - public To? Update(To apiDto) + public TO? Update(TO apiDto) { - T? sqlDto = MapperToSqlDto(apiDto); - if (sqlDto == null) - return null; + //TODO tester l'existence de l'apiDto dans le SQL + + T sqlDto = MapperToSqlDto(apiDto); T? sqlDtoValidation = GenericRepository.Update(sqlDto); - if (sqlDtoValidation == null) { return null; } - return MapperToApiDto(sqlDtoValidation); - } - public To? Delete(To apiDto) - { - T? sqlDto = MapperToSqlDto(apiDto); - if (sqlDto == null) + + if (sqlDtoValidation == null) return null; - T? sqlDtoValidation = GenericRepository.Delete(sqlDto); - if (sqlDtoValidation == null) { return null; } + return MapperToApiDto(sqlDtoValidation); } + public bool Delete(TO apiDto) + { + T sqlDto = MapperToSqlDto(apiDto); + return GenericRepository.Delete(sqlDto); + } } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices/IGenericsServices.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices/IGenericsServices.cs index 443a80c..3ba9193 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices/IGenericsServices.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices/IGenericsServices.cs @@ -1,15 +1,15 @@ -using espacecollab.backend.infrastructure.sql.dtos; +using espacecollab.backend.infrastructure.sql.dtos.Interfaces; namespace espacecollab.backend.appservices { - public interface IGenericsServices where T : class, IGenericSqlDto + public interface IGenericsServices where T : class, IGenericIdSqlDto { - To? Add(T entity); + TO? Add(T entity); - IEnumerable GetAll(); + IEnumerable GetAll(); - To? GetById(int id); + TO? GetById(int id); - To? Update(T entity); + TO? Update(T entity); } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeCollaborateurRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeCollaborateurRepository.cs new file mode 100644 index 0000000..d6aa6bc --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeCollaborateurRepository.cs @@ -0,0 +1,42 @@ +using espacecollab.backend.infrastructure.interfaces; +using espacecollab.backend.infrastructure.sql.dtos; +using espacecollab.backend.infrastructure.sql.dtos.Values; + +namespace espacecollab.backend.infrastructure.fake +{ + public class FakeCollaborateurRepository : GenericFakeRepository, ICollaborateurRepository + { + public FakeCollaborateurRepository() + { + Context = new List + { + new(1, "Dupont", "Jean", new DateTime(1980, 12, 10), + EnumGenreSql.MASCULIN, EnumStatutSql.NONCADRE, 0, "1 rue du Louvre, 63000, Clermont-Ferrand", "0660258644", + "jean.dupont@gmail.com", "jean.dupont@apside-groupe.com", new DateTime(2023, 12, 17), 2, 1), + + new(2, "Michel", "Laura", new DateTime(1985, 08, 12), + EnumGenreSql.FEMININ, EnumStatutSql.NONCADRE, 0, "5 rue du Louvre, 63000, Clermont-Ferrand", "0660258644", + "laura.michel@gmail.com", "laura.michel@apside-groupe.com", new DateTime(2023, 12, 17), 1, 1) + }; + } + + #region méthodes spécifiques à l'interface ICollaborateurRepository + + public IList GetCollaborateursByBusinessUnit(int businessUnitId) + { + return Context.Where(entity => entity.BusinessUnitId == businessUnitId).ToList(); + } + + public IList GetCollaborateursByReferrer(int referrerId) + { + return Context.Where(entity => entity.ReferrerId == referrerId).ToList(); + } + + public CollaborateurSqlDto GetCollaborateurByApsideMail(string apsideMail) + { + return Context.First(entity => entity.ApsideMail == apsideMail); + } + + #endregion + } +} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/GenericFakeRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/GenericFakeRepository.cs new file mode 100644 index 0000000..6117796 --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/GenericFakeRepository.cs @@ -0,0 +1,47 @@ +using espacecollab.backend.infrastructure.interfaces; +using espacecollab.backend.infrastructure.sql.dtos.Interfaces; + +namespace espacecollab.backend.infrastructure.fake +{ + public class GenericFakeRepository : IGenericRepository where T : class, IGenericIdSqlDto + { + protected List Context { get; set; } + + public virtual T? Add(T entity) + { + int lastId = Context.Max(e => e.Id); + entity.Id = lastId + 1; + + Context.Add(entity); + + return entity; + } + + public virtual bool Delete(T entity) + { + return Context.Remove(entity); + } + + public virtual IEnumerable 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); + } + } +} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/espacecollab.backend.infrastructure.fake.csproj b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/espacecollab.backend.infrastructure.fake.csproj new file mode 100644 index 0000000..2b4f8c9 --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/espacecollab.backend.infrastructure.fake.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IAgenceRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IAgenceRepository.cs similarity index 67% rename from Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IAgenceRepository.cs rename to Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IAgenceRepository.cs index 15f90be..1443cdd 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IAgenceRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IAgenceRepository.cs @@ -1,6 +1,6 @@ using espacecollab.backend.infrastructure.sql.dtos; -namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface +namespace espacecollab.backend.infrastructure.interfaces { public interface IAgenceRepository : IGenericRepository { diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IBusinessUnitRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IBusinessUnitRepository.cs similarity index 69% rename from Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IBusinessUnitRepository.cs rename to Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IBusinessUnitRepository.cs index 0aadfc4..42a10fd 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IBusinessUnitRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IBusinessUnitRepository.cs @@ -1,6 +1,6 @@ using espacecollab.backend.infrastructure.sql.dtos; -namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface +namespace espacecollab.backend.infrastructure.interfaces { public interface IBusinessUnitRepository : IGenericRepository { diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/ICollaborateurRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/ICollaborateurRepository.cs similarity index 85% rename from Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/ICollaborateurRepository.cs rename to Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/ICollaborateurRepository.cs index 6eef355..f89aecb 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/ICollaborateurRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/ICollaborateurRepository.cs @@ -1,6 +1,6 @@ using espacecollab.backend.infrastructure.sql.dtos; -namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface +namespace espacecollab.backend.infrastructure.interfaces { public interface ICollaborateurRepository : IGenericRepository { diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IGenericRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IGenericRepository.cs similarity index 60% rename from Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IGenericRepository.cs rename to Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IGenericRepository.cs index 13a2f9a..87b225d 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IGenericRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IGenericRepository.cs @@ -1,11 +1,11 @@ -using espacecollab.backend.infrastructure.sql.dtos; +using espacecollab.backend.infrastructure.sql.dtos.Interfaces; -namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface +namespace espacecollab.backend.infrastructure.interfaces { - public interface IGenericRepository where T : class, IGenericSqlDto + public interface IGenericRepository where T : class, IGenericIdSqlDto { T? Add(T entity); - T? Delete(T entity); + bool Delete(T entity); IEnumerable GetAll(); T? GetById(int id); T? Update(T entity); diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IPeriodeEssaiRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IPeriodeEssaiRepository.cs similarity index 69% rename from Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IPeriodeEssaiRepository.cs rename to Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IPeriodeEssaiRepository.cs index 43b4c25..64e08f1 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IPeriodeEssaiRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IPeriodeEssaiRepository.cs @@ -1,6 +1,6 @@ using espacecollab.backend.infrastructure.sql.dtos; -namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface +namespace espacecollab.backend.infrastructure.interfaces { public interface IPeriodeEssaiRepository : IGenericRepository { diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IProjetRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IProjetRepository.cs similarity index 75% rename from Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IProjetRepository.cs rename to Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IProjetRepository.cs index 2dfb773..8738106 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IProjetRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IProjetRepository.cs @@ -1,6 +1,6 @@ using espacecollab.backend.infrastructure.sql.dtos; -namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface +namespace espacecollab.backend.infrastructure.interfaces { public interface IProjetRepository : IGenericRepository { diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IReferencementRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IReferencementRepository.cs similarity index 86% rename from Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IReferencementRepository.cs rename to Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IReferencementRepository.cs index b6f6f75..0e9c81a 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/Interface/IReferencementRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IReferencementRepository.cs @@ -1,6 +1,6 @@ using espacecollab.backend.infrastructure.sql.dtos; -namespace espacecollab.backend.infrastructure.sql.SqlRepo.Interface +namespace espacecollab.backend.infrastructure.interfaces { public interface IReferencementRepository : IGenericRepository { diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/espacecollab.backend.infrastructure.interfaces.csproj b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/espacecollab.backend.infrastructure.interfaces.csproj new file mode 100644 index 0000000..a18f76e --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/espacecollab.backend.infrastructure.interfaces.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/AgenceSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/AgenceSqlDto.cs index cbe1ccc..780ffaa 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/AgenceSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/AgenceSqlDto.cs @@ -1,8 +1,9 @@ using System.Diagnostics.CodeAnalysis; +using espacecollab.backend.infrastructure.sql.dtos.Interfaces; namespace espacecollab.backend.infrastructure.sql.dtos { - public class AgenceSqlDto : IGenericSqlDto + public class AgenceSqlDto : IGenericIdSqlDto { public int Id { get; set; } public string Name { get; set; } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/BusinessUnitSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/BusinessUnitSqlDto.cs index 4b20d4a..1df0c73 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/BusinessUnitSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/BusinessUnitSqlDto.cs @@ -1,8 +1,9 @@ using System.Diagnostics.CodeAnalysis; +using espacecollab.backend.infrastructure.sql.dtos.Interfaces; namespace espacecollab.backend.infrastructure.sql.dtos { - public class BusinessUnitSqlDto : IGenericSqlDto + public class BusinessUnitSqlDto : IGenericIdSqlDto { public int Id { get; set; } public string Name { get; set; } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurAppartientBusinessUnitSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurAppartientBusinessUnitSqlDto.cs index 8eb40da..7c63750 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurAppartientBusinessUnitSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurAppartientBusinessUnitSqlDto.cs @@ -1,6 +1,6 @@ using System.Diagnostics.CodeAnalysis; -namespace espacecollab.backend.infrastructure.sql.dtos.Associations +namespace espacecollab.backend.infrastructure.sql.dtos { public class CollaborateurAppartientBusinessUnitSqlDto { diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurEstFonctionSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurEstFonctionSqlDto.cs index a3cdd1a..b1129c4 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurEstFonctionSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurEstFonctionSqlDto.cs @@ -1,6 +1,6 @@ using System.Diagnostics.CodeAnalysis; -namespace espacecollab.backend.infrastructure.sql.dtos.Associations +namespace espacecollab.backend.infrastructure.sql.dtos { public class CollaborateurEstFonctionSqlDto { diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurSqlDto.cs index 137764e..e1adf0f 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurSqlDto.cs @@ -1,9 +1,10 @@ using espacecollab.backend.infrastructure.sql.dtos.Values; using System.Diagnostics.CodeAnalysis; +using espacecollab.backend.infrastructure.sql.dtos.Interfaces; namespace espacecollab.backend.infrastructure.sql.dtos { - public class CollaborateurSqlDto : IGenericSqlDto + public class CollaborateurSqlDto : IGenericIdSqlDto { public int Id { get; set; } public string Name { get; set; } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/FonctionSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/FonctionSqlDto.cs index db63bc9..1b1cee1 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/FonctionSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/FonctionSqlDto.cs @@ -1,8 +1,9 @@ using System.Diagnostics.CodeAnalysis; +using espacecollab.backend.infrastructure.sql.dtos.Interfaces; namespace espacecollab.backend.infrastructure.sql.dtos { - public class FonctionSqlDto : IGenericSqlDto + public class FonctionSqlDto : IGenericIdSqlDto { public int Id { get; set; } public string Name { get; set; } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/IGenericSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/IGenericSqlDto.cs deleted file mode 100644 index 93547ed..0000000 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/IGenericSqlDto.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace espacecollab.backend.infrastructure.sql.dtos -{ - public interface IGenericSqlDto - { - public int Id { get; set; } - - } -} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/Interfaces/IGenericIdSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/Interfaces/IGenericIdSqlDto.cs new file mode 100644 index 0000000..ce4c282 --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/Interfaces/IGenericIdSqlDto.cs @@ -0,0 +1,7 @@ +namespace espacecollab.backend.infrastructure.sql.dtos.Interfaces +{ + public interface IGenericIdSqlDto + { + public int Id { get; set; } + } +} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/PeriodeEssaiSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/PeriodeEssaiSqlDto.cs index bcc3d5e..7379399 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/PeriodeEssaiSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/PeriodeEssaiSqlDto.cs @@ -1,9 +1,10 @@ using espacecollab.backend.infrastructure.sql.dtos.Values; using System.Diagnostics.CodeAnalysis; +using espacecollab.backend.infrastructure.sql.dtos.Interfaces; namespace espacecollab.backend.infrastructure.sql.dtos { - public class PeriodeEssaiSqlDto : IGenericSqlDto + public class PeriodeEssaiSqlDto : IGenericIdSqlDto { public int Id { get; set; } public DateTime StartingDate { get; set; } @@ -29,7 +30,5 @@ namespace espacecollab.backend.infrastructure.sql.dtos Issue = issue; CollaborateurId = collaborateurId; } - - } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetSqlDto.cs index 2e93a0c..62df00f 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetSqlDto.cs @@ -1,8 +1,9 @@ using System.Diagnostics.CodeAnalysis; +using espacecollab.backend.infrastructure.sql.dtos.Interfaces; namespace espacecollab.backend.infrastructure.sql.dtos { - public class ProjetSqlDto : IGenericSqlDto + public class ProjetSqlDto : IGenericIdSqlDto { public int Id { get; set; } public string Name { get; set; } @@ -25,6 +26,5 @@ namespace espacecollab.backend.infrastructure.sql.dtos StartingDate = startingDate; EndingDate = endingDate; } - } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetUtiliseTechnologieSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetUtiliseTechnologieSqlDto.cs index b3ef497..bf47a6a 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetUtiliseTechnologieSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetUtiliseTechnologieSqlDto.cs @@ -17,6 +17,5 @@ namespace espacecollab.backend.infrastructure.sql.dtos ProjetId = projetId; TechnologieId = technologieId; } - } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ReferencementSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ReferencementSqlDto.cs index d69163d..8bd980a 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ReferencementSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ReferencementSqlDto.cs @@ -1,8 +1,9 @@ using System.Diagnostics.CodeAnalysis; +using espacecollab.backend.infrastructure.sql.dtos.Interfaces; namespace espacecollab.backend.infrastructure.sql.dtos { - public class ReferencementSqlDto : IGenericSqlDto + public class ReferencementSqlDto : IGenericIdSqlDto { public int Id { get; set; } public DateTime StartingDate { get; set; } @@ -23,7 +24,5 @@ namespace espacecollab.backend.infrastructure.sql.dtos ReferredId = referredId; ReferrerId = referrerId; } - - } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteSqlDto.cs index a59f867..3d6afef 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteSqlDto.cs @@ -1,8 +1,9 @@ using System.Diagnostics.CodeAnalysis; +using espacecollab.backend.infrastructure.sql.dtos.Interfaces; namespace espacecollab.backend.infrastructure.sql.dtos { - public class SiteSqlDto : IGenericSqlDto + public class SiteSqlDto : IGenericIdSqlDto { public int Id { get; set; } public string Name { get; set; } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/TechnologieSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/TechnologieSqlDto.cs index cf38ed6..cf53ce5 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/TechnologieSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/TechnologieSqlDto.cs @@ -1,8 +1,9 @@ using System.Diagnostics.CodeAnalysis; +using espacecollab.backend.infrastructure.sql.dtos.Interfaces; namespace espacecollab.backend.infrastructure.sql.dtos { - public class TechnologieSqlDto : IGenericSqlDto + public class TechnologieSqlDto : IGenericIdSqlDto { public int Id { get; set; } public string Name { get; set; } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/FakeRepo/FakeCollaborateurRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/FakeRepo/FakeCollaborateurRepository.cs deleted file mode 100644 index cc89025..0000000 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/FakeRepo/FakeCollaborateurRepository.cs +++ /dev/null @@ -1,84 +0,0 @@ -using espacecollab.backend.infrastructure.sql.dtos; -using espacecollab.backend.infrastructure.sql.dtos.Values; -using espacecollab.backend.infrastructure.sql.SqlRepo; -using espacecollab.backend.infrastructure.sql.SqlRepo.Interface; - -namespace espacecollab.backend.infrastructure.sql.FakeRepo -{ - public class FakeCollaborateurRepository : GenericRepository, ICollaborateurRepository - { - - private IList Collaborateurs { get; } = new List - { - new CollaborateurSqlDto(1, "Dupont", "Jean", new DateTime(1980, 12, 10), - EnumGenreSql.MASCULIN, EnumStatutSql.NONCADRE, 0, "1 rue du Louvre, 63000, Clermont-Ferrand", "0660258644", - "jean.dupont@gmail.com", "jean.dupont@apside-groupe.com", new DateTime(2023, 12, 17), 2, 1), - - new CollaborateurSqlDto(2, "Michel", "Laura", new DateTime(1985, 08, 12), - EnumGenreSql.FEMININ, EnumStatutSql.NONCADRE, 0, "5 rue du Louvre, 63000, Clermont-Ferrand", "0660258644", - "laura.michel@gmail.com", "laura.michel@apside-groupe.com", new DateTime(2023, 12, 17), 1, 1) - }; - - public FakeCollaborateurRepository() - { - } - - #region redéfinition des méthodes du GenericRepository pour fonctionner avec Fake - - public new CollaborateurSqlDto? GetById(int id) - { - return Collaborateurs.FirstOrDefault(entity => entity.Id == id); - } - - public new CollaborateurSqlDto? Add(CollaborateurSqlDto entity) - { - Collaborateurs.Add(entity); - return entity; - } - - public new CollaborateurSqlDto? Delete(CollaborateurSqlDto entity) - { - Collaborateurs.Remove(entity); - return entity; - } - - public new IEnumerable GetAll() - { - return Collaborateurs; - } - - public new CollaborateurSqlDto? Update(CollaborateurSqlDto collaborateur) - { - CollaborateurSqlDto? oldCollab = Collaborateurs.FirstOrDefault(entity => entity.Id == collaborateur.Id); - if (oldCollab == null) - { - Collaborateurs.Add(collaborateur); - return collaborateur; - } - Collaborateurs.Remove(oldCollab); - Collaborateurs.Add(collaborateur); - return collaborateur; - } - - #endregion - - #region méthodes spécifiques à l'interface ICollaborateurRepository - - public IList GetCollaborateursByBusinessUnit(int businessUnitId) - { - return Collaborateurs.Where(entity => entity.BusinessUnitId == businessUnitId).ToList(); - } - - public IList GetCollaborateursByReferrer(int referrerId) - { - return Collaborateurs.Where(entity => entity.ReferrerId == referrerId).ToList(); - } - - public CollaborateurSqlDto GetCollaborateurByApsideMail(string apsideMail) - { - return Collaborateurs.First(entity => entity.ApsideMail == apsideMail); - } - - #endregion - } -} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/MainDbContext.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/MainDbContext.cs index 25204d2..8642097 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/MainDbContext.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/MainDbContext.cs @@ -1,5 +1,4 @@ -using espacecollab.backend.infrastructure.sql.dtos; -using espacecollab.backend.infrastructure.sql.Options; +using espacecollab.backend.infrastructure.sql.Options; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; namespace espacecollab.backend.infrastructure.sql @@ -8,12 +7,11 @@ namespace espacecollab.backend.infrastructure.sql { private IOptions SqlSettings { get; } - public DbSet? Collaborateur { get; set; } - public MainDbContext(IOptions sqlSettings) { SqlSettings = sqlSettings; } + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlServer(SqlSettings.Value.ConnectionString, builder => @@ -21,7 +19,5 @@ namespace espacecollab.backend.infrastructure.sql builder.EnableRetryOnFailure(5, TimeSpan.FromSeconds(10), null); }); } - - } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/CollaborateurSqlRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/CollaborateurSqlRepository.cs similarity index 74% rename from Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/CollaborateurSqlRepository.cs rename to Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/CollaborateurSqlRepository.cs index 6903f92..192d593 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/CollaborateurSqlRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/CollaborateurSqlRepository.cs @@ -1,9 +1,9 @@ -using espacecollab.backend.infrastructure.sql.dtos; -using espacecollab.backend.infrastructure.sql.SqlRepo.Interface; +using espacecollab.backend.infrastructure.interfaces; +using espacecollab.backend.infrastructure.sql.dtos; -namespace espacecollab.backend.infrastructure.sql.SqlRepo +namespace espacecollab.backend.infrastructure.sql.Repository { - public class CollaborateurSqlRepository : GenericRepository,ICollaborateurRepository + public class CollaborateurSqlRepository : GenericSqlRepository, ICollaborateurRepository { private MainDbContext Context { get; } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/GenericRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/GenericSqlRepository.cs similarity index 60% rename from Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/GenericRepository.cs rename to Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/GenericSqlRepository.cs index 373b35d..bee38ec 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/SqlRepo/GenericRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/GenericSqlRepository.cs @@ -1,18 +1,13 @@ -using espacecollab.backend.infrastructure.sql.dtos; -using espacecollab.backend.infrastructure.sql.SqlRepo.Interface; +using espacecollab.backend.infrastructure.interfaces; +using espacecollab.backend.infrastructure.sql.dtos.Interfaces; -namespace espacecollab.backend.infrastructure.sql.SqlRepo +namespace espacecollab.backend.infrastructure.sql.Repository { - public class GenericRepository : IGenericRepository where T : class, IGenericSqlDto + public class GenericSqlRepository : IGenericRepository where T : class, IGenericIdSqlDto { private MainDbContext Context { get; } - public GenericRepository() - { - - } - - public GenericRepository(MainDbContext context) + public GenericSqlRepository(MainDbContext context) { Context = context; } @@ -22,9 +17,11 @@ namespace espacecollab.backend.infrastructure.sql.SqlRepo return Context.Set().Add(entity) as T; } - public virtual T? Delete(T entity) + public virtual bool Delete(T entity) { - return Context.Set().Remove(entity) as T; + Context.Set().Remove(entity); + + return Context.SaveChanges() == 1; } public virtual IEnumerable GetAll() @@ -41,8 +38,8 @@ namespace espacecollab.backend.infrastructure.sql.SqlRepo { Context.Set().Update(entity); Context.SaveChanges(); + return Context.Set().FirstOrDefault(e => e.Id == entity.Id); } - } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/espacecollab.backend.infrastructure.sql.csproj b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/espacecollab.backend.infrastructure.sql.csproj index d919b65..66c4cb9 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/espacecollab.backend.infrastructure.sql.csproj +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/espacecollab.backend.infrastructure.sql.csproj @@ -17,6 +17,7 @@ + diff --git a/Collaborateur_Epa_Back/espacecollab.backend.sln b/Collaborateur_Epa_Back/espacecollab.backend.sln index 26e96a6..bd0a931 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.sln +++ b/Collaborateur_Epa_Back/espacecollab.backend.sln @@ -3,15 +3,25 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.0.31912.275 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "espacecollab.backend.api", "espacecollab.backend.api\espacecollab.backend.api.csproj", "{A8DEB005-D7E2-4A96-B004-A66BBF12AC54}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "espacecollab.backend.api", "espacecollab.backend.api\espacecollab.backend.api.csproj", "{A8DEB005-D7E2-4A96-B004-A66BBF12AC54}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "espacecollab.backend.appservices", "espacecollab.backend.appservices\espacecollab.backend.appservices.csproj", "{70F1BE1C-87C1-4CCF-A7E8-2A36F3F16D9E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "espacecollab.backend.appservices", "espacecollab.backend.appservices\espacecollab.backend.appservices.csproj", "{70F1BE1C-87C1-4CCF-A7E8-2A36F3F16D9E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "espacecollab.backend.appservices.dtos", "espacecollab.backend.appservices.dtos\espacecollab.backend.appservices.dtos.csproj", "{CB0CB8FC-0E53-4205-AAA3-4176211C922B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "espacecollab.backend.appservices.dtos", "espacecollab.backend.appservices.dtos\espacecollab.backend.appservices.dtos.csproj", "{CB0CB8FC-0E53-4205-AAA3-4176211C922B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "espacecollab.backend.infrastructure.sql", "espacecollab.backend.infrastructure.sql\espacecollab.backend.infrastructure.sql.csproj", "{590FF09D-0DF3-4881-8D86-E4FDAAC75FDC}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "espacecollab.backend.infrastructure.sql", "espacecollab.backend.infrastructure.sql\espacecollab.backend.infrastructure.sql.csproj", "{590FF09D-0DF3-4881-8D86-E4FDAAC75FDC}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "espacecollab.backend.infrastructure.sql.dtos", "espacecollab.backend.infrastructure.sql.dtos\espacecollab.backend.infrastructure.sql.dtos.csproj", "{26C08CE0-E6E5-4E03-8AEA-233F93218A3B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "espacecollab.backend.infrastructure.sql.dtos", "espacecollab.backend.infrastructure.sql.dtos\espacecollab.backend.infrastructure.sql.dtos.csproj", "{26C08CE0-E6E5-4E03-8AEA-233F93218A3B}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "1 Host", "1 Host", "{19237F76-6CA9-47DF-87F8-8027C78070C9}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "2 ApplicationsServices", "2 ApplicationsServices", "{CE5199B3-E423-46C1-B141-18C46473D964}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "4 Infrastructure", "4 Infrastructure", "{E29F5CA9-ABAF-4437-8633-49FF27110E6D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "espacecollab.backend.infrastructure.interfaces", "espacecollab.backend.infrastructure.interfaces\espacecollab.backend.infrastructure.interfaces.csproj", "{3E9E4801-D686-4581-8051-E0E1B036AC70}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "espacecollab.backend.infrastructure.fake", "espacecollab.backend.infrastructure.fake\espacecollab.backend.infrastructure.fake.csproj", "{48253B9B-9B42-48CF-A95F-358171BABA74}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -39,10 +49,27 @@ Global {26C08CE0-E6E5-4E03-8AEA-233F93218A3B}.Debug|Any CPU.Build.0 = Debug|Any CPU {26C08CE0-E6E5-4E03-8AEA-233F93218A3B}.Release|Any CPU.ActiveCfg = Release|Any CPU {26C08CE0-E6E5-4E03-8AEA-233F93218A3B}.Release|Any CPU.Build.0 = Release|Any CPU + {3E9E4801-D686-4581-8051-E0E1B036AC70}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3E9E4801-D686-4581-8051-E0E1B036AC70}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3E9E4801-D686-4581-8051-E0E1B036AC70}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3E9E4801-D686-4581-8051-E0E1B036AC70}.Release|Any CPU.Build.0 = Release|Any CPU + {48253B9B-9B42-48CF-A95F-358171BABA74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {48253B9B-9B42-48CF-A95F-358171BABA74}.Debug|Any CPU.Build.0 = Debug|Any CPU + {48253B9B-9B42-48CF-A95F-358171BABA74}.Release|Any CPU.ActiveCfg = Release|Any CPU + {48253B9B-9B42-48CF-A95F-358171BABA74}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {A8DEB005-D7E2-4A96-B004-A66BBF12AC54} = {19237F76-6CA9-47DF-87F8-8027C78070C9} + {70F1BE1C-87C1-4CCF-A7E8-2A36F3F16D9E} = {CE5199B3-E423-46C1-B141-18C46473D964} + {CB0CB8FC-0E53-4205-AAA3-4176211C922B} = {CE5199B3-E423-46C1-B141-18C46473D964} + {590FF09D-0DF3-4881-8D86-E4FDAAC75FDC} = {E29F5CA9-ABAF-4437-8633-49FF27110E6D} + {26C08CE0-E6E5-4E03-8AEA-233F93218A3B} = {E29F5CA9-ABAF-4437-8633-49FF27110E6D} + {3E9E4801-D686-4581-8051-E0E1B036AC70} = {E29F5CA9-ABAF-4437-8633-49FF27110E6D} + {48253B9B-9B42-48CF-A95F-358171BABA74} = {E29F5CA9-ABAF-4437-8633-49FF27110E6D} + EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {0A56A44C-135E-4CE4-834B-8DFDF69DC415} EndGlobalSection -- 2.36.3 From 09ff256ca7bd81c578432a7552b44fdd20e30090 Mon Sep 17 00:00:00 2001 From: Clement FERRERE Date: Fri, 3 Dec 2021 10:50:08 +0100 Subject: [PATCH 10/19] =?UTF-8?q?G=C3=A9n=C3=A9ricit=C3=A9=20compl=C3=A8te?= =?UTF-8?q?,=20TODO=20fixed.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/CollaborateursController.cs | 4 +-- .../CollaborateurApiDto.cs | 6 +++-- .../Interfaces/IGenericIdSqlDto.cs | 7 +++++ .../CollaborateursServices.cs | 27 ------------------- .../GenericsServices.cs | 16 +++++------ .../GenericFakeRepository.cs | 4 ++- .../IGenericRepository.cs | 2 +- .../IReferencementRepository.cs | 2 -- .../Repository/GenericSqlRepository.cs | 4 ++- 9 files changed, 28 insertions(+), 44 deletions(-) create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Interfaces/IGenericIdSqlDto.cs diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs index a249fe4..0d8b17e 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs @@ -44,9 +44,9 @@ namespace espacecollab.backend.api.Controllers } [HttpDelete("delete")] - public ActionResult DeleteCollaborateur(CollaborateurApiDto collaborateurApi) //TODO passé uniquement l'ID + public ActionResult DeleteCollaborateur(int collaborateurId) { - bool isCollaborateurDeleted = CollaborateursServices.Delete(collaborateurApi); + bool isCollaborateurDeleted = CollaborateursServices.Delete(collaborateurId); if (!isCollaborateurDeleted) return Problem(); diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs index d974894..a181292 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs @@ -1,6 +1,8 @@ -namespace espacecollab.backend.appservices.dtos +using espacecollab.backend.infrastructure.sql.dtos.Interfaces; + +namespace espacecollab.backend.appservices.dtos { - public class CollaborateurApiDto + public class CollaborateurApiDto : IGenericIdApiDto { public int Id { get; set; } public string Name { get; set; } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Interfaces/IGenericIdSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Interfaces/IGenericIdSqlDto.cs new file mode 100644 index 0000000..f15ba9c --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Interfaces/IGenericIdSqlDto.cs @@ -0,0 +1,7 @@ +namespace espacecollab.backend.infrastructure.sql.dtos.Interfaces +{ + public interface IGenericIdApiDto + { + public int Id { get; set; } + } +} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs index 9255799..b0b1940 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs @@ -15,33 +15,6 @@ namespace espacecollab.backend.appservices CollaborateurRepository = collaborateurRepository; } - public CollaborateurApiDto? AddCollaborateur(CollaborateurApiDto collaborateurApi) - { - CollaborateurSqlDto collaborateurSql = collaborateurApi.ToSql(); - if (collaborateurSql == null) - return null; - CollaborateurRepository.Add(collaborateurSql); - return collaborateurApi; - } - - public CollaborateurApiDto? DeleteCollaborateur(CollaborateurApiDto collaborateurApi) - { - CollaborateurSqlDto collaborateurSql = collaborateurApi.ToSql(); - if (collaborateurSql == null) - return null; - CollaborateurRepository.Delete(collaborateurSql); - return collaborateurApi; - } - - public CollaborateurApiDto? UpdateCollaborateur(CollaborateurApiDto collaborateurApi) - { - CollaborateurSqlDto collaborateurSql = collaborateurApi.ToSql(); - if (collaborateurSql == null) - return null; - CollaborateurRepository.Update(collaborateurSql); - return collaborateurApi; - } - public IEnumerable GetCollaborateursByBusinessUnit(int businessUnitId) { return CollaborateurRepository.GetCollaborateursByBusinessUnit(businessUnitId).Select(collaborateurSql => collaborateurSql.ToApi()); diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs index f4e0bcb..af77b56 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs @@ -4,7 +4,7 @@ using espacecollab.backend.infrastructure.sql.dtos.Interfaces; namespace espacecollab.backend.appservices { public abstract class GenericsServices where T : class, IGenericIdSqlDto - where TO : class + where TO : class, IGenericIdApiDto { Func MapperToApiDto { get; } Func MapperToSqlDto { get; } @@ -44,9 +44,11 @@ namespace espacecollab.backend.appservices } public TO? Update(TO apiDto) - { - //TODO tester l'existence de l'apiDto dans le SQL - + { + if(GetById(apiDto.Id)==null) + { + return null; + } T sqlDto = MapperToSqlDto(apiDto); T? sqlDtoValidation = GenericRepository.Update(sqlDto); @@ -56,11 +58,9 @@ namespace espacecollab.backend.appservices return MapperToApiDto(sqlDtoValidation); } - public bool Delete(TO apiDto) + public bool Delete(int apiDtoId) { - T sqlDto = MapperToSqlDto(apiDto); - - return GenericRepository.Delete(sqlDto); + return GenericRepository.Delete(apiDtoId); } } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/GenericFakeRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/GenericFakeRepository.cs index 6117796..f155d9c 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/GenericFakeRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/GenericFakeRepository.cs @@ -17,8 +17,10 @@ namespace espacecollab.backend.infrastructure.fake return entity; } - public virtual bool Delete(T entity) + public virtual bool Delete(int entityId) { + T? entity = GetById(entityId); + if (entity == null) return false; return Context.Remove(entity); } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IGenericRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IGenericRepository.cs index 87b225d..a071958 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IGenericRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IGenericRepository.cs @@ -5,7 +5,7 @@ namespace espacecollab.backend.infrastructure.interfaces public interface IGenericRepository where T : class, IGenericIdSqlDto { T? Add(T entity); - bool Delete(T entity); + bool Delete(int entityId); IEnumerable GetAll(); T? GetById(int id); T? Update(T entity); diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IReferencementRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IReferencementRepository.cs index 0e9c81a..4bb453e 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IReferencementRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IReferencementRepository.cs @@ -6,7 +6,5 @@ namespace espacecollab.backend.infrastructure.interfaces { IList? GetReferrersByCollaborateurId(int collaborateurId); IList? GetReferrersByCollaborateurApsideMail(string apsideMail); - - //TODO Voir les attentes concernant "le référent ayant le plus suivi depuis une date" } } \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/GenericSqlRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/GenericSqlRepository.cs index bee38ec..20291de 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/GenericSqlRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/GenericSqlRepository.cs @@ -17,8 +17,10 @@ namespace espacecollab.backend.infrastructure.sql.Repository return Context.Set().Add(entity) as T; } - public virtual bool Delete(T entity) + public virtual bool Delete(int entityId) { + T? entity = GetById(entityId); + if (entity == null) return false; Context.Set().Remove(entity); return Context.SaveChanges() == 1; -- 2.36.3 From 34a5c4783f321f997368422d33e54fa0ee0528af Mon Sep 17 00:00:00 2001 From: Clement FERRERE Date: Fri, 3 Dec 2021 11:42:46 +0100 Subject: [PATCH 11/19] Collaborateurs complets --- .../Controllers/CollaborateursController.cs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs index 0d8b17e..a8baacc 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs @@ -64,6 +64,36 @@ namespace espacecollab.backend.api.Controllers } + [HttpGet("businessunit/{businessId}")] + public ActionResult> GetCollaborateursByBusinessUnit(int businessId) + { + IEnumerable collaborateurs = CollaborateursServices.GetCollaborateursByBusinessUnit(businessId); + if (collaborateurs == null) + return NotFound(); + + return Ok(collaborateurs); + } + + [HttpGet("referrer/{referrerId}")] + public ActionResult> GetCollaborateursByReferrer(int referrerId) + { + IEnumerable collaborateurs = CollaborateursServices.GetCollaborateursByReferrer(referrerId); + if (collaborateurs == null) + return NotFound(); + + return Ok(collaborateurs); + } + + [HttpGet("apsidemail/{apsideMail}")] + public ActionResult GetCollaborateurByApsideMail(string apsideMail) + { + CollaborateurApiDto? collaborateur = CollaborateursServices.GetCollaborateurByApsideMail(apsideMail); + if (collaborateur == null) + return NotFound(); + + return Ok(collaborateur); + } + //public IEnumerable GetCollaborateursByBusinessUnit(int businessUnitId) //{ // return CollaborateurRepository.GetCollaborateursByBusinessUnit(businessUnitId).Select(collaborateurSql => collaborateurSql.ToApi()); -- 2.36.3 From 4c7647ac27915010dc179ba7137154de3c39dfbf Mon Sep 17 00:00:00 2001 From: Clement FERRERE Date: Fri, 3 Dec 2021 14:19:25 +0100 Subject: [PATCH 12/19] Code Cleanup --- .../Controllers/CollaborateursController.cs | 25 +++---------------- .../CollaborateursServices.cs | 4 +-- .../GenericsServices.cs | 6 ++--- .../BusinessUnitSqlDto.cs | 2 +- ...llaborateurAppartientBusinessUnitSqlDto.cs | 2 +- .../CollaborateurEstFonctionSqlDto.cs | 4 +-- .../FonctionSqlDto.cs | 2 +- .../SiteDeveloppeProjetSqlDto.cs | 4 +-- .../SiteSqlDto.cs | 4 +-- .../Repository/CollaborateurSqlRepository.cs | 2 +- .../Repository/GenericSqlRepository.cs | 2 +- 11 files changed, 19 insertions(+), 38 deletions(-) diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs index a8baacc..1dc4238 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs @@ -6,7 +6,7 @@ namespace espacecollab.backend.api.Controllers { [Route("api/[controller]")] [ApiController] - public class CollaborateursController : ControllerBase + public class CollaborateursController : ControllerBase { private CollaborateursServices CollaborateursServices { get; } @@ -15,14 +15,12 @@ namespace espacecollab.backend.api.Controllers CollaborateursServices = collaborateursServices; } - // GET: api/collaborateurs [HttpGet] public ActionResult> GetCollaborateurs() { - return Ok(CollaborateursServices.GetAll()); + return Ok(CollaborateursServices.GetAll()); } - // GET: api/collaborateurs/{collaborateurId} [HttpGet("{collaborateurId}")] public ActionResult GetCollaborateurById(int collaborateurId) { @@ -61,7 +59,7 @@ namespace espacecollab.backend.api.Controllers return Problem(); return Ok(updatedCollaborateur); - + } [HttpGet("businessunit/{businessId}")] @@ -93,22 +91,5 @@ namespace espacecollab.backend.api.Controllers return Ok(collaborateur); } - - //public IEnumerable GetCollaborateursByBusinessUnit(int businessUnitId) - //{ - // return CollaborateurRepository.GetCollaborateursByBusinessUnit(businessUnitId).Select(collaborateurSql => collaborateurSql.ToApi()); - //} - - //public IEnumerable GetCollaborateursByReferrer(int referrerId) - //{ - // return CollaborateurRepository.GetCollaborateursByReferrer(referrerId).Select(collaborateurSql => collaborateurSql.ToApi()); - //} - - //public CollaborateurApiDto? GetCollaborateurByApsideMail(string apsideMail) - //{ - // if (string.IsNullOrEmpty(apsideMail)) - // return null; - // return CollaborateurRepository.GetCollaborateurByApsideMail(apsideMail).ToApi(); - //} } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs index b0b1940..388ff77 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs @@ -10,7 +10,7 @@ namespace espacecollab.backend.appservices private ICollaborateurRepository CollaborateurRepository { get; } public CollaborateursServices(ICollaborateurRepository collaborateurRepository) - :base(collaborateurRepository, CollaborateurMapper.ToApi, CollaborateurMapper.ToSql) + : base(collaborateurRepository, CollaborateurMapper.ToApi, CollaborateurMapper.ToSql) { CollaborateurRepository = collaborateurRepository; } @@ -30,7 +30,7 @@ namespace espacecollab.backend.appservices if (string.IsNullOrEmpty(apsideMail)) return null; - return CollaborateurRepository.GetCollaborateurByApsideMail(apsideMail)?.ToApi(); + return CollaborateurRepository.GetCollaborateurByApsideMail(apsideMail)?.ToApi(); } } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs index af77b56..77429af 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs @@ -44,15 +44,15 @@ namespace espacecollab.backend.appservices } public TO? Update(TO apiDto) - { - if(GetById(apiDto.Id)==null) + { + if (GetById(apiDto.Id) == null) { return null; } T sqlDto = MapperToSqlDto(apiDto); T? sqlDtoValidation = GenericRepository.Update(sqlDto); - if (sqlDtoValidation == null) + if (sqlDtoValidation == null) return null; return MapperToApiDto(sqlDtoValidation); diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/BusinessUnitSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/BusinessUnitSqlDto.cs index 1df0c73..1a8029f 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/BusinessUnitSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/BusinessUnitSqlDto.cs @@ -22,6 +22,6 @@ namespace espacecollab.backend.infrastructure.sql.dtos AgenceId = agenceId; } - + } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurAppartientBusinessUnitSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurAppartientBusinessUnitSqlDto.cs index 7c63750..03fc86a 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurAppartientBusinessUnitSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurAppartientBusinessUnitSqlDto.cs @@ -19,6 +19,6 @@ namespace espacecollab.backend.infrastructure.sql.dtos BusinessUnitId = businessUnitId; } - + } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurEstFonctionSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurEstFonctionSqlDto.cs index b1129c4..cf7fcde 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurEstFonctionSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurEstFonctionSqlDto.cs @@ -2,7 +2,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos { - public class CollaborateurEstFonctionSqlDto + public class CollaborateurEstFonctionSqlDto { public int CollaborateurId { get; set; } public int FonctionId { get; set; } @@ -18,6 +18,6 @@ namespace espacecollab.backend.infrastructure.sql.dtos FonctionId = fonctionId; } - + } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/FonctionSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/FonctionSqlDto.cs index 1b1cee1..0d67697 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/FonctionSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/FonctionSqlDto.cs @@ -19,6 +19,6 @@ namespace espacecollab.backend.infrastructure.sql.dtos Name = name; } - + } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteDeveloppeProjetSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteDeveloppeProjetSqlDto.cs index 44e4828..8cc3395 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteDeveloppeProjetSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteDeveloppeProjetSqlDto.cs @@ -18,7 +18,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos ProjetId = projetId; } - - + + } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteSqlDto.cs index 3d6afef..216ca5d 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteSqlDto.cs @@ -23,7 +23,7 @@ namespace espacecollab.backend.infrastructure.sql.dtos BusinessUnitId = businessUnitId; } - - + + } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/CollaborateurSqlRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/CollaborateurSqlRepository.cs index 192d593..6519c36 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/CollaborateurSqlRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/CollaborateurSqlRepository.cs @@ -4,7 +4,7 @@ using espacecollab.backend.infrastructure.sql.dtos; namespace espacecollab.backend.infrastructure.sql.Repository { public class CollaborateurSqlRepository : GenericSqlRepository, ICollaborateurRepository - { + { private MainDbContext Context { get; } public CollaborateurSqlRepository(MainDbContext context) : base(context) diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/GenericSqlRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/GenericSqlRepository.cs index 20291de..7b68b69 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/GenericSqlRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/GenericSqlRepository.cs @@ -12,7 +12,7 @@ namespace espacecollab.backend.infrastructure.sql.Repository Context = context; } - public virtual T? Add(T entity) + public virtual T? Add(T entity) { return Context.Set().Add(entity) as T; } -- 2.36.3 From 62f0c210a907a3996d5c7d67849d8dccf83b3728 Mon Sep 17 00:00:00 2001 From: Clement FERRERE Date: Mon, 6 Dec 2021 09:23:12 +0100 Subject: [PATCH 13/19] Refacto + "Valider les types directement dans l'URL (quand possible)" --- .../Controllers/CollaborateursController.cs | 10 +++---- .../espacecollab.backend.api/Register.cs | 26 +++++++++++++++++++ .../espacecollab.backend.api/Startup.cs | 24 +++-------------- .../CollaborateurApiDto.cs | 13 +--------- .../Interfaces/IGenericIdSqlDto.cs | 2 +- .../IGenericsServices.cs | 15 +++++++++++ ...llab.backend.appservices.interfaces.csproj | 14 ++++++++++ .../GenericsServices.cs | 12 +++++---- .../IGenericsServices.cs | 15 ----------- .../espacecollab.backend.appservices.csproj | 1 + .../espacecollab.backend.sln | 11 ++++++-- 11 files changed, 83 insertions(+), 60 deletions(-) create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.api/Register.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.appservices.interfaces/IGenericsServices.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.appservices.interfaces/espacecollab.backend.appservices.interfaces.csproj delete mode 100644 Collaborateur_Epa_Back/espacecollab.backend.appservices/IGenericsServices.cs diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs index 1dc4238..d6c7e49 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs @@ -21,7 +21,7 @@ namespace espacecollab.backend.api.Controllers return Ok(CollaborateursServices.GetAll()); } - [HttpGet("{collaborateurId}")] + [HttpGet("{collaborateurId:int:min(1)}")] public ActionResult GetCollaborateurById(int collaborateurId) { CollaborateurApiDto? collaborateur = CollaborateursServices.GetById(collaborateurId); @@ -41,7 +41,7 @@ namespace espacecollab.backend.api.Controllers return Ok(addedCollaborateur); } - [HttpDelete("delete")] + [HttpDelete("delete/{collaborateurId:int:min(1)}")] public ActionResult DeleteCollaborateur(int collaborateurId) { bool isCollaborateurDeleted = CollaborateursServices.Delete(collaborateurId); @@ -62,7 +62,7 @@ namespace espacecollab.backend.api.Controllers } - [HttpGet("businessunit/{businessId}")] + [HttpGet("businessunit/{businessId:int:min(1)}")] public ActionResult> GetCollaborateursByBusinessUnit(int businessId) { IEnumerable collaborateurs = CollaborateursServices.GetCollaborateursByBusinessUnit(businessId); @@ -72,7 +72,7 @@ namespace espacecollab.backend.api.Controllers return Ok(collaborateurs); } - [HttpGet("referrer/{referrerId}")] + [HttpGet("referrer/{referrerId:int:min(1)}")] public ActionResult> GetCollaborateursByReferrer(int referrerId) { IEnumerable collaborateurs = CollaborateursServices.GetCollaborateursByReferrer(referrerId); @@ -82,7 +82,7 @@ namespace espacecollab.backend.api.Controllers return Ok(collaborateurs); } - [HttpGet("apsidemail/{apsideMail}")] + [HttpGet("apsidemail/{apsideMail:minlength(1):regex(^\\S.*)}")] public ActionResult GetCollaborateurByApsideMail(string apsideMail) { CollaborateurApiDto? collaborateur = CollaborateursServices.GetCollaborateurByApsideMail(apsideMail); diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Register.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Register.cs new file mode 100644 index 0000000..3357194 --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Register.cs @@ -0,0 +1,26 @@ +using espacecollab.backend.appservices; +using espacecollab.backend.infrastructure.fake; +using espacecollab.backend.infrastructure.interfaces; +using espacecollab.backend.infrastructure.sql; +using espacecollab.backend.infrastructure.sql.Options; +using espacecollab.backend.infrastructure.sql.Repository; + +namespace espacecollab.backend.api; + +internal static class Register +{ + public static void InjectDependencies(IServiceCollection services, SqlOption contextOptions) + { + services.AddScoped(); + + if (contextOptions.LoadFake) + { + services.AddScoped(); + } + else + { + services.AddScoped(); + services.AddScoped(); + } + } +} \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Startup.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Startup.cs index 0748fcf..1231a37 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/Startup.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Startup.cs @@ -1,9 +1,4 @@ -using espacecollab.backend.appservices; -using espacecollab.backend.infrastructure.fake; -using espacecollab.backend.infrastructure.interfaces; -using espacecollab.backend.infrastructure.sql; -using espacecollab.backend.infrastructure.sql.Options; -using espacecollab.backend.infrastructure.sql.Repository; +using espacecollab.backend.infrastructure.sql.Options; namespace espacecollab.backend.api { @@ -20,26 +15,15 @@ namespace espacecollab.backend.api { IConfigurationSection sqlSection = Configuration.GetSection(SqlOption.Key); services.Configure(sqlSection); - SqlOption contextOptions = sqlSection.Get(); + SqlOption sqlOptions = sqlSection.Get(); services.AddControllers(); services.AddRouting(options => options.LowercaseUrls = true); - if (contextOptions.LoadFake) - { - services.AddScoped(); - } - else - { - services.AddScoped(); - } - - services.AddScoped(); - - services.AddScoped(); - services.AddEndpointsApiExplorer(); services.AddSwaggerGen(); + + Register.InjectDependencies(services, sqlOptions); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs index a181292..7b5ac19 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs @@ -1,4 +1,4 @@ -using espacecollab.backend.infrastructure.sql.dtos.Interfaces; +using espacecollab.backend.appservices.dtos.Interfaces; namespace espacecollab.backend.appservices.dtos { @@ -40,16 +40,5 @@ namespace espacecollab.backend.appservices.dtos ReferrerId = referrerId; BusinessUnitId = businessUnitId; } - - //public override CollaborateurSqlDto ToEntity() - //{ - // return new CollaborateurSqlDto(Id, Name, FirstName, BirthDate, Gender.ToEnumGenreSql(), Status.ToEnumStatutSql(), ChildrenNumber, - // Address, Telephone, PersonalMail, ApsideMail, ResignationDate, ReferrerId, BusinessUnitId); - //} - - //public override CollaborateurApiDto FromEntity(CollaborateurSqlDto entity) - //{ - // return this; - //} } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Interfaces/IGenericIdSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Interfaces/IGenericIdSqlDto.cs index f15ba9c..af0c0ec 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Interfaces/IGenericIdSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Interfaces/IGenericIdSqlDto.cs @@ -1,4 +1,4 @@ -namespace espacecollab.backend.infrastructure.sql.dtos.Interfaces +namespace espacecollab.backend.appservices.dtos.Interfaces { public interface IGenericIdApiDto { diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.interfaces/IGenericsServices.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.interfaces/IGenericsServices.cs new file mode 100644 index 0000000..83402d2 --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.interfaces/IGenericsServices.cs @@ -0,0 +1,15 @@ +using espacecollab.backend.appservices.dtos.Interfaces; + +namespace espacecollab.backend.appservices.interfaces +{ + public interface IGenericsServices where T : class, IGenericIdApiDto + { + T? Add(T apiDto); + + IEnumerable GetAll(); + + T? GetById(int id); + + T? Update(T apiDto); + } +} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.interfaces/espacecollab.backend.appservices.interfaces.csproj b/Collaborateur_Epa_Back/espacecollab.backend.appservices.interfaces/espacecollab.backend.appservices.interfaces.csproj new file mode 100644 index 0000000..9e0ac7e --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.interfaces/espacecollab.backend.appservices.interfaces.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs index 77429af..76715d8 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs @@ -1,13 +1,15 @@ -using espacecollab.backend.infrastructure.interfaces; +using espacecollab.backend.appservices.dtos.Interfaces; +using espacecollab.backend.appservices.interfaces; +using espacecollab.backend.infrastructure.interfaces; using espacecollab.backend.infrastructure.sql.dtos.Interfaces; namespace espacecollab.backend.appservices { - public abstract class GenericsServices where T : class, IGenericIdSqlDto - where TO : class, IGenericIdApiDto + public abstract class GenericsServices : IGenericsServices where T : class, IGenericIdSqlDto + where TO : class, IGenericIdApiDto { - Func MapperToApiDto { get; } - Func MapperToSqlDto { get; } + private Func MapperToApiDto { get; } + private Func MapperToSqlDto { get; } private IGenericRepository GenericRepository { get; } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices/IGenericsServices.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices/IGenericsServices.cs deleted file mode 100644 index 3ba9193..0000000 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices/IGenericsServices.cs +++ /dev/null @@ -1,15 +0,0 @@ -using espacecollab.backend.infrastructure.sql.dtos.Interfaces; - -namespace espacecollab.backend.appservices -{ - public interface IGenericsServices where T : class, IGenericIdSqlDto - { - TO? Add(T entity); - - IEnumerable GetAll(); - - TO? GetById(int id); - - TO? Update(T entity); - } -} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices/espacecollab.backend.appservices.csproj b/Collaborateur_Epa_Back/espacecollab.backend.appservices/espacecollab.backend.appservices.csproj index 69235a9..098754d 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices/espacecollab.backend.appservices.csproj +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices/espacecollab.backend.appservices.csproj @@ -8,6 +8,7 @@ + diff --git a/Collaborateur_Epa_Back/espacecollab.backend.sln b/Collaborateur_Epa_Back/espacecollab.backend.sln index bd0a931..0569be5 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.sln +++ b/Collaborateur_Epa_Back/espacecollab.backend.sln @@ -19,9 +19,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "2 ApplicationsServices", "2 EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "4 Infrastructure", "4 Infrastructure", "{E29F5CA9-ABAF-4437-8633-49FF27110E6D}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "espacecollab.backend.infrastructure.interfaces", "espacecollab.backend.infrastructure.interfaces\espacecollab.backend.infrastructure.interfaces.csproj", "{3E9E4801-D686-4581-8051-E0E1B036AC70}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "espacecollab.backend.infrastructure.interfaces", "espacecollab.backend.infrastructure.interfaces\espacecollab.backend.infrastructure.interfaces.csproj", "{3E9E4801-D686-4581-8051-E0E1B036AC70}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "espacecollab.backend.infrastructure.fake", "espacecollab.backend.infrastructure.fake\espacecollab.backend.infrastructure.fake.csproj", "{48253B9B-9B42-48CF-A95F-358171BABA74}" +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}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -57,6 +59,10 @@ Global {48253B9B-9B42-48CF-A95F-358171BABA74}.Debug|Any CPU.Build.0 = Debug|Any CPU {48253B9B-9B42-48CF-A95F-358171BABA74}.Release|Any CPU.ActiveCfg = Release|Any CPU {48253B9B-9B42-48CF-A95F-358171BABA74}.Release|Any CPU.Build.0 = Release|Any CPU + {7872657E-46E2-44A1-AFA6-0D3B9E45084A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {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 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -69,6 +75,7 @@ Global {26C08CE0-E6E5-4E03-8AEA-233F93218A3B} = {E29F5CA9-ABAF-4437-8633-49FF27110E6D} {3E9E4801-D686-4581-8051-E0E1B036AC70} = {E29F5CA9-ABAF-4437-8633-49FF27110E6D} {48253B9B-9B42-48CF-A95F-358171BABA74} = {E29F5CA9-ABAF-4437-8633-49FF27110E6D} + {7872657E-46E2-44A1-AFA6-0D3B9E45084A} = {CE5199B3-E423-46C1-B141-18C46473D964} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {0A56A44C-135E-4CE4-834B-8DFDF69DC415} -- 2.36.3 From ecacc497ebee417b5cd176300aae485257a4ac73 Mon Sep 17 00:00:00 2001 From: Clement FERRERE Date: Mon, 6 Dec 2021 09:52:52 +0100 Subject: [PATCH 14/19] Fix "Route UPDATE/DELETE avec id" --- .../Controllers/CollaborateursController.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs index d6c7e49..0a343a6 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs @@ -51,9 +51,11 @@ namespace espacecollab.backend.api.Controllers return Ok(); } - [HttpPut("update")] - public ActionResult UpdateCollaborateur(CollaborateurApiDto collaborateurApi) + [HttpPut("update/{collaborateurId:int:min(1)}")] + public ActionResult UpdateCollaborateur(int collaborateurId, CollaborateurApiDto collaborateurApi) { + if (collaborateurApi.Id != collaborateurId) + return Unauthorized(); CollaborateurApiDto? updatedCollaborateur = CollaborateursServices.Update(collaborateurApi); if (updatedCollaborateur == null) return Problem(); -- 2.36.3 From 01c4ea71206fd941dfd8456f88507a8408f52560 Mon Sep 17 00:00:00 2001 From: Clement FERRERE Date: Mon, 6 Dec 2021 10:15:23 +0100 Subject: [PATCH 15/19] Fix "Nommage des routes CRUD" --- .../Controllers/CollaborateursController.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs index 0a343a6..f74c0cd 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs @@ -41,7 +41,7 @@ namespace espacecollab.backend.api.Controllers return Ok(addedCollaborateur); } - [HttpDelete("delete/{collaborateurId:int:min(1)}")] + [HttpDelete("{collaborateurId:int:min(1)}")] public ActionResult DeleteCollaborateur(int collaborateurId) { bool isCollaborateurDeleted = CollaborateursServices.Delete(collaborateurId); @@ -64,10 +64,10 @@ namespace espacecollab.backend.api.Controllers } - [HttpGet("businessunit/{businessId:int:min(1)}")] - public ActionResult> GetCollaborateursByBusinessUnit(int businessId) + [HttpGet("businessunit/{businessUnitId:int:min(1)}")] + public ActionResult> GetCollaborateursByBusinessUnit(int businessUnitId) { - IEnumerable collaborateurs = CollaborateursServices.GetCollaborateursByBusinessUnit(businessId); + IEnumerable collaborateurs = CollaborateursServices.GetCollaborateursByBusinessUnit(businessUnitId); if (collaborateurs == null) return NotFound(); -- 2.36.3 From f495bd019e300426aa254efded472ef40bfc7b0f Mon Sep 17 00:00:00 2001 From: Clement FERRERE Date: Mon, 6 Dec 2021 10:28:35 +0100 Subject: [PATCH 16/19] Fix "Utilisation des type unsigned dans la couche API + AppSvc" --- .../Controllers/CollaborateursController.cs | 10 +++++----- .../CollaborateurApiDto.cs | 4 ++-- .../Interfaces/IGenericIdSqlDto.cs | 2 +- .../Mappers/CollaborateurApiDtoMapper.cs | 4 ++-- .../IGenericsServices.cs | 2 +- .../CollaborateursServices.cs | 8 ++++---- .../GenericsServices.cs | 10 +++++----- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs index f74c0cd..df9e5ac 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs @@ -22,7 +22,7 @@ namespace espacecollab.backend.api.Controllers } [HttpGet("{collaborateurId:int:min(1)}")] - public ActionResult GetCollaborateurById(int collaborateurId) + public ActionResult GetCollaborateurById(uint collaborateurId) { CollaborateurApiDto? collaborateur = CollaborateursServices.GetById(collaborateurId); if (collaborateur == null) @@ -42,7 +42,7 @@ namespace espacecollab.backend.api.Controllers } [HttpDelete("{collaborateurId:int:min(1)}")] - public ActionResult DeleteCollaborateur(int collaborateurId) + public ActionResult DeleteCollaborateur(uint collaborateurId) { bool isCollaborateurDeleted = CollaborateursServices.Delete(collaborateurId); if (!isCollaborateurDeleted) @@ -52,7 +52,7 @@ namespace espacecollab.backend.api.Controllers } [HttpPut("update/{collaborateurId:int:min(1)}")] - public ActionResult UpdateCollaborateur(int collaborateurId, CollaborateurApiDto collaborateurApi) + public ActionResult UpdateCollaborateur(uint collaborateurId, CollaborateurApiDto collaborateurApi) { if (collaborateurApi.Id != collaborateurId) return Unauthorized(); @@ -65,7 +65,7 @@ namespace espacecollab.backend.api.Controllers } [HttpGet("businessunit/{businessUnitId:int:min(1)}")] - public ActionResult> GetCollaborateursByBusinessUnit(int businessUnitId) + public ActionResult> GetCollaborateursByBusinessUnit(uint businessUnitId) { IEnumerable collaborateurs = CollaborateursServices.GetCollaborateursByBusinessUnit(businessUnitId); if (collaborateurs == null) @@ -75,7 +75,7 @@ namespace espacecollab.backend.api.Controllers } [HttpGet("referrer/{referrerId:int:min(1)}")] - public ActionResult> GetCollaborateursByReferrer(int referrerId) + public ActionResult> GetCollaborateursByReferrer(uint referrerId) { IEnumerable collaborateurs = CollaborateursServices.GetCollaborateursByReferrer(referrerId); if (collaborateurs == null) diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs index 7b5ac19..af539c5 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs @@ -4,7 +4,7 @@ namespace espacecollab.backend.appservices.dtos { public class CollaborateurApiDto : IGenericIdApiDto { - public int Id { get; set; } + public uint Id { get; set; } public string Name { get; set; } public string FirstName { get; set; } public DateTime BirthDate { get; set; } @@ -23,7 +23,7 @@ namespace espacecollab.backend.appservices.dtos { } - public CollaborateurApiDto(int id, string name, string firstName, DateTime birthDate, EnumGenreApi gender, EnumStatutApi status, int childrenNumber, string address, string telephone, string personalMail, string apsideMail, DateTime resignationDate, int referrerId, int businessUnitId) + public CollaborateurApiDto(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) { Id = id; Name = name; diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Interfaces/IGenericIdSqlDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Interfaces/IGenericIdSqlDto.cs index af0c0ec..167465b 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Interfaces/IGenericIdSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Interfaces/IGenericIdSqlDto.cs @@ -2,6 +2,6 @@ { public interface IGenericIdApiDto { - public int Id { get; set; } + public uint Id { get; set; } } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/CollaborateurApiDtoMapper.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/CollaborateurApiDtoMapper.cs index 7a72dab..b604f55 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/CollaborateurApiDtoMapper.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/CollaborateurApiDtoMapper.cs @@ -6,7 +6,7 @@ namespace espacecollab.backend.appservices.dtos.Mappers { public static CollaborateurApiDto ToApi(this CollaborateurSqlDto collaborateurSql) { - return new CollaborateurApiDto(collaborateurSql.Id, collaborateurSql.Name, collaborateurSql.FirstName, + 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); @@ -14,7 +14,7 @@ namespace espacecollab.backend.appservices.dtos.Mappers public static CollaborateurSqlDto ToSql(this CollaborateurApiDto collaborateurApi) { - return new CollaborateurSqlDto(collaborateurApi.Id, collaborateurApi.Name, collaborateurApi.FirstName, + 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); diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.interfaces/IGenericsServices.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.interfaces/IGenericsServices.cs index 83402d2..5f14f76 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices.interfaces/IGenericsServices.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.interfaces/IGenericsServices.cs @@ -8,7 +8,7 @@ namespace espacecollab.backend.appservices.interfaces IEnumerable GetAll(); - T? GetById(int id); + T? GetById(uint id); T? Update(T apiDto); } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs index 388ff77..f9039c7 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursServices.cs @@ -15,14 +15,14 @@ namespace espacecollab.backend.appservices CollaborateurRepository = collaborateurRepository; } - public IEnumerable GetCollaborateursByBusinessUnit(int businessUnitId) + public IEnumerable GetCollaborateursByBusinessUnit(uint businessUnitId) { - return CollaborateurRepository.GetCollaborateursByBusinessUnit(businessUnitId).Select(collaborateurSql => collaborateurSql.ToApi()); + return CollaborateurRepository.GetCollaborateursByBusinessUnit((int)businessUnitId).Select(collaborateurSql => collaborateurSql.ToApi()); } - public IEnumerable GetCollaborateursByReferrer(int referrerId) + public IEnumerable GetCollaborateursByReferrer(uint referrerId) { - return CollaborateurRepository.GetCollaborateursByReferrer(referrerId).Select(collaborateurSql => collaborateurSql.ToApi()); + return CollaborateurRepository.GetCollaborateursByReferrer((int)referrerId).Select(collaborateurSql => collaborateurSql.ToApi()); } public CollaborateurApiDto? GetCollaborateurByApsideMail(string apsideMail) diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs index 76715d8..d1c65c2 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs @@ -10,7 +10,7 @@ namespace espacecollab.backend.appservices { private Func MapperToApiDto { get; } private Func MapperToSqlDto { get; } - + private IGenericRepository GenericRepository { get; } protected GenericsServices(IGenericRepository genericRepository, Func mapperToApiDto, Func mapperToSqlDto) @@ -25,9 +25,9 @@ namespace espacecollab.backend.appservices return GenericRepository.GetAll().Select(entity => MapperToApiDto(entity)).ToList(); } - public TO? GetById(int id) + public TO? GetById(uint id) { - T? entity = GenericRepository.GetById(id); + T? entity = GenericRepository.GetById((int)id); if (entity == null) return null; @@ -60,9 +60,9 @@ namespace espacecollab.backend.appservices return MapperToApiDto(sqlDtoValidation); } - public bool Delete(int apiDtoId) + public bool Delete(uint apiDtoId) { - return GenericRepository.Delete(apiDtoId); + return GenericRepository.Delete((int)apiDtoId); } } } -- 2.36.3 From a3f46a13481b3b705c2b49a17e677945db97aa25 Mon Sep 17 00:00:00 2001 From: Clement FERRERE Date: Mon, 6 Dec 2021 11:56:04 +0100 Subject: [PATCH 17/19] =?UTF-8?q?Fix=20Register=20en=20Singleton=20pour=20?= =?UTF-8?q?conservation=20des=20Fake=20Data=20pendant=20l'ex=C3=A9cution?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Collaborateur_Epa_Back/espacecollab.backend.api/Register.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Register.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Register.cs index 3357194..b12e464 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/Register.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Register.cs @@ -15,7 +15,7 @@ internal static class Register if (contextOptions.LoadFake) { - services.AddScoped(); + services.AddSingleton(); } else { -- 2.36.3 From ad64563055e95e7b8b4e79f61ace7ccd1ad43b3d Mon Sep 17 00:00:00 2001 From: Clement FERRERE Date: Mon, 6 Dec 2021 14:32:09 +0100 Subject: [PATCH 18/19] Fix Nommage des routes add et update --- .../Controllers/CollaborateursController.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs index df9e5ac..27cdc9e 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs @@ -31,7 +31,7 @@ namespace espacecollab.backend.api.Controllers return Ok(collaborateur); } - [HttpPost("add")] + [HttpPost] public ActionResult AddCollaborateur(CollaborateurApiDto collaborateurApi) { CollaborateurApiDto? addedCollaborateur = CollaborateursServices.Add(collaborateurApi); @@ -51,7 +51,7 @@ namespace espacecollab.backend.api.Controllers return Ok(); } - [HttpPut("update/{collaborateurId:int:min(1)}")] + [HttpPut("{collaborateurId:int:min(1)}")] public ActionResult UpdateCollaborateur(uint collaborateurId, CollaborateurApiDto collaborateurApi) { if (collaborateurApi.Id != collaborateurId) -- 2.36.3 From b7064ccc448063bca0a20623adc511b7f78ce8e2 Mon Sep 17 00:00:00 2001 From: Clement FERRERE Date: Tue, 7 Dec 2021 12:13:41 +0100 Subject: [PATCH 19/19] =?UTF-8?q?Ajout=20des=20agences=20avec=20g=C3=A9n?= =?UTF-8?q?=C3=A9ricit=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/AgenceController.cs | 12 ++++ .../Controllers/BaseController.cs | 68 +++++++++++++++++++ .../Controllers/CollaborateursController.cs | 61 ++--------------- .../espacecollab.backend.api/Register.cs | 3 + .../AgenceApiDto.cs | 8 +++ .../CollaborateurApiDto.cs | 40 +---------- .../Mappers/AgenceMapper.cs | 15 ++++ .../IGenericsServices.cs | 2 + .../AgenceService.cs | 14 ++++ .../FakeAgenceRepository.cs | 18 +++++ .../Repository/AgenceSqlRepository.cs | 11 +++ .../Repository/CollaborateurSqlRepository.cs | 2 - .../Repository/GenericSqlRepository.cs | 2 +- 13 files changed, 161 insertions(+), 95 deletions(-) create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/AgenceController.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/BaseController.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/AgenceApiDto.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/AgenceMapper.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.appservices/AgenceService.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeAgenceRepository.cs create mode 100644 Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/AgenceSqlRepository.cs diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/AgenceController.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/AgenceController.cs new file mode 100644 index 0000000..dc96075 --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/AgenceController.cs @@ -0,0 +1,12 @@ +using espacecollab.backend.appservices; +using espacecollab.backend.appservices.dtos; + +namespace espacecollab.backend.api.Controllers +{ + public class AgenceController : BaseController + { + public AgenceController(AgenceService agenceService) : base(agenceService) + { + } + } +} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/BaseController.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/BaseController.cs new file mode 100644 index 0000000..0ec5b6c --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/BaseController.cs @@ -0,0 +1,68 @@ +using espacecollab.backend.appservices.dtos.Interfaces; +using espacecollab.backend.appservices.interfaces; +using Microsoft.AspNetCore.Mvc; + +namespace espacecollab.backend.api.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public abstract class BaseController : Controller where TO : class, IGenericIdApiDto + { + protected IGenericsServices Services { get; } + + protected BaseController(IGenericsServices services) + { + Services = services; + } + + [HttpGet] + public ActionResult> GetAll() + { + return Ok(Services.GetAll()); + } + + [HttpGet("{id:int:min(1)}")] + public ActionResult GetById(uint id) + { + TO? apiDtos = Services.GetById(id); + if (apiDtos == null) + return NotFound(); + + return Ok(apiDtos); + } + + [HttpPost] + public ActionResult Add(TO apiDto) + { + TO? addedApiDto = Services.Add(apiDto); + if (addedApiDto == null) + return Problem(); + + return Ok(addedApiDto); + } + + [HttpDelete("{id:int:min(1)}")] + public ActionResult Delete(uint id) + { + bool isDeleted = Services.Delete(id); + if (!isDeleted) + return Problem(); + + return Ok(); + } + + [HttpPut("{collaborateurId:int:min(1)}")] + public ActionResult Update(uint id, TO apiDto) + { + if (apiDto.Id != id) + return Unauthorized(); + + TO? updatedApiDto = Services.Update(apiDto); + if (updatedApiDto == null) + return Problem(); + + return Ok(updatedApiDto); + + } + } +} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs index 27cdc9e..d23bff9 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/CollaborateursController.cs @@ -4,71 +4,22 @@ using Microsoft.AspNetCore.Mvc; namespace espacecollab.backend.api.Controllers { - [Route("api/[controller]")] - [ApiController] - public class CollaborateursController : ControllerBase + //[Route("api/[controller]")] + //[ApiController] + public class CollaborateursController : BaseController { private CollaborateursServices CollaborateursServices { get; } - public CollaborateursController(CollaborateursServices collaborateursServices) + public CollaborateursController(CollaborateursServices collaborateursServices) : base(collaborateursServices) { CollaborateursServices = collaborateursServices; } - [HttpGet] - public ActionResult> GetCollaborateurs() - { - return Ok(CollaborateursServices.GetAll()); - } - - [HttpGet("{collaborateurId:int:min(1)}")] - public ActionResult GetCollaborateurById(uint collaborateurId) - { - CollaborateurApiDto? collaborateur = CollaborateursServices.GetById(collaborateurId); - if (collaborateur == null) - return NotFound(); - - return Ok(collaborateur); - } - - [HttpPost] - public ActionResult AddCollaborateur(CollaborateurApiDto collaborateurApi) - { - CollaborateurApiDto? addedCollaborateur = CollaborateursServices.Add(collaborateurApi); - if (addedCollaborateur == null) - return Problem(); - - return Ok(addedCollaborateur); - } - - [HttpDelete("{collaborateurId:int:min(1)}")] - public ActionResult DeleteCollaborateur(uint collaborateurId) - { - bool isCollaborateurDeleted = CollaborateursServices.Delete(collaborateurId); - if (!isCollaborateurDeleted) - return Problem(); - - return Ok(); - } - - [HttpPut("{collaborateurId:int:min(1)}")] - public ActionResult UpdateCollaborateur(uint collaborateurId, CollaborateurApiDto collaborateurApi) - { - if (collaborateurApi.Id != collaborateurId) - return Unauthorized(); - CollaborateurApiDto? updatedCollaborateur = CollaborateursServices.Update(collaborateurApi); - if (updatedCollaborateur == null) - return Problem(); - - return Ok(updatedCollaborateur); - - } - [HttpGet("businessunit/{businessUnitId:int:min(1)}")] public ActionResult> GetCollaborateursByBusinessUnit(uint businessUnitId) { IEnumerable collaborateurs = CollaborateursServices.GetCollaborateursByBusinessUnit(businessUnitId); - if (collaborateurs == null) + if (!collaborateurs.Any()) return NotFound(); return Ok(collaborateurs); @@ -78,7 +29,7 @@ namespace espacecollab.backend.api.Controllers public ActionResult> GetCollaborateursByReferrer(uint referrerId) { IEnumerable collaborateurs = CollaborateursServices.GetCollaborateursByReferrer(referrerId); - if (collaborateurs == null) + if (!collaborateurs.Any()) return NotFound(); return Ok(collaborateurs); diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Register.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Register.cs index b12e464..603e14a 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/Register.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Register.cs @@ -12,15 +12,18 @@ internal static class Register public static void InjectDependencies(IServiceCollection services, SqlOption contextOptions) { services.AddScoped(); + services.AddScoped(); if (contextOptions.LoadFake) { services.AddSingleton(); + services.AddSingleton(); } else { services.AddScoped(); services.AddScoped(); + services.AddScoped(); } } } \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/AgenceApiDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/AgenceApiDto.cs new file mode 100644 index 0000000..630761b --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/AgenceApiDto.cs @@ -0,0 +1,8 @@ +using espacecollab.backend.appservices.dtos.Interfaces; + +namespace espacecollab.backend.appservices.dtos; + +public record AgenceApiDto(uint Id, string Name) : IGenericIdApiDto +{ + public uint Id { get; set; } = Id; +} \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs index af539c5..ceb58c5 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs @@ -2,43 +2,9 @@ namespace espacecollab.backend.appservices.dtos { - public class CollaborateurApiDto : IGenericIdApiDto + 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 uint 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 int ReferrerId { get; set; } - public int BusinessUnitId { get; set; } - - public CollaborateurApiDto() - { - } - - public 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) - { - 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; - } + public uint Id { get; set; } = Id; } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/AgenceMapper.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/AgenceMapper.cs new file mode 100644 index 0000000..bb078b5 --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/AgenceMapper.cs @@ -0,0 +1,15 @@ +using espacecollab.backend.infrastructure.sql.dtos; + +namespace espacecollab.backend.appservices.dtos.Mappers; + +public static class AgenceMapper +{ + public static AgenceApiDto ToApi(this AgenceSqlDto agenceSqlDto) + { + return new AgenceApiDto((uint)agenceSqlDto.Id, agenceSqlDto.Name); + } + public static AgenceSqlDto ToSql(this AgenceApiDto agenceApiDto) + { + return new AgenceSqlDto((int)agenceApiDto.Id, agenceApiDto.Name); + } +} \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.interfaces/IGenericsServices.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.interfaces/IGenericsServices.cs index 5f14f76..eeeddae 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices.interfaces/IGenericsServices.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.interfaces/IGenericsServices.cs @@ -11,5 +11,7 @@ namespace espacecollab.backend.appservices.interfaces T? GetById(uint id); T? Update(T apiDto); + + bool Delete(uint apiDtoId); } } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices/AgenceService.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices/AgenceService.cs new file mode 100644 index 0000000..fb7bfef --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices/AgenceService.cs @@ -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 AgenceService : GenericsServices +{ + public AgenceService(IAgenceRepository agenceRepository) + :base(agenceRepository, AgenceMapper.ToApi, AgenceMapper.ToSql) + { + } +} \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeAgenceRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeAgenceRepository.cs new file mode 100644 index 0000000..5cdd3ad --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeAgenceRepository.cs @@ -0,0 +1,18 @@ +using espacecollab.backend.infrastructure.interfaces; +using espacecollab.backend.infrastructure.sql.dtos; + +namespace espacecollab.backend.infrastructure.fake +{ + public class FakeAgenceRepository : GenericFakeRepository, IAgenceRepository + { + public FakeAgenceRepository() + { + Context = new List + { + new(1, "Tours"), + + new(2, "Clermont-Ferrand") + }; + } + } +} diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/AgenceSqlRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/AgenceSqlRepository.cs new file mode 100644 index 0000000..a5f569b --- /dev/null +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/AgenceSqlRepository.cs @@ -0,0 +1,11 @@ +using espacecollab.backend.infrastructure.interfaces; +using espacecollab.backend.infrastructure.sql.dtos; + +namespace espacecollab.backend.infrastructure.sql.Repository; + +public class AgenceSqlRepository : GenericSqlRepository, IAgenceRepository +{ + public AgenceSqlRepository(MainDbContext context) : base(context) + { + } +} \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/CollaborateurSqlRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/CollaborateurSqlRepository.cs index 6519c36..f24bf5f 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/CollaborateurSqlRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/CollaborateurSqlRepository.cs @@ -5,8 +5,6 @@ namespace espacecollab.backend.infrastructure.sql.Repository { public class CollaborateurSqlRepository : GenericSqlRepository, ICollaborateurRepository { - private MainDbContext Context { get; } - public CollaborateurSqlRepository(MainDbContext context) : base(context) { Context = context; diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/GenericSqlRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/GenericSqlRepository.cs index 7b68b69..f1986bf 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/GenericSqlRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/GenericSqlRepository.cs @@ -5,7 +5,7 @@ namespace espacecollab.backend.infrastructure.sql.Repository { public class GenericSqlRepository : IGenericRepository where T : class, IGenericIdSqlDto { - private MainDbContext Context { get; } + protected MainDbContext Context { get; set; } public GenericSqlRepository(MainDbContext context) { -- 2.36.3