diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/BusinessUnitController.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/BusinessUnitController.cs index 9606c8b..5df82b5 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/BusinessUnitController.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Controllers/BusinessUnitController.cs @@ -1,4 +1,5 @@ using espacecollab.backend.appservices; +using espacecollab.backend.appservices.dtos; using espacecollab.backend.infrastructure.sql.dtos; namespace espacecollab.backend.api.Controllers diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Program.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Program.cs index edf6cfb..22a4ebb 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/Program.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Program.cs @@ -1,17 +1,16 @@ -namespace espacecollab.backend.api +namespace espacecollab.backend.api; + +public static class Program { - public static class Program + public static void Main(string[] args) { - public static void Main(string[] args) - { - CreateHostBuilder(args).Build().Run(); - } - - public static IHostBuilder CreateHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup(); - }); + CreateHostBuilder(args).Build().Run(); } -} + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); +} \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Register.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Register.cs index 18fcdae..22b1458 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/Register.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Register.cs @@ -12,7 +12,7 @@ internal static class Register public static void InjectDependencies(IServiceCollection services, SqlOption contextOptions) { services.AddCors(); - services.AddScoped(); + services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); diff --git a/Collaborateur_Epa_Back/espacecollab.backend.api/Startup.cs b/Collaborateur_Epa_Back/espacecollab.backend.api/Startup.cs index e7ee256..8c6f9da 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.api/Startup.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.api/Startup.cs @@ -1,58 +1,57 @@ using espacecollab.backend.infrastructure.sql.Options; using System.Text.Json.Serialization; -namespace espacecollab.backend.api +namespace espacecollab.backend.api; + +public class Startup { - public class Startup + public IConfiguration Configuration { get; } + public Startup(IConfiguration configuration) { - public IConfiguration Configuration { get; } - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } + Configuration = configuration; + } - // This method gets called by the runtime. Use this method to add services to the container. - public void ConfigureServices(IServiceCollection services) + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + IConfigurationSection sqlSection = Configuration.GetSection(SqlOption.Key); + services.Configure(sqlSection); + SqlOption sqlOptions = sqlSection.Get(); + + services.AddControllers().AddJsonOptions(opt => { - IConfigurationSection sqlSection = Configuration.GetSection(SqlOption.Key); - services.Configure(sqlSection); - SqlOption sqlOptions = sqlSection.Get(); + opt.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); + }); ; + services.AddRouting(options => options.LowercaseUrls = true); - services.AddControllers().AddJsonOptions(opt => - { - opt.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); - }); ; - services.AddRouting(options => options.LowercaseUrls = true); + services.AddEndpointsApiExplorer(); + services.AddSwaggerGen(); - services.AddEndpointsApiExplorer(); - services.AddSwaggerGen(); + Register.InjectDependencies(services, sqlOptions); + } - Register.InjectDependencies(services, sqlOptions); + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); } + app.UseCors( + options => options.WithOrigins("http://localhost:4200").AllowAnyMethod().AllowAnyHeader() + ); + app.UseSwagger(); + app.UseSwaggerUI(); + + app.UseHttpsRedirection(); - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - } - app.UseCors( - options => options.WithOrigins("http://localhost:4200").AllowAnyMethod().AllowAnyHeader() - ); - app.UseSwagger(); - app.UseSwaggerUI(); - - app.UseHttpsRedirection(); - - app.UseRouting(); - - app.UseAuthorization(); - - app.UseEndpoints(endpoints => - { - endpoints.MapControllers(); - }); - } + endpoints.MapControllers(); + }); } -} +} \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/BusinessUnitApiDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/BusinessUnitApiDto.cs index ef1077c..64a1ddf 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/BusinessUnitApiDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/BusinessUnitApiDto.cs @@ -1,9 +1,8 @@ using espacecollab.backend.appservices.dtos.Interfaces; -namespace espacecollab.backend.infrastructure.sql.dtos +namespace espacecollab.backend.appservices.dtos; + +public record BusinessUnitApiDto(uint Id, string Name, uint AgenceId) : IGenericIdApiDto { - public record BusinessUnitApiDto(uint Id, string Name, uint AgenceId) : IGenericIdApiDto - { - public uint Id { get; set; } = Id; - } -} + public uint Id { get; set; } = Id; +} \ 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 edcbc22..2b80730 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/CollaborateurApiDto.cs @@ -1,11 +1,10 @@ using espacecollab.backend.appservices.dtos.Interfaces; using espacecollab.backend.appservices.dtos.Values; -namespace espacecollab.backend.appservices.dtos +namespace espacecollab.backend.appservices.dtos; + +public record CollaborateurApiDto(uint Id, string Name, string FirstName, string BirthDate, EnumGenreApi Gender, EnumStatutApi Status, int ChildrenNumber, string Address, + string Telephone, string PersonalMail, string ApsideMail, string ResignationDate, int ReferrerId, int BusinessUnitId) : IGenericIdApiDto { - public record CollaborateurApiDto(uint Id, string Name, string FirstName, string BirthDate, EnumGenreApi Gender, EnumStatutApi Status, int ChildrenNumber, string Address, - string Telephone, string PersonalMail, string ApsideMail, string ResignationDate, int ReferrerId, int BusinessUnitId) : IGenericIdApiDto - { - public uint Id { get; set; } = Id; - } -} + public uint Id { get; set; } = Id; +} \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Interfaces/IGenericIdApiDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Interfaces/IGenericIdApiDto.cs index 167465b..c07391f 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Interfaces/IGenericIdApiDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Interfaces/IGenericIdApiDto.cs @@ -1,7 +1,6 @@ -namespace espacecollab.backend.appservices.dtos.Interfaces +namespace espacecollab.backend.appservices.dtos.Interfaces; + +public interface IGenericIdApiDto { - public interface IGenericIdApiDto - { - public uint Id { get; set; } - } -} + public uint Id { get; set; } +} \ No newline at end of file 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 11ab39e..e80870a 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/CollaborateurApiDtoMapper.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/CollaborateurApiDtoMapper.cs @@ -1,24 +1,23 @@ using espacecollab.backend.infrastructure.sql.dtos; using System.Globalization; -namespace espacecollab.backend.appservices.dtos.Mappers +namespace espacecollab.backend.appservices.dtos.Mappers; + +public static class CollaborateurMapper { - public static class CollaborateurMapper + public static CollaborateurApiDto ToApi(this CollaborateurSqlDto collaborateurSql) { - public static CollaborateurApiDto ToApi(this CollaborateurSqlDto collaborateurSql) - { - return new CollaborateurApiDto((uint)collaborateurSql.Id, collaborateurSql.Name, collaborateurSql.FirstName, - collaborateurSql.BirthDate.ToShortDateString(), collaborateurSql.Gender.ToEnumGenreApi(), collaborateurSql.Status.ToEnumStatutApi(), collaborateurSql.ChildrenNumber, - collaborateurSql.Address, collaborateurSql.Telephone, collaborateurSql.PersonalMail, collaborateurSql.ApsideMail, - collaborateurSql.ResignationDate.ToShortDateString(), collaborateurSql.ReferrerId, collaborateurSql.BusinessUnitId); - } + return new CollaborateurApiDto((uint)collaborateurSql.Id, collaborateurSql.Name, collaborateurSql.FirstName, + collaborateurSql.BirthDate.ToShortDateString(), collaborateurSql.Gender.ToEnumGenreApi(), collaborateurSql.Status.ToEnumStatutApi(), collaborateurSql.ChildrenNumber, + collaborateurSql.Address, collaborateurSql.Telephone, collaborateurSql.PersonalMail, collaborateurSql.ApsideMail, + collaborateurSql.ResignationDate.ToShortDateString(), collaborateurSql.ReferrerId, collaborateurSql.BusinessUnitId); + } - public static CollaborateurSqlDto ToSql(this CollaborateurApiDto collaborateurApi) - { - return new CollaborateurSqlDto((int)collaborateurApi.Id, collaborateurApi.Name, collaborateurApi.FirstName, - DateTime.ParseExact(collaborateurApi.BirthDate,"dd/MM/yyyy",CultureInfo.InvariantCulture), collaborateurApi.Gender.ToEnumGenreSql(), collaborateurApi.Status.ToEnumStatutSql(), collaborateurApi.ChildrenNumber, - collaborateurApi.Address, collaborateurApi.Telephone, collaborateurApi.PersonalMail, collaborateurApi.ApsideMail, - DateTime.ParseExact(collaborateurApi.ResignationDate, "dd/MM/yyyy", CultureInfo.InvariantCulture), collaborateurApi.ReferrerId, collaborateurApi.BusinessUnitId); - } + public static CollaborateurSqlDto ToSql(this CollaborateurApiDto collaborateurApi) + { + return new CollaborateurSqlDto((int)collaborateurApi.Id, collaborateurApi.Name, collaborateurApi.FirstName, + DateTime.ParseExact(collaborateurApi.BirthDate, "dd/MM/yyyy", CultureInfo.InvariantCulture), collaborateurApi.Gender.ToEnumGenreSql(), collaborateurApi.Status.ToEnumStatutSql(), collaborateurApi.ChildrenNumber, + collaborateurApi.Address, collaborateurApi.Telephone, collaborateurApi.PersonalMail, collaborateurApi.ApsideMail, + DateTime.ParseExact(collaborateurApi.ResignationDate, "dd/MM/yyyy", CultureInfo.InvariantCulture), collaborateurApi.ReferrerId, collaborateurApi.BusinessUnitId); } -} +} \ No newline at end of file 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 9ec076a..1dc7c58 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/EnumGenreMapper.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/EnumGenreMapper.cs @@ -1,30 +1,29 @@ using espacecollab.backend.appservices.dtos.Values; using espacecollab.backend.infrastructure.sql.dtos.Values; -namespace espacecollab.backend.appservices.dtos.Mappers +namespace espacecollab.backend.appservices.dtos.Mappers; + +public static class EnumGenreMapper { - public static class EnumGenreMapper + public static EnumGenreApi ToEnumGenreApi(this EnumGenreSql enumGenreSql) { - public static EnumGenreApi ToEnumGenreApi(this EnumGenreSql enumGenreSql) + return enumGenreSql switch { - return enumGenreSql switch - { - EnumGenreSql.MASCULIN => EnumGenreApi.MASCULIN, - EnumGenreSql.FEMININ => EnumGenreApi.FEMININ, - EnumGenreSql.AUTRE => EnumGenreApi.AUTRE, - _ => EnumGenreApi.AUTRE, - }; - } + EnumGenreSql.MASCULIN => EnumGenreApi.MASCULIN, + EnumGenreSql.FEMININ => EnumGenreApi.FEMININ, + EnumGenreSql.AUTRE => EnumGenreApi.AUTRE, + _ => EnumGenreApi.AUTRE, + }; + } - public static EnumGenreSql ToEnumGenreSql(this EnumGenreApi enumGenreApi) + public static EnumGenreSql ToEnumGenreSql(this EnumGenreApi enumGenreApi) + { + return enumGenreApi switch { - return enumGenreApi switch - { - EnumGenreApi.MASCULIN => EnumGenreSql.MASCULIN, - EnumGenreApi.FEMININ => EnumGenreSql.FEMININ, - EnumGenreApi.AUTRE => EnumGenreSql.AUTRE, - _ => EnumGenreSql.AUTRE, - }; - } + EnumGenreApi.MASCULIN => EnumGenreSql.MASCULIN, + EnumGenreApi.FEMININ => EnumGenreSql.FEMININ, + EnumGenreApi.AUTRE => EnumGenreSql.AUTRE, + _ => EnumGenreSql.AUTRE, + }; } -} +} \ No newline at end of file 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 9f7e1ca..a7d1ed7 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/EnumStatutMapper.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/EnumStatutMapper.cs @@ -1,32 +1,31 @@ using espacecollab.backend.appservices.dtos.Values; using espacecollab.backend.infrastructure.sql.dtos.Values; -namespace espacecollab.backend.appservices.dtos.Mappers +namespace espacecollab.backend.appservices.dtos.Mappers; + +public static class EnumStatutMapper { - public static class EnumStatutMapper + public static EnumStatutApi ToEnumStatutApi(this EnumStatutSql enumStatutSql) { - public static EnumStatutApi ToEnumStatutApi(this EnumStatutSql enumStatutSql) + return enumStatutSql switch { - return enumStatutSql switch - { - EnumStatutSql.STAGIAIRE => EnumStatutApi.STAGIAIRE, - EnumStatutSql.NONCADRE => EnumStatutApi.NONCADRE, - EnumStatutSql.CADRE => EnumStatutApi.CADRE, - EnumStatutSql.ALTERNANT => EnumStatutApi.ALTERNANT, - _ => EnumStatutApi.NONCADRE, - }; - } + EnumStatutSql.STAGIAIRE => EnumStatutApi.STAGIAIRE, + EnumStatutSql.NONCADRE => EnumStatutApi.NONCADRE, + EnumStatutSql.CADRE => EnumStatutApi.CADRE, + EnumStatutSql.ALTERNANT => EnumStatutApi.ALTERNANT, + _ => EnumStatutApi.NONCADRE, + }; + } - public static EnumStatutSql ToEnumStatutSql(this EnumStatutApi enumStatutApi) + public static EnumStatutSql ToEnumStatutSql(this EnumStatutApi enumStatutApi) + { + return enumStatutApi switch { - return enumStatutApi switch - { - EnumStatutApi.STAGIAIRE => EnumStatutSql.STAGIAIRE, - EnumStatutApi.NONCADRE => EnumStatutSql.NONCADRE, - EnumStatutApi.CADRE => EnumStatutSql.CADRE, - EnumStatutApi.ALTERNANT => EnumStatutSql.ALTERNANT, - _ => EnumStatutSql.NONCADRE, - }; - } + EnumStatutApi.STAGIAIRE => EnumStatutSql.STAGIAIRE, + EnumStatutApi.NONCADRE => EnumStatutSql.NONCADRE, + EnumStatutApi.CADRE => EnumStatutSql.CADRE, + EnumStatutApi.ALTERNANT => EnumStatutSql.ALTERNANT, + _ => EnumStatutSql.NONCADRE, + }; } -} +} \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/PeriodeEssaiMapper.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/PeriodeEssaiMapper.cs index cf4417e..0773314 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/PeriodeEssaiMapper.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Mappers/PeriodeEssaiMapper.cs @@ -1,4 +1,5 @@ -using espacecollab.backend.infrastructure.sql.dtos; +using espacecollab.backend.appservices.dtos.Values; +using espacecollab.backend.infrastructure.sql.dtos; using espacecollab.backend.infrastructure.sql.dtos.Values; namespace espacecollab.backend.appservices.dtos.Mappers; diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/PeriodeEssaiApiDto.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/PeriodeEssaiApiDto.cs index 3e4068b..f243bb8 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/PeriodeEssaiApiDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/PeriodeEssaiApiDto.cs @@ -1,5 +1,5 @@ using espacecollab.backend.appservices.dtos.Interfaces; -using espacecollab.backend.infrastructure.sql.dtos.Values; +using espacecollab.backend.appservices.dtos.Values; namespace espacecollab.backend.appservices.dtos; diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Values/EnumGenreApi.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Values/EnumGenreApi.cs index ea0429a..4a4aee0 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Values/EnumGenreApi.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Values/EnumGenreApi.cs @@ -1,9 +1,8 @@ -namespace espacecollab.backend.appservices.dtos.Values +namespace espacecollab.backend.appservices.dtos.Values; + +public enum EnumGenreApi { - public enum EnumGenreApi - { - MASCULIN, - FEMININ, - AUTRE - } -} + MASCULIN, + FEMININ, + AUTRE +} \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Values/EnumIssueApi.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Values/EnumIssueApi.cs index 25e5ae1..c36160e 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Values/EnumIssueApi.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Values/EnumIssueApi.cs @@ -1,11 +1,10 @@ -namespace espacecollab.backend.infrastructure.sql.dtos.Values +namespace espacecollab.backend.appservices.dtos.Values; + +public enum EnumIssueApi { - public enum EnumIssueApi - { - VALIDEE, - PROLONGEE_COLLAB, - PROLONGEE_APSIDE, - ARRETEE_COLLAB, - ARRETEE_APSIDE - } -} + VALIDEE, + PROLONGEE_COLLAB, + PROLONGEE_APSIDE, + ARRETEE_COLLAB, + ARRETEE_APSIDE +} \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Values/EnumStatutApi.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Values/EnumStatutApi.cs index d95441f..14ae974 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Values/EnumStatutApi.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.dtos/Values/EnumStatutApi.cs @@ -1,10 +1,9 @@ -namespace espacecollab.backend.appservices.dtos.Values +namespace espacecollab.backend.appservices.dtos.Values; + +public enum EnumStatutApi { - public enum EnumStatutApi - { - CADRE, - NONCADRE, - ALTERNANT, - STAGIAIRE - } + CADRE, + NONCADRE, + ALTERNANT, + STAGIAIRE } \ 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 eeeddae..ecb6c12 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices.interfaces/IGenericsServices.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices.interfaces/IGenericsServices.cs @@ -1,17 +1,16 @@ using espacecollab.backend.appservices.dtos.Interfaces; -namespace espacecollab.backend.appservices.interfaces +namespace espacecollab.backend.appservices.interfaces; + +public interface IGenericsServices where T : class, IGenericIdApiDto { - public interface IGenericsServices where T : class, IGenericIdApiDto - { - T? Add(T apiDto); + T? Add(T apiDto); - IEnumerable GetAll(); + IEnumerable GetAll(); - T? GetById(uint id); + T? GetById(uint id); - T? Update(T apiDto); + T? Update(T apiDto); - bool Delete(uint apiDtoId); - } -} + bool Delete(uint apiDtoId); +} \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices/AgenceService.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices/AgenceService.cs index fb7bfef..e081882 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices/AgenceService.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices/AgenceService.cs @@ -8,7 +8,7 @@ namespace espacecollab.backend.appservices; public class AgenceService : GenericsServices { public AgenceService(IAgenceRepository agenceRepository) - :base(agenceRepository, AgenceMapper.ToApi, AgenceMapper.ToSql) + : base(agenceRepository, AgenceMapper.ToApi, AgenceMapper.ToSql) { } } \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices/BusinessUnitService.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices/BusinessUnitService.cs index 16bb915..a12024e 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices/BusinessUnitService.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices/BusinessUnitService.cs @@ -1,4 +1,5 @@ -using espacecollab.backend.appservices.dtos.Mappers; +using espacecollab.backend.appservices.dtos; +using espacecollab.backend.appservices.dtos.Mappers; using espacecollab.backend.infrastructure.interfaces; using espacecollab.backend.infrastructure.sql.dtos; diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursService.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursService.cs index 18c2ba7..81796f9 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursService.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices/CollaborateursService.cs @@ -3,34 +3,33 @@ using espacecollab.backend.appservices.dtos.Mappers; using espacecollab.backend.infrastructure.interfaces; using espacecollab.backend.infrastructure.sql.dtos; -namespace espacecollab.backend.appservices +namespace espacecollab.backend.appservices; + +public class CollaborateursService : GenericsServices { - public class CollaborateursService : GenericsServices - { - private ICollaborateurRepository CollaborateurRepository { get; } + private ICollaborateurRepository CollaborateurRepository { get; } - public CollaborateursService(ICollaborateurRepository collaborateurRepository) - : base(collaborateurRepository, CollaborateurMapper.ToApi, CollaborateurMapper.ToSql) - { - CollaborateurRepository = collaborateurRepository; - } + public CollaborateursService(ICollaborateurRepository collaborateurRepository) + : base(collaborateurRepository, CollaborateurMapper.ToApi, CollaborateurMapper.ToSql) + { + CollaborateurRepository = collaborateurRepository; + } - public IEnumerable GetCollaborateursByBusinessUnit(uint businessUnitId) - { - return CollaborateurRepository.GetCollaborateursByBusinessUnit((int)businessUnitId).Select(collaborateurSql => collaborateurSql.ToApi()); - } + public IEnumerable GetCollaborateursByBusinessUnit(uint businessUnitId) + { + return CollaborateurRepository.GetCollaborateursByBusinessUnit((int)businessUnitId).Select(collaborateurSql => collaborateurSql.ToApi()); + } - public IEnumerable GetCollaborateursByReferrer(uint referrerId) - { - return CollaborateurRepository.GetCollaborateursByReferrer((int)referrerId).Select(collaborateurSql => collaborateurSql.ToApi()); - } + public IEnumerable GetCollaborateursByReferrer(uint referrerId) + { + return CollaborateurRepository.GetCollaborateursByReferrer((int)referrerId).Select(collaborateurSql => collaborateurSql.ToApi()); + } - public CollaborateurApiDto? GetCollaborateurByApsideMail(string apsideMail) - { - if (string.IsNullOrEmpty(apsideMail)) - return null; + public CollaborateurApiDto? GetCollaborateurByApsideMail(string apsideMail) + { + if (string.IsNullOrEmpty(apsideMail)) + return null; - return CollaborateurRepository.GetCollaborateurByApsideMail(apsideMail)?.ToApi(); - } + return CollaborateurRepository.GetCollaborateurByApsideMail(apsideMail)?.ToApi(); } -} +} \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs index 7798d35..72d8693 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices/GenericsServices.cs @@ -3,65 +3,64 @@ using espacecollab.backend.appservices.interfaces; using espacecollab.backend.infrastructure.interfaces; using espacecollab.backend.infrastructure.sql.dtos.Interfaces; -namespace espacecollab.backend.appservices +namespace espacecollab.backend.appservices; + +public abstract class GenericsServices : IGenericsServices where T : class, IGenericIdSqlDto + where TO : class, IGenericIdApiDto { - public abstract class GenericsServices : IGenericsServices where T : class, IGenericIdSqlDto - where TO : class, IGenericIdApiDto - { - private Func MapperToApiDto { get; } - private Func MapperToSqlDto { get; } - - private IGenericRepository GenericRepository { get; } + private Func MapperToApiDto { get; } + private Func MapperToSqlDto { get; } - protected GenericsServices(IGenericRepository genericRepository, Func mapperToApiDto, Func mapperToSqlDto) - { - GenericRepository = genericRepository; - MapperToApiDto = mapperToApiDto; - MapperToSqlDto = mapperToSqlDto; - } + private IGenericRepository GenericRepository { get; } - public IEnumerable GetAll() - { - return GenericRepository.GetAll().Select(entity => MapperToApiDto(entity)).ToList(); - } + protected GenericsServices(IGenericRepository genericRepository, Func mapperToApiDto, Func mapperToSqlDto) + { + GenericRepository = genericRepository; + MapperToApiDto = mapperToApiDto; + MapperToSqlDto = mapperToSqlDto; + } + + public IEnumerable GetAll() + { + return GenericRepository.GetAll().Select(entity => MapperToApiDto(entity)).ToList(); + } - public TO? GetById(uint id) - { - T? entity = GenericRepository.GetById((int)id); - if (entity == null) - return null; + public TO? GetById(uint id) + { + T? entity = GenericRepository.GetById((int)id); + if (entity == null) + return null; - return MapperToApiDto(entity); - } + return MapperToApiDto(entity); + } - public TO? Add(TO apiDto) - { - T sqlDto = MapperToSqlDto(apiDto); + public TO? Add(TO apiDto) + { + T sqlDto = MapperToSqlDto(apiDto); - T? entitySqlValidation = GenericRepository.Add(sqlDto); - if (entitySqlValidation == null) - return null; + T? entitySqlValidation = GenericRepository.Add(sqlDto); + if (entitySqlValidation == null) + return null; - return MapperToApiDto(entitySqlValidation); - } + return MapperToApiDto(entitySqlValidation); + } - public TO? Update(TO apiDto) - { - if (GetById(apiDto.Id) == null) - return null; + public TO? Update(TO apiDto) + { + if (GetById(apiDto.Id) == null) + return null; - T sqlDto = MapperToSqlDto(apiDto); - T? sqlDtoValidation = GenericRepository.Update(sqlDto); + T sqlDto = MapperToSqlDto(apiDto); + T? sqlDtoValidation = GenericRepository.Update(sqlDto); - if (sqlDtoValidation == null) - return null; + if (sqlDtoValidation == null) + return null; - return MapperToApiDto(sqlDtoValidation); - } + return MapperToApiDto(sqlDtoValidation); + } - public bool Delete(uint apiDtoId) - { - return GenericRepository.Delete((int)apiDtoId); - } + public bool Delete(uint apiDtoId) + { + return GenericRepository.Delete((int)apiDtoId); } -} +} \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.appservices/PeriodeEssaiService.cs b/Collaborateur_Epa_Back/espacecollab.backend.appservices/PeriodeEssaiService.cs index 10e72ac..64c3424 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.appservices/PeriodeEssaiService.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.appservices/PeriodeEssaiService.cs @@ -11,5 +11,4 @@ public class PeriodeEssaiService : GenericsServices, IAgenceRepository { - public class FakeAgenceRepository : GenericFakeRepository, IAgenceRepository + public FakeAgenceRepository() { - public FakeAgenceRepository() + Context = new List { - Context = new List - { - new(1, "Tours"), - - new(2, "Clermont-Ferrand") - }; - } + new(1, "Tours"), + new(2, "Clermont-Ferrand") + }; } -} +} \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeBusinessUnitRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeBusinessUnitRepository.cs index e9d99ed..f7ba96b 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeBusinessUnitRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeBusinessUnitRepository.cs @@ -1,18 +1,16 @@ using espacecollab.backend.infrastructure.interfaces; using espacecollab.backend.infrastructure.sql.dtos; -namespace espacecollab.backend.infrastructure.fake +namespace espacecollab.backend.infrastructure.fake; + +public class FakeBusinessUnitRepository : GenericFakeRepository, IBusinessUnitRepository { - public class FakeBusinessUnitRepository : GenericFakeRepository, IBusinessUnitRepository + public FakeBusinessUnitRepository() { - public FakeBusinessUnitRepository() + Context = new List { - Context = new List - { - new(1, "BU 1", 1), - - new(2, "BU 2", 1) - }; - } + new(1, "BU 1", 1), + new(2, "BU 2", 1) + }; } -} +} \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeCollaborateurRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeCollaborateurRepository.cs index d6aa6bc..f1a956c 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeCollaborateurRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeCollaborateurRepository.cs @@ -2,41 +2,39 @@ using espacecollab.backend.infrastructure.sql.dtos; using espacecollab.backend.infrastructure.sql.dtos.Values; -namespace espacecollab.backend.infrastructure.fake +namespace espacecollab.backend.infrastructure.fake; + +public class FakeCollaborateurRepository : GenericFakeRepository, ICollaborateurRepository { - public class FakeCollaborateurRepository : GenericFakeRepository, ICollaborateurRepository + public FakeCollaborateurRepository() { - public FakeCollaborateurRepository() + Context = new List { - 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) - }; - } + new(1, "Dupont", "Jean", new DateTime(1980, 12, 10), + EnumGenreSql.MASCULIN, EnumStatutSql.NONCADRE, 0, "1 rue du Louvre, 63000, Clermont-Ferrand", "0660258644", + "jean.dupont@gmail.com", "jean.dupont@apside-groupe.com", new DateTime(2023, 12, 17), 2, 1), + new(2, "Michel", "Laura", new DateTime(1985, 08, 12), + EnumGenreSql.FEMININ, EnumStatutSql.NONCADRE, 0, "5 rue du Louvre, 63000, Clermont-Ferrand", "0660258644", + "laura.michel@gmail.com", "laura.michel@apside-groupe.com", new DateTime(2023, 12, 17), 1, 1) + }; + } - #region méthodes spécifiques à l'interface ICollaborateurRepository + #region méthodes spécifiques à l'interface ICollaborateurRepository - public IList 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 IList GetCollaborateursByBusinessUnit(int businessUnitId) + { + return Context.Where(entity => entity.BusinessUnitId == businessUnitId).ToList(); + } - public CollaborateurSqlDto GetCollaborateurByApsideMail(string apsideMail) - { - return Context.First(entity => entity.ApsideMail == apsideMail); - } + public IList GetCollaborateursByReferrer(int referrerId) + { + return Context.Where(entity => entity.ReferrerId == referrerId).ToList(); + } - #endregion + public CollaborateurSqlDto GetCollaborateurByApsideMail(string apsideMail) + { + return Context.First(entity => entity.ApsideMail == apsideMail); } -} + + #endregion +} \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeFonctionRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeFonctionRepository.cs index 8bf34bf..f33f212 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeFonctionRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakeFonctionRepository.cs @@ -10,7 +10,6 @@ public class FakeFonctionRepository : GenericFakeRepository, IFo Context = new List { new(1, "Fonction 1"), - new(2, "Fonction 2") }; } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakePeriodeEssaiRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakePeriodeEssaiRepository.cs index a44fbae..cda3af7 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakePeriodeEssaiRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/FakePeriodeEssaiRepository.cs @@ -11,7 +11,6 @@ public class FakePeriodeEssaiRepository : GenericFakeRepository { new(1, new DateTime(2021, 10, 1), new DateTime(2021, 12, 1), new DateTime(2022, 1, 1), "A voir", EnumIssueSql.VALIDEE, 1), - new(2, new DateTime(2021, 10, 1), new DateTime(2021, 12, 1), new DateTime(2022, 1, 1), "Ne pas donner suite", EnumIssueSql.ARRETEE_APSIDE, 2) }; } diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/GenericFakeRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/GenericFakeRepository.cs index 08dae61..34c6125 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/GenericFakeRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.fake/GenericFakeRepository.cs @@ -1,49 +1,48 @@ using espacecollab.backend.infrastructure.interfaces; using espacecollab.backend.infrastructure.sql.dtos.Interfaces; -namespace espacecollab.backend.infrastructure.fake +namespace espacecollab.backend.infrastructure.fake; + +public class GenericFakeRepository : IGenericRepository where T : class, IGenericIdSqlDto { - public class GenericFakeRepository : IGenericRepository where T : class, IGenericIdSqlDto + protected List Context { get; set; } = new(); + + public virtual T? Add(T entity) + { + int lastId = Context.Max(e => e.Id); + entity.Id = lastId + 1; + + Context.Add(entity); + + return entity; + } + + public virtual bool Delete(int entityId) + { + T? entity = GetById(entityId); + if (entity == null) return false; + return Context.Remove(entity); + } + + public virtual IEnumerable GetAll() { - protected List Context { get; set; } = new(); - - public virtual T? Add(T entity) - { - int lastId = Context.Max(e => e.Id); - entity.Id = lastId + 1; - - Context.Add(entity); - - return entity; - } - - public virtual bool Delete(int entityId) - { - T? entity = GetById(entityId); - if (entity == null) return false; - return Context.Remove(entity); - } - - public virtual IEnumerable GetAll() - { - return Context.ToList(); - } - - public virtual T? GetById(int id) - { - return Context.FirstOrDefault(entity => entity.Id == id); - } - - public virtual T? Update(T entity) - { - T? oldEntity = GetById(entity.Id); - if (oldEntity == null) - return null; - - Context.Remove(oldEntity); - Context.Add(entity); - - return Context.FirstOrDefault(e => e.Id == entity.Id); - } + return Context.ToList(); + } + + public virtual T? GetById(int id) + { + return Context.FirstOrDefault(entity => entity.Id == id); + } + + public virtual T? Update(T entity) + { + T? oldEntity = GetById(entity.Id); + if (oldEntity == null) + return null; + + Context.Remove(oldEntity); + Context.Add(entity); + + return Context.FirstOrDefault(e => e.Id == entity.Id); } -} +} \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IAgenceRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IAgenceRepository.cs index 1443cdd..e93c032 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IAgenceRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IAgenceRepository.cs @@ -1,8 +1,7 @@ using espacecollab.backend.infrastructure.sql.dtos; -namespace espacecollab.backend.infrastructure.interfaces +namespace espacecollab.backend.infrastructure.interfaces; + +public interface IAgenceRepository : IGenericRepository { - public interface IAgenceRepository : IGenericRepository - { - } } \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IBusinessUnitRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IBusinessUnitRepository.cs index 42a10fd..5ef62a0 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IBusinessUnitRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IBusinessUnitRepository.cs @@ -1,8 +1,7 @@ using espacecollab.backend.infrastructure.sql.dtos; -namespace espacecollab.backend.infrastructure.interfaces +namespace espacecollab.backend.infrastructure.interfaces; + +public interface IBusinessUnitRepository : IGenericRepository { - public interface IBusinessUnitRepository : IGenericRepository - { - } } \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/ICollaborateurRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/ICollaborateurRepository.cs index f89aecb..35f8866 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/ICollaborateurRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/ICollaborateurRepository.cs @@ -1,11 +1,10 @@ using espacecollab.backend.infrastructure.sql.dtos; -namespace espacecollab.backend.infrastructure.interfaces +namespace espacecollab.backend.infrastructure.interfaces; + +public interface ICollaborateurRepository : IGenericRepository { - public interface ICollaborateurRepository : IGenericRepository - { - CollaborateurSqlDto? GetCollaborateurByApsideMail(string apsideMail); - IList GetCollaborateursByBusinessUnit(int businessUnitId); - IList GetCollaborateursByReferrer(int 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.interfaces/IGenericRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IGenericRepository.cs index a071958..9554d2b 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IGenericRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IGenericRepository.cs @@ -1,14 +1,12 @@ using espacecollab.backend.infrastructure.sql.dtos.Interfaces; -namespace espacecollab.backend.infrastructure.interfaces +namespace espacecollab.backend.infrastructure.interfaces; + +public interface IGenericRepository where T : class, IGenericIdSqlDto { - public interface IGenericRepository where T : class, IGenericIdSqlDto - { - T? Add(T entity); - bool Delete(int entityId); - IEnumerable GetAll(); - T? GetById(int id); - T? Update(T entity); - //void GetAll() where T : class, IGenericSqlDto; - } + T? Add(T entity); + bool Delete(int entityId); + IEnumerable GetAll(); + T? GetById(int id); + T? Update(T entity); } \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IProjetRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IProjetRepository.cs index 8738106..adb65e2 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IProjetRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IProjetRepository.cs @@ -1,9 +1,8 @@ using espacecollab.backend.infrastructure.sql.dtos; -namespace espacecollab.backend.infrastructure.interfaces +namespace espacecollab.backend.infrastructure.interfaces; + +public interface IProjetRepository : IGenericRepository { - 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.interfaces/IReferencementRepository.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IReferencementRepository.cs index 4bb453e..c12b65f 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IReferencementRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.interfaces/IReferencementRepository.cs @@ -1,10 +1,9 @@ using espacecollab.backend.infrastructure.sql.dtos; -namespace espacecollab.backend.infrastructure.interfaces +namespace espacecollab.backend.infrastructure.interfaces; + +public interface IReferencementRepository : IGenericRepository { - public interface IReferencementRepository : IGenericRepository - { - IList? GetReferrersByCollaborateurId(int collaborateurId); - IList? GetReferrersByCollaborateurApsideMail(string apsideMail); - } + IList? GetReferrersByCollaborateurId(int collaborateurId); + IList? GetReferrersByCollaborateurApsideMail(string apsideMail); } \ No newline at end of file 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 03fc86a..cc67f52 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurAppartientBusinessUnitSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurAppartientBusinessUnitSqlDto.cs @@ -1,24 +1,21 @@ using System.Diagnostics.CodeAnalysis; -namespace espacecollab.backend.infrastructure.sql.dtos -{ - public class CollaborateurAppartientBusinessUnitSqlDto - { - public int CollaborateurId { get; set; } - public int BusinessUnitId { get; set; } +namespace espacecollab.backend.infrastructure.sql.dtos; +public class CollaborateurAppartientBusinessUnitSqlDto +{ + public int CollaborateurId { get; set; } + public int BusinessUnitId { get; set; } - [ExcludeFromCodeCoverage] - private CollaborateurAppartientBusinessUnitSqlDto() - { - } - - public CollaborateurAppartientBusinessUnitSqlDto(int collaborateurId, int businessUnitId) - { - CollaborateurId = collaborateurId; - BusinessUnitId = businessUnitId; - } + [ExcludeFromCodeCoverage] + private CollaborateurAppartientBusinessUnitSqlDto() + { + } + public CollaborateurAppartientBusinessUnitSqlDto(int collaborateurId, int businessUnitId) + { + CollaborateurId = collaborateurId; + BusinessUnitId = businessUnitId; } -} +} \ No newline at end of file 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 0c61504..c57fa0a 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurCollaboreProjetSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurCollaboreProjetSqlDto.cs @@ -1,24 +1,22 @@ using System.Diagnostics.CodeAnalysis; -namespace espacecollab.backend.infrastructure.sql.dtos -{ - public class CollaborateurCollaboreProjetSqlDto - { - public int CollaborateurId { get; set; } - public int ProjetId { get; set; } - public bool IsManager { get; set; } +namespace espacecollab.backend.infrastructure.sql.dtos; - [ExcludeFromCodeCoverage] - private CollaborateurCollaboreProjetSqlDto() - { - } +public class CollaborateurCollaboreProjetSqlDto +{ + public int CollaborateurId { get; set; } + public int ProjetId { get; set; } + public bool IsManager { get; set; } - public CollaborateurCollaboreProjetSqlDto(int collaborateurId, int projetId, bool isManager) - { - CollaborateurId = collaborateurId; - ProjetId = projetId; - IsManager = isManager; - } + [ExcludeFromCodeCoverage] + private CollaborateurCollaboreProjetSqlDto() + { + } + public CollaborateurCollaboreProjetSqlDto(int collaborateurId, int projetId, bool isManager) + { + CollaborateurId = collaborateurId; + ProjetId = projetId; + IsManager = isManager; } -} +} \ No newline at end of file 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 cf7fcde..70da704 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurEstFonctionSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/CollaborateurEstFonctionSqlDto.cs @@ -1,23 +1,20 @@ using System.Diagnostics.CodeAnalysis; -namespace espacecollab.backend.infrastructure.sql.dtos -{ - public class CollaborateurEstFonctionSqlDto - { - public int CollaborateurId { get; set; } - public int FonctionId { get; set; } +namespace espacecollab.backend.infrastructure.sql.dtos; - [ExcludeFromCodeCoverage] - private CollaborateurEstFonctionSqlDto() - { - } - - public CollaborateurEstFonctionSqlDto(int collaborateurId, int fonctionId) - { - CollaborateurId = collaborateurId; - FonctionId = fonctionId; - } +public class CollaborateurEstFonctionSqlDto +{ + public int CollaborateurId { get; set; } + public int FonctionId { get; set; } + [ExcludeFromCodeCoverage] + private CollaborateurEstFonctionSqlDto() + { + } + public CollaborateurEstFonctionSqlDto(int collaborateurId, int fonctionId) + { + CollaborateurId = collaborateurId; + FonctionId = fonctionId; } -} +} \ No newline at end of file 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 ed1eb8e..5bb3bff 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/FonctionSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/FonctionSqlDto.cs @@ -18,5 +18,4 @@ public class FonctionSqlDto : IGenericIdSqlDto Id = id; Name = name; } - } \ No newline at end of file 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 index ce4c282..dc326e5 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/Interfaces/IGenericIdSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/Interfaces/IGenericIdSqlDto.cs @@ -1,7 +1,6 @@ -namespace espacecollab.backend.infrastructure.sql.dtos.Interfaces +namespace espacecollab.backend.infrastructure.sql.dtos.Interfaces; + +public interface IGenericIdSqlDto { - public interface IGenericIdSqlDto - { - public int Id { get; set; } - } -} + public int Id { get; set; } +} \ No newline at end of file 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 62df00f..9cd830b 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetSqlDto.cs @@ -1,30 +1,29 @@ using System.Diagnostics.CodeAnalysis; using espacecollab.backend.infrastructure.sql.dtos.Interfaces; -namespace espacecollab.backend.infrastructure.sql.dtos +namespace espacecollab.backend.infrastructure.sql.dtos; + +public class ProjetSqlDto : IGenericIdSqlDto { - public class ProjetSqlDto : IGenericIdSqlDto - { - public int Id { get; set; } - public string Name { get; set; } - public string Client { get; set; } - public string Description { get; set; } - public DateTime StartingDate { get; set; } - public DateTime EndingDate { get; set; } + public int Id { get; set; } + public string Name { get; set; } + public string Client { get; set; } + public string Description { get; set; } + public DateTime StartingDate { get; set; } + public DateTime EndingDate { get; set; } - [ExcludeFromCodeCoverage] - private ProjetSqlDto() - { - } + [ExcludeFromCodeCoverage] + private ProjetSqlDto() + { + } - public ProjetSqlDto(int id, string name, string client, string description, DateTime startingDate, DateTime endingDate) - { - Id = id; - Name = name; - Client = client; - Description = description; - StartingDate = startingDate; - EndingDate = endingDate; - } + public ProjetSqlDto(int id, string name, string client, string description, DateTime startingDate, DateTime endingDate) + { + Id = id; + Name = name; + Client = client; + Description = description; + StartingDate = startingDate; + EndingDate = endingDate; } -} +} \ No newline at end of file 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 bf47a6a..48147de 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetUtiliseTechnologieSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ProjetUtiliseTechnologieSqlDto.cs @@ -1,21 +1,20 @@ using System.Diagnostics.CodeAnalysis; -namespace espacecollab.backend.infrastructure.sql.dtos +namespace espacecollab.backend.infrastructure.sql.dtos; + +public class ProjetUtiliseTechnologieSqlDto { - public class ProjetUtiliseTechnologieSqlDto - { - public int ProjetId { get; set; } - public int TechnologieId { get; set; } + public int ProjetId { get; set; } + public int TechnologieId { get; set; } - [ExcludeFromCodeCoverage] - private ProjetUtiliseTechnologieSqlDto() - { - } + [ExcludeFromCodeCoverage] + private ProjetUtiliseTechnologieSqlDto() + { + } - public ProjetUtiliseTechnologieSqlDto(int projetId, int technologieId) - { - ProjetId = projetId; - TechnologieId = technologieId; - } + public ProjetUtiliseTechnologieSqlDto(int projetId, int technologieId) + { + ProjetId = projetId; + TechnologieId = technologieId; } -} +} \ No newline at end of file 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 8bd980a..09318a5 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ReferencementSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/ReferencementSqlDto.cs @@ -1,28 +1,27 @@ using System.Diagnostics.CodeAnalysis; using espacecollab.backend.infrastructure.sql.dtos.Interfaces; -namespace espacecollab.backend.infrastructure.sql.dtos +namespace espacecollab.backend.infrastructure.sql.dtos; + +public class ReferencementSqlDto : IGenericIdSqlDto { - public class ReferencementSqlDto : IGenericIdSqlDto - { - public int Id { get; set; } - public DateTime StartingDate { get; set; } - public DateTime EndingDate { get; set; } - public int ReferredId { get; set; } - public int ReferrerId { get; set; } + public int Id { get; set; } + public DateTime StartingDate { get; set; } + public DateTime EndingDate { get; set; } + public int ReferredId { get; set; } + public int ReferrerId { get; set; } - [ExcludeFromCodeCoverage] - private ReferencementSqlDto() - { - } + [ExcludeFromCodeCoverage] + private ReferencementSqlDto() + { + } - public ReferencementSqlDto(int id, DateTime startingDate, DateTime endingDate, int referredId, int referrerId) - { - Id = id; - StartingDate = startingDate; - EndingDate = endingDate; - ReferredId = referredId; - ReferrerId = referrerId; - } + public ReferencementSqlDto(int id, DateTime startingDate, DateTime endingDate, int referredId, int referrerId) + { + Id = id; + StartingDate = startingDate; + EndingDate = endingDate; + ReferredId = referredId; + ReferrerId = referrerId; } -} +} \ No newline at end of file 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 8cc3395..3572149 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteDeveloppeProjetSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteDeveloppeProjetSqlDto.cs @@ -1,24 +1,20 @@ using System.Diagnostics.CodeAnalysis; -namespace espacecollab.backend.infrastructure.sql.dtos -{ - public class SiteDeveloppeProjetSqlDto - { - public int SiteId { get; set; } - public int ProjetId { get; set; } - - [ExcludeFromCodeCoverage] - private SiteDeveloppeProjetSqlDto() - { - } - - public SiteDeveloppeProjetSqlDto(int siteId, int projetId) - { - SiteId = siteId; - ProjetId = projetId; - } +namespace espacecollab.backend.infrastructure.sql.dtos; +public class SiteDeveloppeProjetSqlDto +{ + public int SiteId { get; set; } + public int ProjetId { get; set; } + [ExcludeFromCodeCoverage] + private SiteDeveloppeProjetSqlDto() + { + } + public SiteDeveloppeProjetSqlDto(int siteId, int projetId) + { + SiteId = siteId; + ProjetId = projetId; } -} +} \ No newline at end of file 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 216ca5d..f639708 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/SiteSqlDto.cs @@ -1,29 +1,25 @@ using System.Diagnostics.CodeAnalysis; using espacecollab.backend.infrastructure.sql.dtos.Interfaces; -namespace espacecollab.backend.infrastructure.sql.dtos -{ - public class SiteSqlDto : IGenericIdSqlDto - { - public int Id { get; set; } - public string Name { get; set; } - public string Address { get; set; } - public int BusinessUnitId { get; set; } - - [ExcludeFromCodeCoverage] - private SiteSqlDto() - { - } - - public SiteSqlDto(int id, string name, string address, int businessUnitId) - { - Id = id; - Name = name; - Address = address; - BusinessUnitId = businessUnitId; - } +namespace espacecollab.backend.infrastructure.sql.dtos; +public class SiteSqlDto : IGenericIdSqlDto +{ + public int Id { get; set; } + public string Name { get; set; } + public string Address { get; set; } + public int BusinessUnitId { get; set; } + [ExcludeFromCodeCoverage] + private SiteSqlDto() + { + } + public SiteSqlDto(int id, string name, string address, int businessUnitId) + { + Id = id; + Name = name; + Address = address; + BusinessUnitId = businessUnitId; } -} +} \ No newline at end of file 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 cf53ce5..01df2e0 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/TechnologieSqlDto.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/TechnologieSqlDto.cs @@ -1,23 +1,21 @@ -using System.Diagnostics.CodeAnalysis; -using espacecollab.backend.infrastructure.sql.dtos.Interfaces; +using espacecollab.backend.infrastructure.sql.dtos.Interfaces; +using System.Diagnostics.CodeAnalysis; -namespace espacecollab.backend.infrastructure.sql.dtos -{ - public class TechnologieSqlDto : IGenericIdSqlDto - { - public int Id { get; set; } - public string Name { get; set; } +namespace espacecollab.backend.infrastructure.sql.dtos; - [ExcludeFromCodeCoverage] - private TechnologieSqlDto() - { - } +public class TechnologieSqlDto : IGenericIdSqlDto +{ + public int Id { get; set; } + public string Name { get; set; } - public TechnologieSqlDto(int id, string name) - { - Id = id; - Name = name; - } + [ExcludeFromCodeCoverage] + private TechnologieSqlDto() + { + } + public TechnologieSqlDto(int id, string name) + { + Id = id; + Name = name; } -} +} \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/Values/EnumGenreSql.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/Values/EnumGenreSql.cs index f3298bc..617e7ff 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/Values/EnumGenreSql.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/Values/EnumGenreSql.cs @@ -1,9 +1,8 @@ -namespace espacecollab.backend.infrastructure.sql.dtos.Values +namespace espacecollab.backend.infrastructure.sql.dtos.Values; + +public enum EnumGenreSql { - public enum EnumGenreSql - { - MASCULIN, - FEMININ, - AUTRE - } -} + MASCULIN, + FEMININ, + AUTRE +} \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/Values/EnumIssueSql.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/Values/EnumIssueSql.cs index 63e990c..fa9fd6a 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/Values/EnumIssueSql.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/Values/EnumIssueSql.cs @@ -1,11 +1,10 @@ -namespace espacecollab.backend.infrastructure.sql.dtos.Values +namespace espacecollab.backend.infrastructure.sql.dtos.Values; + +public enum EnumIssueSql { - public enum EnumIssueSql - { - VALIDEE, - PROLONGEE_COLLAB, - PROLONGEE_APSIDE, - ARRETEE_COLLAB, - ARRETEE_APSIDE - } -} + VALIDEE, + PROLONGEE_COLLAB, + PROLONGEE_APSIDE, + ARRETEE_COLLAB, + ARRETEE_APSIDE +} \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/Values/EnumStatutSql.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/Values/EnumStatutSql.cs index d0284a3..4131c9b 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/Values/EnumStatutSql.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql.dtos/Values/EnumStatutSql.cs @@ -1,10 +1,9 @@ -namespace espacecollab.backend.infrastructure.sql.dtos.Values +namespace espacecollab.backend.infrastructure.sql.dtos.Values; + +public enum EnumStatutSql { - public enum EnumStatutSql - { - CADRE, - NONCADRE, - ALTERNANT, - STAGIAIRE - } -} + CADRE, + NONCADRE, + ALTERNANT, + STAGIAIRE +} \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/MainDbContext.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/MainDbContext.cs index 247426c..e05acb9 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/MainDbContext.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/MainDbContext.cs @@ -2,36 +2,35 @@ using espacecollab.backend.infrastructure.sql.Options; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; -namespace espacecollab.backend.infrastructure.sql + +namespace espacecollab.backend.infrastructure.sql; + +public class MainDbContext : DbContext { - public class MainDbContext : DbContext - { - private IOptions SqlSettings { get; } - private DbSet? Collaborateur { get; set; } + private IOptions SqlSettings { get; } - public MainDbContext(IOptions sqlSettings) - { - SqlSettings = sqlSettings; - } + public MainDbContext(IOptions sqlSettings) + { + SqlSettings = sqlSettings; + } - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { - optionsBuilder.UseMySql(SqlSettings.Value.ConnectionString, + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + optionsBuilder.UseMySql(SqlSettings.Value.ConnectionString, ServerVersion.AutoDetect(SqlSettings.Value.ConnectionString)) - .EnableSensitiveDataLogging(); - } + .EnableSensitiveDataLogging(); + } - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - modelBuilder.Entity().Property(p=> p.Id).UseMySqlIdentityColumn(); - modelBuilder - .Entity() - .Property(e => e.Gender) - .HasConversion(); - modelBuilder - .Entity() - .Property(e => e.Status) - .HasConversion(); - } + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity().Property(p => p.Id).UseMySqlIdentityColumn(); + modelBuilder + .Entity() + .Property(e => e.Gender) + .HasConversion(); + modelBuilder + .Entity() + .Property(e => e.Status) + .HasConversion(); } -} +} \ No newline at end of file diff --git a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Options/SqlOption.cs b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Options/SqlOption.cs index f741343..0216f27 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Options/SqlOption.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Options/SqlOption.cs @@ -1,14 +1,13 @@ -namespace espacecollab.backend.infrastructure.sql.Options +namespace espacecollab.backend.infrastructure.sql.Options; + +public class SqlOption { - public class SqlOption - { - public static string Key => "Sql"; - public bool LoadFake { get; set; } - public string ConnectionString { get; set; } + public static string Key => "Sql"; + public bool LoadFake { get; set; } + public string ConnectionString { get; set; } - public SqlOption() - { - ConnectionString = string.Empty; - } + public SqlOption() + { + ConnectionString = string.Empty; } -} +} \ 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 f24bf5f..7abfa46 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/CollaborateurSqlRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/CollaborateurSqlRepository.cs @@ -1,22 +1,21 @@ using espacecollab.backend.infrastructure.interfaces; using espacecollab.backend.infrastructure.sql.dtos; -namespace espacecollab.backend.infrastructure.sql.Repository +namespace espacecollab.backend.infrastructure.sql.Repository; + +public class CollaborateurSqlRepository : GenericSqlRepository, ICollaborateurRepository { - public class CollaborateurSqlRepository : GenericSqlRepository, ICollaborateurRepository + public CollaborateurSqlRepository(MainDbContext context) : base(context) { - public CollaborateurSqlRepository(MainDbContext context) : base(context) - { - Context = context; - } + Context = context; + } - public IList GetCollaborateursByBusinessUnit(int businessUnitId) - => Context.Set().Where(collaborateur => collaborateur.BusinessUnitId == businessUnitId).ToList(); + public IList GetCollaborateursByBusinessUnit(int businessUnitId) + => Context.Set().Where(collaborateur => collaborateur.BusinessUnitId == businessUnitId).ToList(); - public IList GetCollaborateursByReferrer(int referrerId) - => Context.Set().Where(collaborateur => collaborateur.ReferrerId == referrerId).ToList(); + public IList GetCollaborateursByReferrer(int referrerId) + => Context.Set().Where(collaborateur => collaborateur.ReferrerId == referrerId).ToList(); - public CollaborateurSqlDto? GetCollaborateurByApsideMail(string apsideMail) - => Context?.Set().SingleOrDefault(collaborateur => collaborateur.ApsideMail == apsideMail); - } -} + public CollaborateurSqlDto? GetCollaborateurByApsideMail(string apsideMail) + => Context?.Set().SingleOrDefault(collaborateur => collaborateur.ApsideMail == apsideMail); +} \ 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 77d9023..532ea08 100644 --- a/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/GenericSqlRepository.cs +++ b/Collaborateur_Epa_Back/espacecollab.backend.infrastructure.sql/Repository/GenericSqlRepository.cs @@ -1,50 +1,51 @@ using espacecollab.backend.infrastructure.interfaces; using espacecollab.backend.infrastructure.sql.dtos.Interfaces; -using Microsoft.EntityFrameworkCore; -namespace espacecollab.backend.infrastructure.sql.Repository +namespace espacecollab.backend.infrastructure.sql.Repository; + +public class GenericSqlRepository : IGenericRepository where T : class, IGenericIdSqlDto { - public class GenericSqlRepository : IGenericRepository where T : class, IGenericIdSqlDto + protected MainDbContext Context { get; set; } + + public GenericSqlRepository(MainDbContext context) + { + Context = context; + } + + public virtual T? Add(T entity) { - protected MainDbContext Context { get; set; } - - public GenericSqlRepository(MainDbContext context) - { - Context = context; - } - - public virtual T? Add(T entity) - { - Context.Set().Add(entity); - Context.SaveChanges(); - return entity; - - } - - public virtual bool Delete(int entityId) - { - T? entity = GetById(entityId); - if (entity == null) return false; - Context.Set().Remove(entity); - - return Context.SaveChanges() == 1; - } - - public virtual IEnumerable GetAll() - { - return Context.Set().ToList(); - } - - public virtual T? GetById(int id) - { - return Context.Set().FirstOrDefault(entity => entity.Id == id); - } - - public virtual T? Update(T entity) - { - Context.Set().Update(entity); - Context.SaveChanges(); - return Context.Set().FirstOrDefault(e => e.Id == entity.Id); - } + Context.Set().Add(entity); + Context.SaveChanges(); + + return entity; + } + + public virtual bool Delete(int entityId) + { + T? entity = GetById(entityId); + if (entity == null) + return false; + + Context.Set().Remove(entity); + + return Context.SaveChanges() == 1; + } + + public virtual IEnumerable GetAll() + { + return Context.Set().ToList(); + } + + public virtual T? GetById(int id) + { + return Context.Set().SingleOrDefault(entity => entity.Id == id); + } + + public virtual T? Update(T entity) + { + Context.Set().Update(entity); + Context.SaveChanges(); + + return GetById(entity.Id); } -} +} \ No newline at end of file