Merge pull request '- Api v1.0' (#20) from dev into main
Reviewed-on: #20
This commit is contained in:
commit
39cf9124fe
13
.idea/.idea.ldap-cesi/.idea/.gitignore
generated
vendored
Normal file
13
.idea/.idea.ldap-cesi/.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Rider ignored files
|
||||||
|
/modules.xml
|
||||||
|
/.idea.ldap-cesi.iml
|
||||||
|
/projectSettingsUpdater.xml
|
||||||
|
/contentModel.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
18
.idea/.idea.ldap-cesi/.idea/dataSources.xml
generated
Normal file
18
.idea/.idea.ldap-cesi/.idea/dataSources.xml
generated
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
||||||
|
<data-source source="LOCAL" name="ldap@192.168.1.196" uuid="4416cc9a-9c84-4a37-8ec1-70323890f91e">
|
||||||
|
<driver-ref>postgresql</driver-ref>
|
||||||
|
<synchronize>true</synchronize>
|
||||||
|
<jdbc-driver>org.postgresql.Driver</jdbc-driver>
|
||||||
|
<jdbc-url>jdbc:postgresql://192.168.1.196:5432/ldap</jdbc-url>
|
||||||
|
<jdbc-additional-properties>
|
||||||
|
<property name="com.intellij.clouds.kubernetes.db.host.port" />
|
||||||
|
<property name="com.intellij.clouds.kubernetes.db.enabled" value="false" />
|
||||||
|
<property name="com.intellij.clouds.kubernetes.db.resource.type" value="Deployment" />
|
||||||
|
<property name="com.intellij.clouds.kubernetes.db.container.port" />
|
||||||
|
</jdbc-additional-properties>
|
||||||
|
<working-dir>$ProjectFileDir$</working-dir>
|
||||||
|
</data-source>
|
||||||
|
</component>
|
||||||
|
</project>
|
4
.idea/.idea.ldap-cesi/.idea/encodings.xml
generated
Normal file
4
.idea/.idea.ldap-cesi/.idea/encodings.xml
generated
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
|
||||||
|
</project>
|
8
.idea/.idea.ldap-cesi/.idea/indexLayout.xml
generated
Normal file
8
.idea/.idea.ldap-cesi/.idea/indexLayout.xml
generated
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="UserContentModel">
|
||||||
|
<attachedFolders />
|
||||||
|
<explicitIncludes />
|
||||||
|
<explicitExcludes />
|
||||||
|
</component>
|
||||||
|
</project>
|
26
.idea/.idea.ldap-cesi/.idea/misc.xml
generated
Normal file
26
.idea/.idea.ldap-cesi/.idea/misc.xml
generated
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="KubernetesApiProvider">{}</component>
|
||||||
|
<component name="ProjectInspectionProfilesVisibleTreeState">
|
||||||
|
<entry key="Project Default">
|
||||||
|
<profile-state>
|
||||||
|
<expanded-state>
|
||||||
|
<State>
|
||||||
|
<id>Android Lint: Security</id>
|
||||||
|
</State>
|
||||||
|
<State>
|
||||||
|
<id>Code Coverage</id>
|
||||||
|
</State>
|
||||||
|
<State>
|
||||||
|
<id>HTML</id>
|
||||||
|
</State>
|
||||||
|
</expanded-state>
|
||||||
|
<selected-state>
|
||||||
|
<State>
|
||||||
|
<id>AndroidLintBadHostnameVerifier</id>
|
||||||
|
</State>
|
||||||
|
</selected-state>
|
||||||
|
</profile-state>
|
||||||
|
</entry>
|
||||||
|
</component>
|
||||||
|
</project>
|
6
.idea/.idea.ldap-cesi/.idea/vcs.xml
generated
Normal file
6
.idea/.idea.ldap-cesi/.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
16
ldap-cesi.sln
Normal file
16
ldap-cesi.sln
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ldap-cesi", "ldap-cesi\ldap-cesi.csproj", "{0AE1CE6A-DF41-4377-92A9-80E130D27F8B}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{0AE1CE6A-DF41-4377-92A9-80E130D27F8B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{0AE1CE6A-DF41-4377-92A9-80E130D27F8B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{0AE1CE6A-DF41-4377-92A9-80E130D27F8B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{0AE1CE6A-DF41-4377-92A9-80E130D27F8B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
9
ldap-cesi/.gitignore
vendored
Normal file
9
ldap-cesi/.gitignore
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
bin/
|
||||||
|
obj/
|
||||||
|
/packages/
|
||||||
|
riderModule.iml
|
||||||
|
/_ReSharper.Caches/
|
||||||
|
appsettings.json
|
||||||
|
appsettings.Development.json
|
||||||
|
/.env
|
||||||
|
/logs
|
148
ldap-cesi/Configurations/Conf.cs
Normal file
148
ldap-cesi/Configurations/Conf.cs
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
using FluentValidation;
|
||||||
|
using FluentValidation.AspNetCore;
|
||||||
|
using ldap_cesi.Context;
|
||||||
|
using ldap_cesi.Repository;
|
||||||
|
using ldap_cesi.Repository.Services;
|
||||||
|
using ldap_cesi.Services;
|
||||||
|
using ldap_cesi.Services.Interfaces;
|
||||||
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.IdentityModel.Tokens;
|
||||||
|
using Microsoft.OpenApi.Models;
|
||||||
|
using Serilog;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Configurations;
|
||||||
|
|
||||||
|
public static class Conf
|
||||||
|
{
|
||||||
|
public static void BuildConf(this WebApplicationBuilder builder)
|
||||||
|
{
|
||||||
|
builder.AddRepositories();
|
||||||
|
builder.AddServices();
|
||||||
|
builder.Services.AddControllers();
|
||||||
|
builder.AddEFCoreConfiguration();
|
||||||
|
builder.CorseConfiguration();
|
||||||
|
builder.AddSwagger();
|
||||||
|
builder.AddSerilog();
|
||||||
|
builder.AddJwt();
|
||||||
|
builder.Services.AddAutoMapper(typeof(Program));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AddRepositories(this WebApplicationBuilder builder)
|
||||||
|
{
|
||||||
|
builder.Services.AddScoped<IRepositoryService, ServiceRepository>();
|
||||||
|
builder.Services.AddScoped<IRepositorySite, SiteRepository>();
|
||||||
|
builder.Services.AddScoped<IRepositorySalarie, SalarieRepository>();
|
||||||
|
builder.Services.AddScoped<IRepositoryRole, RoleRepository>();
|
||||||
|
builder.Services.AddScoped<IRepositoryUtilisateur, UtilisateurRepository>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AddServices(this WebApplicationBuilder builder)
|
||||||
|
{
|
||||||
|
builder.Services.AddScoped<IServiceService, ServiceService >();
|
||||||
|
builder.Services.AddScoped<IRoleService, RoleService>();
|
||||||
|
builder.Services.AddScoped<ISiteService, SiteService>();
|
||||||
|
builder.Services.AddScoped<ISalarieService, SalarieService>();
|
||||||
|
builder.Services.AddScoped<IUtilisateurService, UtilisateurService>();
|
||||||
|
builder.Services.AddScoped<IJwtService, JwtService>();
|
||||||
|
builder.Services.AddSingleton<IRsaKeyService, RsaKeyService>();
|
||||||
|
builder.Services.AddValidatorsFromAssemblyContaining<Program>();
|
||||||
|
builder.Services.AddFluentValidationAutoValidation();
|
||||||
|
}
|
||||||
|
public static void AddEFCoreConfiguration(this WebApplicationBuilder builder)
|
||||||
|
{
|
||||||
|
string connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
|
||||||
|
builder.Services.AddDbContext<PgContext>(options => options.UseNpgsql(connectionString));
|
||||||
|
}
|
||||||
|
public static void CorseConfiguration(this WebApplicationBuilder builder)
|
||||||
|
{
|
||||||
|
builder.Services.AddCors(options =>
|
||||||
|
{
|
||||||
|
options.AddPolicy("AllowSpecific",
|
||||||
|
builder => builder
|
||||||
|
.WithOrigins("http://localhost:3000")
|
||||||
|
.AllowAnyMethod()
|
||||||
|
.AllowAnyHeader());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AddSerilog(this WebApplicationBuilder builder)
|
||||||
|
{
|
||||||
|
var loggerConfiguration = new LoggerConfiguration()
|
||||||
|
.WriteTo.Console()
|
||||||
|
.WriteTo.File("logs/log.txt", rollingInterval: RollingInterval.Hour);
|
||||||
|
var logger = loggerConfiguration.CreateLogger();
|
||||||
|
builder.Logging.AddSerilog(logger);
|
||||||
|
builder.Services.AddLogging();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AddJwt(this WebApplicationBuilder builder)
|
||||||
|
{
|
||||||
|
var rsaKeyService = builder.Services.BuildServiceProvider().GetRequiredService<IRsaKeyService>();
|
||||||
|
var rsaKey = rsaKeyService.GetRsaKey();
|
||||||
|
|
||||||
|
builder.Services.AddAuthentication(options =>
|
||||||
|
{
|
||||||
|
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||||
|
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||||
|
})
|
||||||
|
.AddJwtBearer(options =>
|
||||||
|
{
|
||||||
|
options.TokenValidationParameters = new TokenValidationParameters
|
||||||
|
{
|
||||||
|
ValidateIssuer = true,
|
||||||
|
ValidateAudience = true,
|
||||||
|
ValidateLifetime = true,
|
||||||
|
ValidateIssuerSigningKey = true,
|
||||||
|
ValidIssuer = builder.Configuration["Jwt:Issuer"],
|
||||||
|
ValidAudience = builder.Configuration["Jwt:Audience"],
|
||||||
|
IssuerSigningKey = new RsaSecurityKey(rsaKey)
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void AddSwagger(this WebApplicationBuilder builder)
|
||||||
|
{
|
||||||
|
// Add services to the container.
|
||||||
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||||
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
|
builder.Services.AddAuthorization();
|
||||||
|
builder.Configuration.AddEnvironmentVariables();
|
||||||
|
builder.Services.AddSwaggerGen(c =>
|
||||||
|
{
|
||||||
|
c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
|
||||||
|
{
|
||||||
|
Name = "Authorization",
|
||||||
|
In = ParameterLocation.Header,
|
||||||
|
Type = SecuritySchemeType.ApiKey,
|
||||||
|
Scheme = "Bearer",
|
||||||
|
Description = "JWT Token. Use \"Bearer {token}\""
|
||||||
|
});
|
||||||
|
c.AddSecurityRequirement(new OpenApiSecurityRequirement
|
||||||
|
{
|
||||||
|
{
|
||||||
|
new OpenApiSecurityScheme
|
||||||
|
{
|
||||||
|
Reference = new OpenApiReference
|
||||||
|
{
|
||||||
|
Id = "Bearer",
|
||||||
|
Type = ReferenceType.SecurityScheme
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new List<string>()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
c.SwaggerDoc("v1", new OpenApiInfo
|
||||||
|
{
|
||||||
|
Title = "LDAP - Backend",
|
||||||
|
Version = "v1"
|
||||||
|
});
|
||||||
|
var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
|
||||||
|
c.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
135
ldap-cesi/Context/PgContext.cs
Normal file
135
ldap-cesi/Context/PgContext.cs
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using ldap_cesi.Entities;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Context;
|
||||||
|
|
||||||
|
public partial class PgContext : DbContext
|
||||||
|
{
|
||||||
|
public PgContext()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public PgContext(DbContextOptions<PgContext> options)
|
||||||
|
: base(options)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual DbSet<Role> Roles { get; set; }
|
||||||
|
|
||||||
|
public virtual DbSet<Salarie> Salaries { get; set; }
|
||||||
|
|
||||||
|
public virtual DbSet<Service> Services { get; set; }
|
||||||
|
|
||||||
|
public virtual DbSet<Site> Sites { get; set; }
|
||||||
|
|
||||||
|
public virtual DbSet<Utilisateur> Utilisateurs { get; set; }
|
||||||
|
|
||||||
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
modelBuilder.Entity<Role>(entity =>
|
||||||
|
{
|
||||||
|
entity.HasKey(e => e.Id).HasName("role_pk");
|
||||||
|
|
||||||
|
entity.ToTable("role");
|
||||||
|
|
||||||
|
entity.Property(e => e.Id).HasColumnName("id");
|
||||||
|
entity.Property(e => e.Nom)
|
||||||
|
.HasMaxLength(50)
|
||||||
|
.HasColumnName("nom");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity<Salarie>(entity =>
|
||||||
|
{
|
||||||
|
entity.HasKey(e => e.Id).HasName("salarie_pk");
|
||||||
|
|
||||||
|
entity.ToTable("salarie");
|
||||||
|
|
||||||
|
entity.Property(e => e.Id).HasColumnName("id");
|
||||||
|
entity.Property(e => e.Email)
|
||||||
|
.HasMaxLength(50)
|
||||||
|
.HasColumnName("email");
|
||||||
|
entity.Property(e => e.IdService).HasColumnName("id_service");
|
||||||
|
entity.Property(e => e.IdSite).HasColumnName("id_site");
|
||||||
|
entity.Property(e => e.Nom)
|
||||||
|
.HasMaxLength(50)
|
||||||
|
.HasColumnName("nom");
|
||||||
|
entity.Property(e => e.Prenom)
|
||||||
|
.HasMaxLength(50)
|
||||||
|
.HasColumnName("prenom");
|
||||||
|
entity.Property(e => e.TelephoneFixe)
|
||||||
|
.HasMaxLength(50)
|
||||||
|
.HasColumnName("telephone_fixe");
|
||||||
|
entity.Property(e => e.TelephonePortable)
|
||||||
|
.HasMaxLength(50)
|
||||||
|
.HasColumnName("telephone_portable");
|
||||||
|
|
||||||
|
entity.HasOne(d => d.IdServiceNavigation).WithMany(p => p.Salaries)
|
||||||
|
.HasForeignKey(d => d.IdService)
|
||||||
|
.OnDelete(DeleteBehavior.ClientSetNull)
|
||||||
|
.HasConstraintName("salarie_service0_fk");
|
||||||
|
|
||||||
|
entity.HasOne(d => d.IdSiteNavigation).WithMany(p => p.Salaries)
|
||||||
|
.HasForeignKey(d => d.IdSite)
|
||||||
|
.OnDelete(DeleteBehavior.ClientSetNull)
|
||||||
|
.HasConstraintName("salarie_site_fk");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity<Service>(entity =>
|
||||||
|
{
|
||||||
|
entity.HasKey(e => e.Id).HasName("service_pk");
|
||||||
|
|
||||||
|
entity.ToTable("service");
|
||||||
|
|
||||||
|
entity.Property(e => e.Id).HasColumnName("id");
|
||||||
|
entity.Property(e => e.Nom)
|
||||||
|
.HasMaxLength(50)
|
||||||
|
.HasColumnName("nom");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity<Site>(entity =>
|
||||||
|
{
|
||||||
|
entity.HasKey(e => e.Id).HasName("site_pk");
|
||||||
|
|
||||||
|
entity.ToTable("site");
|
||||||
|
|
||||||
|
entity.Property(e => e.Id).HasColumnName("id");
|
||||||
|
entity.Property(e => e.Ville)
|
||||||
|
.HasMaxLength(150)
|
||||||
|
.HasColumnName("ville");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity<Utilisateur>(entity =>
|
||||||
|
{
|
||||||
|
entity.HasKey(e => e.Id).HasName("utilisateur_pk");
|
||||||
|
|
||||||
|
entity.ToTable("utilisateur");
|
||||||
|
|
||||||
|
entity.Property(e => e.Id).HasColumnName("id");
|
||||||
|
entity.Property(e => e.IdRole).HasColumnName("id_role");
|
||||||
|
entity.Property(e => e.MotDePasse)
|
||||||
|
.HasMaxLength(50)
|
||||||
|
.HasColumnName("mot_de_passe");
|
||||||
|
entity.Property(e => e.Nom)
|
||||||
|
.HasMaxLength(50)
|
||||||
|
.HasColumnName("nom");
|
||||||
|
entity.Property(e => e.Email)
|
||||||
|
.HasMaxLength(50)
|
||||||
|
.HasColumnName("email");
|
||||||
|
entity.Property(e => e.Prenom)
|
||||||
|
.HasMaxLength(50)
|
||||||
|
.HasColumnName("prenom");
|
||||||
|
entity.Ignore(e => e.AccessToken);
|
||||||
|
|
||||||
|
entity.HasOne(d => d.IdRoleNavigation).WithMany(p => p.Utilisateurs)
|
||||||
|
.HasForeignKey(d => d.IdRole)
|
||||||
|
.OnDelete(DeleteBehavior.ClientSetNull)
|
||||||
|
.HasConstraintName("utilisateur_role_fk");
|
||||||
|
});
|
||||||
|
|
||||||
|
OnModelCreatingPartial(modelBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
|
||||||
|
}
|
22
ldap-cesi/Controllers/HashController.cs
Normal file
22
ldap-cesi/Controllers/HashController.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Controllers;
|
||||||
|
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
public class HashController : ControllerBase
|
||||||
|
{
|
||||||
|
[HttpPost("hash")]
|
||||||
|
public IActionResult HashString([FromBody] string StringToHash)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(StringToHash))
|
||||||
|
{
|
||||||
|
return BadRequest("Vous devez fournir une chaine de caractere pour la hasher.");
|
||||||
|
}
|
||||||
|
|
||||||
|
string hashedString = BCrypt.Net.BCrypt.HashPassword(StringToHash);
|
||||||
|
|
||||||
|
return Ok(new { HashedString = hashedString });
|
||||||
|
}
|
||||||
|
}
|
29
ldap-cesi/Controllers/JwtController.cs
Normal file
29
ldap-cesi/Controllers/JwtController.cs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
using ldap_cesi.Services.Interfaces;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Controllers;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("/api/jwt")]
|
||||||
|
public class JwtController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly IJwtService _jwtService;
|
||||||
|
|
||||||
|
public JwtController(IJwtService jwtService)
|
||||||
|
{
|
||||||
|
_jwtService = jwtService;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("public-key")]
|
||||||
|
public IActionResult GetPublicKey()
|
||||||
|
{
|
||||||
|
var publicKey = _jwtService.GetPublicKey();
|
||||||
|
if (string.IsNullOrEmpty(publicKey))
|
||||||
|
{
|
||||||
|
return BadRequest("Impossible de récupérer la clé publique");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Ok(publicKey);
|
||||||
|
}
|
||||||
|
}
|
88
ldap-cesi/Controllers/RoleController.cs
Normal file
88
ldap-cesi/Controllers/RoleController.cs
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using ldap_cesi.DTOs.Inputs.Role;
|
||||||
|
using ldap_cesi.Services.Interfaces;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Controllers
|
||||||
|
{
|
||||||
|
[Route("api/[controller]")]
|
||||||
|
[ApiController]
|
||||||
|
public class RoleController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly IRoleService _roleService;
|
||||||
|
|
||||||
|
public RoleController(IRoleService roleService)
|
||||||
|
{
|
||||||
|
_roleService = roleService;
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: api/Role
|
||||||
|
/// <summary>
|
||||||
|
/// Endpoint qui retourne tous les rôles
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Un tableau de rôle</returns>
|
||||||
|
[HttpGet]
|
||||||
|
[Authorize(Roles = "admin")]
|
||||||
|
public async Task<IActionResult> GetAllRoles([FromQuery] int pageNumber = 1, [FromQuery] int pageSize = 10)
|
||||||
|
{
|
||||||
|
var result = await _roleService.GetAll(pageNumber, pageSize);
|
||||||
|
return result.Success ? Ok(result) : BadRequest(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: api/Role/{id}
|
||||||
|
/// <summary>
|
||||||
|
/// Endpoint qui retourne le role
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">L'id du rôle.</param>
|
||||||
|
/// <returns>Le role update</returns>
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
[Authorize(Roles = "admin")]
|
||||||
|
public async Task<IActionResult> GetRoleById(int id)
|
||||||
|
{
|
||||||
|
var result = await _roleService.GetById(id);
|
||||||
|
return result.Success ? Ok(result) : BadRequest(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST: api/Role
|
||||||
|
/// <summary>
|
||||||
|
/// Endpoint créer le Role
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="CreateRoleInput">Le nom du rôle.</param>
|
||||||
|
/// <returns>Response.</returns>
|
||||||
|
[HttpPost]
|
||||||
|
[Authorize(Roles = "admin")]
|
||||||
|
public async Task<IActionResult> CreateRole([FromBody] RoleCreateDto roleDto)
|
||||||
|
{
|
||||||
|
var result = await _roleService.Create(roleDto);
|
||||||
|
return result.Success ? Ok(result) : BadRequest(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
// PUT: api/Role
|
||||||
|
/// <summary>
|
||||||
|
/// Endpoint qui met à jour un role.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="roleUpdateDto">Les informations du role à mettre à jour. Id, nom</param>
|
||||||
|
/// <returns>Le role mis à jour.</returns>
|
||||||
|
[HttpPut]
|
||||||
|
[Authorize(Roles = "admin")]
|
||||||
|
public async Task<IActionResult> UpdateRole([FromBody] RoleUpdateDto roleDto)
|
||||||
|
{
|
||||||
|
var result = await _roleService.Update(roleDto);
|
||||||
|
return result.Success ? Ok(result) : BadRequest(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
// DELETE: api/Role/{id}
|
||||||
|
/// <summary>
|
||||||
|
/// Endpoint qui supprime un rôle.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">L'ID du rôle à supprimer.</param>
|
||||||
|
/// <returns>Un message de confirmation de suppression.</returns>
|
||||||
|
[HttpDelete("{id}")]
|
||||||
|
[Authorize(Roles = "admin")]
|
||||||
|
public async Task<IActionResult> DeleteRole(int id)
|
||||||
|
{
|
||||||
|
var result = await _roleService.Delete(id);
|
||||||
|
return result.Success ? Ok(result) : BadRequest(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
146
ldap-cesi/Controllers/SalarieController.cs
Normal file
146
ldap-cesi/Controllers/SalarieController.cs
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
using ldap_cesi.DTOs.Inputs.Salarie;
|
||||||
|
using ldap_cesi.DTOs.Inputs.Service;
|
||||||
|
using ldap_cesi.Services.Interfaces;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Controllers;
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/salaries")]
|
||||||
|
public class SalarieController : ControllerBase
|
||||||
|
{
|
||||||
|
private ISalarieService _salarieService;
|
||||||
|
|
||||||
|
public SalarieController(ISalarieService salarieService)
|
||||||
|
{
|
||||||
|
_salarieService = salarieService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Endpoint qui retourne tous les salariés.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Une liste de salariés.</returns>
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<IActionResult> GetAllSalaries([FromQuery] int pageNumber = 1, [FromQuery] int pageSize = 25)
|
||||||
|
{
|
||||||
|
var result = await _salarieService.GetAll(pageNumber, pageSize);
|
||||||
|
return result.Success ? Ok(result) : BadRequest(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[HttpGet("search")]
|
||||||
|
public async Task<IActionResult> SearchSalaries(
|
||||||
|
[FromQuery] string searchTerm,
|
||||||
|
[FromQuery] int pageNumber = 1,
|
||||||
|
[FromQuery] int pageSize = 10)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(searchTerm) || searchTerm.Length < 2)
|
||||||
|
{
|
||||||
|
return BadRequest("Votre recherche doit contenir au moins deux caractères.");
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = await _salarieService.SearchWithRelations(
|
||||||
|
searchTerm, pageNumber, pageSize, s => s.IdServiceNavigation, s => s.IdSiteNavigation);
|
||||||
|
|
||||||
|
return result.Success ? Ok(result) : BadRequest(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Endpoint qui retourne le salarié correspondant à l'ID en paramètre.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">L'ID du salarié.</param>
|
||||||
|
/// <returns>Le salarié correspondant à l'ID.</returns>
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
public async Task<IActionResult> GetById(int id)
|
||||||
|
{
|
||||||
|
var result = await _salarieService.GetById(id);
|
||||||
|
return result.Success ? Ok(result) : BadRequest(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Endpoint qui retourne le salarié correspondant à l'ID en paramètre. Avec le nom de service et de site auxquels il apaprtient.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">L'ID du salarié.</param>
|
||||||
|
/// <returns>Le salarié correspondant à l'ID. Ainsi que son service et son site</returns>
|
||||||
|
[HttpGet("/complet/{id}")]
|
||||||
|
public async Task<IActionResult> GetSalarieCompletById(int id)
|
||||||
|
{
|
||||||
|
var result = await _salarieService.GetByIdWithRelations(id,s => s.IdServiceNavigation, s => s.IdSiteNavigation);
|
||||||
|
return result.Success ? Ok(result) : BadRequest(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Endpoint qui retourne tout les salariés et les relations qu'il détient
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Tous les salariés avec leurs relations</returns>
|
||||||
|
[HttpGet("all")]
|
||||||
|
public async Task<IActionResult> GetAllSariesWithRelations([FromQuery] int pageNumber = 1, [FromQuery] int pageSize = 25)
|
||||||
|
{
|
||||||
|
var result = await _salarieService.GetAllWithRelationsAsync(pageNumber, pageSize,s => s.IdServiceNavigation, s => s.IdSiteNavigation);
|
||||||
|
return result.Success ? Ok(result) : BadRequest(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Endpoint qui crée un salarié.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="salarieInput">Les informations du salarié à créer.</param>
|
||||||
|
/// <returns>Le salarié créé.</returns>
|
||||||
|
[HttpPost]
|
||||||
|
[Authorize(Roles = "admin")]
|
||||||
|
public async Task<IActionResult> CreateSalarie([FromBody] SalarieCreateDto salarieInput)
|
||||||
|
{
|
||||||
|
var result = await _salarieService.Create(salarieInput);
|
||||||
|
return result.Success ? Ok(result) : BadRequest(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Endpoint qui met à jour un salarié.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="salarieInput">Les informations du salarié à mettre à jour.</param>
|
||||||
|
/// <returns>Le salarié mis à jour.</returns>
|
||||||
|
[HttpPut]
|
||||||
|
[Authorize(Roles = "admin")]
|
||||||
|
public async Task<IActionResult> UpdateSalarie([FromBody] SalarieUpdateDto salarieInput)
|
||||||
|
{
|
||||||
|
var result = await _salarieService.Update(salarieInput);
|
||||||
|
return result.Success ? Ok(result) : BadRequest(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Endpoint qui supprime un salarié.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">L'ID du salarié à supprimer.</param>
|
||||||
|
/// <returns>Un message de confirmation de suppression.</returns>
|
||||||
|
[HttpDelete("{id}")]
|
||||||
|
[Authorize(Roles = "admin")]
|
||||||
|
public async Task<IActionResult> DeleteSalarie(int id)
|
||||||
|
{
|
||||||
|
var result = await _salarieService.Delete(id);
|
||||||
|
return result.Success ? Ok(result) : BadRequest(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Récupère les salariés appartenant à un site spécifique
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="siteId">Identifiant du site</param>
|
||||||
|
/// <returns>Liste des salariés du site</returns>
|
||||||
|
[HttpGet("site/{siteId}")]
|
||||||
|
public async Task<IActionResult> GetSalariesBySite(int siteId)
|
||||||
|
{
|
||||||
|
var result = await _salarieService.GetSalariesBySite(siteId);
|
||||||
|
return result.Success ? Ok(result) : NotFound(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Récupère les salariés appartenant à un service spécifique
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="serviceId">Identifiant du service</param>
|
||||||
|
/// <returns>Liste des salariés du service</returns>
|
||||||
|
[HttpGet("service/{serviceId}")]
|
||||||
|
public async Task<IActionResult> GetSalariesByService(int serviceId)
|
||||||
|
{
|
||||||
|
var result = await _salarieService.GetSalariesByService(serviceId);
|
||||||
|
return result.Success ? Ok(result) : NotFound(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
91
ldap-cesi/Controllers/ServicesController.cs
Normal file
91
ldap-cesi/Controllers/ServicesController.cs
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
using ldap_cesi.DTOs.Inputs.Service;
|
||||||
|
using ldap_cesi.Services.Interfaces;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Controllers;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/services")]
|
||||||
|
public class ServicesController : ControllerBase
|
||||||
|
{
|
||||||
|
private IServiceService _serviceService;
|
||||||
|
|
||||||
|
public ServicesController(IServiceService serviceService)
|
||||||
|
{
|
||||||
|
_serviceService = serviceService;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Endpoint qui retourne tous les services.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Retourne tous les services.</returns>
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<IActionResult> GetServices([FromQuery] int pageNumber = 1, [FromQuery] int pageSize = 10) {
|
||||||
|
var result = await _serviceService.GetAll(pageNumber, pageSize);
|
||||||
|
return result.Success ? Ok(result) : BadRequest(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Endpoint qui retourne le service correspondant à l'id en paramètre.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">L'ID du service.</param>
|
||||||
|
/// <returns>Le service correspondant à l'ID.</returns>
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
public async Task<IActionResult> GetServiceById(int id)
|
||||||
|
{
|
||||||
|
var result = await _serviceService.GetById(id);
|
||||||
|
return result.Success ? Ok(result) : BadRequest(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Endpoint qui retourne le service et ses salariés correspondant à l'id en paramètre.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">L'ID du service.</param>
|
||||||
|
/// <returns>Le service correspondant à l'ID, avec ses salariés</returns>
|
||||||
|
[HttpGet("complete/{id}")]
|
||||||
|
public async Task<IActionResult> GetServiceByIdWithSalaries(int id)
|
||||||
|
{
|
||||||
|
var result = await _serviceService.GetByIdWithRelations(id, s=>s.Salaries);
|
||||||
|
return result.Success ? Ok(result) : BadRequest(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Endpoint qui crée un service.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="serviceInputDto">Les informations du service à créer.</param>
|
||||||
|
/// <returns>Le service créé.</returns>
|
||||||
|
[HttpPost]
|
||||||
|
[Authorize(Roles = "admin")]
|
||||||
|
public async Task<IActionResult> CreateService([FromBody] ServiceCreateDto serviceInputDto)
|
||||||
|
{
|
||||||
|
var result = await _serviceService.Create(serviceInputDto);
|
||||||
|
return result.Success ? Ok(result.Data) : BadRequest(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Endpoint qui met à jour un service.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="serviceUpdateDto">Les informations du service à mettre à jour.</param>
|
||||||
|
/// <returns>Le service mis à jour.</returns>
|
||||||
|
[HttpPut]
|
||||||
|
[Authorize(Roles = "admin")]
|
||||||
|
public async Task<IActionResult> UpdateService([FromBody] ServiceUpdateDto serviceUpdateDto)
|
||||||
|
{
|
||||||
|
var result = await _serviceService.Update(serviceUpdateDto);
|
||||||
|
return result.Success ? Ok(result) : BadRequest(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Endpoint qui supprime un service.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">L'ID du service à supprimer.</param>
|
||||||
|
/// <returns>Un message de confirmation de suppression.</returns>
|
||||||
|
[HttpDelete("{id}")]
|
||||||
|
[Authorize(Roles = "admin")]
|
||||||
|
public async Task<IActionResult> DeleteService(int id)
|
||||||
|
{
|
||||||
|
var result = await _serviceService.DeleteWithEntiteCheck(id);
|
||||||
|
return result.Success ? Ok(result) : BadRequest(result);
|
||||||
|
}
|
||||||
|
}
|
101
ldap-cesi/Controllers/SiteController.cs
Normal file
101
ldap-cesi/Controllers/SiteController.cs
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
using ldap_cesi.DTOs.Inputs.Site;
|
||||||
|
using ldap_cesi.Services.Interfaces;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Controllers;
|
||||||
|
|
||||||
|
[ApiController]
|
||||||
|
[Route("/api/sites")]
|
||||||
|
public class SiteController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly ISiteService _siteService;
|
||||||
|
|
||||||
|
public SiteController(ISiteService siteService)
|
||||||
|
{
|
||||||
|
_siteService = siteService;
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: api/site
|
||||||
|
/// <summary>
|
||||||
|
/// Récupère la liste de tous les sites.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Retourne une liste de tous les sites.</returns>
|
||||||
|
[HttpGet]
|
||||||
|
public async Task<ActionResult> GetSites([FromQuery] int pageNumber = 1, [FromQuery] int pageSize = 10)
|
||||||
|
{
|
||||||
|
var result = await _siteService.GetAll(pageNumber, pageSize);
|
||||||
|
return result.Success ? Ok(result) : BadRequest(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: api/site/{id}
|
||||||
|
/// <summary>
|
||||||
|
/// Récupère un site spécifique par son identifiant.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">L'identifiant du site à récupérer.</param>
|
||||||
|
/// <returns>Retourne le site correspondant à l'identifiant.</returns>
|
||||||
|
/// <response code="200">Le site a été récupéré avec succès.</response>
|
||||||
|
/// <response code="400">Une erreur s'est produite lors de la récupération du site.</response>
|
||||||
|
/// <response code="404">Le site n'a pas été trouvé.</response>
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
public async Task<ActionResult> GetSite(int id)
|
||||||
|
{
|
||||||
|
var result = await _siteService.GetById(id);
|
||||||
|
return result.Success ? Ok(result) : BadRequest(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
// GET: api/site/{id}
|
||||||
|
/// <summary>
|
||||||
|
/// Récupère un site et ses salariés spécifique par son identifiant.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">L'identifiant du site à récupérer.</param>
|
||||||
|
/// <returns>Retourne le site et ses salariés</returns>
|
||||||
|
[HttpGet("/complete/{id}")]
|
||||||
|
public async Task<ActionResult> GetSiteWithClient(int id)
|
||||||
|
{
|
||||||
|
var result = await _siteService.GetByIdWithRelations(id, s => s.Salaries);
|
||||||
|
return result.Success ? Ok(result) : BadRequest(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
// POST: api/site
|
||||||
|
/// <summary>
|
||||||
|
/// Crée un nouveau site.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="siteCreateDto">Les données du site à créer.</param>
|
||||||
|
/// <returns>Retourne l'identifiant du site créé.</returns>
|
||||||
|
[HttpPost]
|
||||||
|
[Authorize(Roles = "admin")]
|
||||||
|
public async Task<ActionResult> CreateSite([FromBody] SiteCreateDto siteCreateDto)
|
||||||
|
{
|
||||||
|
var result = await _siteService.Create(siteCreateDto);
|
||||||
|
return result.Success ? Ok(result) : BadRequest(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
// PUT: api/site
|
||||||
|
/// <summary>
|
||||||
|
/// Met à jour un site existant.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="siteUpdateDto">Les données du site à mettre à jour.</param>
|
||||||
|
/// <returns>Retourne l'objet ou une erreur.</returns>
|
||||||
|
[HttpPut]
|
||||||
|
[Authorize(Roles = "admin")]
|
||||||
|
public async Task<IActionResult> UpdateSite([FromBody] SiteUpdateDto siteUpdateDto)
|
||||||
|
{
|
||||||
|
var result = await _siteService.Update(siteUpdateDto);
|
||||||
|
return result.Success ? Ok(result) : BadRequest(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
// DELETE: api/site/{id}
|
||||||
|
/// <summary>
|
||||||
|
/// Supprime un site par son identifiant.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">L'identifiant du site à supprimer.</param>
|
||||||
|
/// <returns>Retourne l'id, ou l'erreur</returns>
|
||||||
|
[HttpDelete("{id}")]
|
||||||
|
[Authorize(Roles = "admin")]
|
||||||
|
public async Task<IActionResult> DeleteSite(int id)
|
||||||
|
{
|
||||||
|
var result = await _siteService.DeleteWithEntiteCheck(id);
|
||||||
|
return result.Success ? Ok(result) : BadRequest(result);
|
||||||
|
}
|
||||||
|
}
|
131
ldap-cesi/Controllers/UtilisateurController.cs
Normal file
131
ldap-cesi/Controllers/UtilisateurController.cs
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
using System.Security.Claims;
|
||||||
|
using ldap_cesi.DTOs.Inputs;
|
||||||
|
using ldap_cesi.Services.Interfaces;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Controllers;
|
||||||
|
[ApiController]
|
||||||
|
[Route("api/utilisateurs")]
|
||||||
|
public class UtilisateurController : ControllerBase
|
||||||
|
{
|
||||||
|
private readonly IUtilisateurService _utilisateurService;
|
||||||
|
private readonly IJwtService _jwtService;
|
||||||
|
public UtilisateurController(IUtilisateurService utilisateurService, IJwtService jwtService)
|
||||||
|
{
|
||||||
|
_utilisateurService = utilisateurService;
|
||||||
|
_jwtService = jwtService;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Endpoint pour la connexion des utilisateurs.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="utilisateurInput">Les informations de connexion de l'utilisateur.</param>
|
||||||
|
/// <returns>Un token JWT si la connexion est réussie.</returns>
|
||||||
|
[HttpPost("login")]
|
||||||
|
public async Task<IActionResult> Login([FromBody] UtilisateurLoginDto utilisateurInput)
|
||||||
|
{
|
||||||
|
var result = await _utilisateurService.Login(utilisateurInput);
|
||||||
|
return result.Success ? Ok(result) : BadRequest(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("me")]
|
||||||
|
[Authorize]
|
||||||
|
public async Task<IActionResult> GetCurrentUser()
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
// rçupère tous les claims de type NameIdentifier
|
||||||
|
var nameIdClaims = User.FindAll(ClaimTypes.NameIdentifier).ToList();
|
||||||
|
|
||||||
|
// cherche le claim qui contient un nombre entier
|
||||||
|
int userId = 0;
|
||||||
|
bool foundValidId = false;
|
||||||
|
|
||||||
|
foreach (var claim in nameIdClaims)
|
||||||
|
{
|
||||||
|
if (int.TryParse(claim.Value, out userId))
|
||||||
|
{
|
||||||
|
foundValidId = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!foundValidId)
|
||||||
|
{
|
||||||
|
return BadRequest(new {
|
||||||
|
Success = false,
|
||||||
|
Message = "Utilisateur non identifié. Aucun ID numérique trouvé."
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// rçupère les informations utilisateur
|
||||||
|
var result = await _utilisateurService.GetById(userId);
|
||||||
|
return result.Success ? Ok(result) : BadRequest(result);
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
return BadRequest(new { Success = false, Message = $"Erreur: {ex.Message}" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Endpoint pour déconnecter un utilisateur (invalider son token).
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Un statut indiquant que la déconnexion a réussi.</returns>
|
||||||
|
[HttpPost("logout")]
|
||||||
|
[Authorize]
|
||||||
|
public async Task<IActionResult> Logout()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var authHeader = Request.Headers["Authorization"].ToString();
|
||||||
|
if (string.IsNullOrEmpty(authHeader) || !authHeader.StartsWith("Bearer "))
|
||||||
|
{
|
||||||
|
return BadRequest(new { Success = false, Message = "Token non fourni" });
|
||||||
|
}
|
||||||
|
|
||||||
|
var token = authHeader.Substring("Bearer ".Length).Trim();
|
||||||
|
|
||||||
|
// rendre le tokenm invalide
|
||||||
|
var result = await _jwtService.InvalidateToken(token);
|
||||||
|
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
return Ok(new { Success = true, Message = "Déconnexion réussie" });
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return BadRequest(new { Success = false, Message = "Échec de la déconnexion" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return StatusCode(500, new { Success = false, Message = "Erreur interne du serveur" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Endpoint pour récupérer tous les utilisateurs.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Une liste d'utilisateurs.</returns>
|
||||||
|
[HttpGet]
|
||||||
|
[Authorize(Roles = "admin")]
|
||||||
|
public async Task<IActionResult> GetUtilisateurs()
|
||||||
|
{
|
||||||
|
var result = await _utilisateurService.GetAll();
|
||||||
|
return result.Success ? Ok(result) : BadRequest(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Endpoint pour récupérer un utilisateur par son ID.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="id">L'ID de l'utilisateur.</param>
|
||||||
|
/// <returns>L'utilisateur correspondant à l'ID.</returns>
|
||||||
|
[HttpGet("{id}")]
|
||||||
|
[Authorize(Roles = "admin")]
|
||||||
|
public async Task<IActionResult> GetUtilisateurById(int id)
|
||||||
|
{
|
||||||
|
var result = await _utilisateurService.GetById(id);
|
||||||
|
return result.Success ? Ok(result) : BadRequest(result);
|
||||||
|
}
|
||||||
|
}
|
8
ldap-cesi/DTOs/Generic/RoleDto.cs
Normal file
8
ldap-cesi/DTOs/Generic/RoleDto.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
namespace ldap_cesi.DTOs;
|
||||||
|
|
||||||
|
public class RoleDto
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public string Nom { get; set; }
|
||||||
|
}
|
19
ldap-cesi/DTOs/Generic/SalarieDto.cs
Normal file
19
ldap-cesi/DTOs/Generic/SalarieDto.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
namespace ldap_cesi.DTOs;
|
||||||
|
|
||||||
|
public class SalarieDto
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public string Nom { get; set; } = null!;
|
||||||
|
|
||||||
|
public string Prenom { get; set; } = null!;
|
||||||
|
|
||||||
|
public string TelephoneFixe { get; set; } = null!;
|
||||||
|
|
||||||
|
public string TelephonePortable { get; set; } = null!;
|
||||||
|
|
||||||
|
public string Email { get; set; } = null!;
|
||||||
|
|
||||||
|
public ServiceDto Service { get; set; }
|
||||||
|
public SiteDto Site { get; set; }
|
||||||
|
}
|
11
ldap-cesi/DTOs/Generic/ServiceDto.cs
Normal file
11
ldap-cesi/DTOs/Generic/ServiceDto.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
using ldap_cesi.DTOs.Outputs.Salarie;
|
||||||
|
|
||||||
|
namespace ldap_cesi.DTOs;
|
||||||
|
|
||||||
|
public class ServiceDto
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public string Nom { get; set; }
|
||||||
|
public List<SalarieMinimalDto> Salaries { get; set; }
|
||||||
|
}
|
11
ldap-cesi/DTOs/Generic/SiteDto.cs
Normal file
11
ldap-cesi/DTOs/Generic/SiteDto.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
using ldap_cesi.DTOs.Outputs.Salarie;
|
||||||
|
|
||||||
|
namespace ldap_cesi.DTOs;
|
||||||
|
|
||||||
|
public class SiteDto
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public string Ville { get; set; }
|
||||||
|
public ICollection<SalarieMinimalDto> Salaries { get; set; }
|
||||||
|
}
|
7
ldap-cesi/DTOs/Inputs/Role/RoleCreateDto.cs
Normal file
7
ldap-cesi/DTOs/Inputs/Role/RoleCreateDto.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
namespace ldap_cesi.DTOs.Inputs.Role;
|
||||||
|
|
||||||
|
public class RoleCreateDto
|
||||||
|
{
|
||||||
|
public string Nom { get; set; }
|
||||||
|
}
|
7
ldap-cesi/DTOs/Inputs/Role/RoleUpdateDto.cs
Normal file
7
ldap-cesi/DTOs/Inputs/Role/RoleUpdateDto.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace ldap_cesi.DTOs.Inputs.Role;
|
||||||
|
|
||||||
|
public class RoleUpdateDto
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Nom { get; set; }
|
||||||
|
}
|
12
ldap-cesi/DTOs/Inputs/Salarie/SalarieCreateDto.cs
Normal file
12
ldap-cesi/DTOs/Inputs/Salarie/SalarieCreateDto.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
namespace ldap_cesi.DTOs.Inputs.Salarie;
|
||||||
|
|
||||||
|
public class SalarieCreateDto
|
||||||
|
{
|
||||||
|
public string Nom { get; set; }
|
||||||
|
public string Prenom { get; set; }
|
||||||
|
public string TelephoneFixe { get; set; }
|
||||||
|
public string TelephonePortable { get; set; }
|
||||||
|
public string Email { get; set; }
|
||||||
|
public int IdSite { get; set; }
|
||||||
|
public int IdService { get; set; }
|
||||||
|
}
|
20
ldap-cesi/DTOs/Inputs/Salarie/SalarieUpdateDto.cs
Normal file
20
ldap-cesi/DTOs/Inputs/Salarie/SalarieUpdateDto.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
namespace ldap_cesi.DTOs.Inputs.Service;
|
||||||
|
|
||||||
|
public class SalarieUpdateDto
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public string Nom { get; set; } = null!;
|
||||||
|
|
||||||
|
public string Prenom { get; set; } = null!;
|
||||||
|
|
||||||
|
public string TelephoneFixe { get; set; } = null!;
|
||||||
|
|
||||||
|
public string TelephonePortable { get; set; } = null!;
|
||||||
|
|
||||||
|
public string Email { get; set; } = null!;
|
||||||
|
|
||||||
|
public int IdSite { get; set; }
|
||||||
|
|
||||||
|
public int IdService { get; set; }
|
||||||
|
}
|
6
ldap-cesi/DTOs/Inputs/Service/ServiceCreateDto.cs
Normal file
6
ldap-cesi/DTOs/Inputs/Service/ServiceCreateDto.cs
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
namespace ldap_cesi.DTOs.Inputs.Service;
|
||||||
|
|
||||||
|
public class ServiceCreateDto
|
||||||
|
{
|
||||||
|
public string Nom { get; set; }
|
||||||
|
}
|
8
ldap-cesi/DTOs/Inputs/Service/ServiceUpdateDto.cs
Normal file
8
ldap-cesi/DTOs/Inputs/Service/ServiceUpdateDto.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
namespace ldap_cesi.DTOs.Inputs.Service;
|
||||||
|
|
||||||
|
public class ServiceUpdateDto
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public string Nom { get; set; } = null!;
|
||||||
|
}
|
6
ldap-cesi/DTOs/Inputs/Site/SiteCreateDto.cs
Normal file
6
ldap-cesi/DTOs/Inputs/Site/SiteCreateDto.cs
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
namespace ldap_cesi.DTOs.Inputs.Site;
|
||||||
|
|
||||||
|
public class SiteCreateDto
|
||||||
|
{
|
||||||
|
public string Ville { get; set; }
|
||||||
|
}
|
9
ldap-cesi/DTOs/Inputs/Site/SiteUpdateDto.cs
Normal file
9
ldap-cesi/DTOs/Inputs/Site/SiteUpdateDto.cs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
namespace ldap_cesi.DTOs.Inputs.Site;
|
||||||
|
|
||||||
|
public class SiteUpdateDto
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public string Ville { get; set; }
|
||||||
|
|
||||||
|
}
|
7
ldap-cesi/DTOs/Inputs/Utilisateur/UtilisateurLoginDto.cs
Normal file
7
ldap-cesi/DTOs/Inputs/Utilisateur/UtilisateurLoginDto.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace ldap_cesi.DTOs.Inputs;
|
||||||
|
|
||||||
|
public class UtilisateurLoginDto
|
||||||
|
{
|
||||||
|
public string Email { get; set; }
|
||||||
|
public string MotDePasse { get; set; }
|
||||||
|
}
|
14
ldap-cesi/DTOs/Outputs/Salarie/SalarieListDto.cs
Normal file
14
ldap-cesi/DTOs/Outputs/Salarie/SalarieListDto.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using ldap_cesi.DTOs.Outputs.Service;
|
||||||
|
|
||||||
|
namespace ldap_cesi.DTOs.Outputs.Salarie;
|
||||||
|
|
||||||
|
public class SalarieListDto
|
||||||
|
{
|
||||||
|
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Nom { get; set; }
|
||||||
|
public string Prenom { get; set; }
|
||||||
|
public string NomComplet => $"{Prenom} {Nom}";
|
||||||
|
public ServiceMinimalDto Service { get; set; }
|
||||||
|
public SiteMinimalDto Site { get; set; }
|
||||||
|
}
|
17
ldap-cesi/DTOs/Outputs/Salarie/SalarieMinimalDto.cs
Normal file
17
ldap-cesi/DTOs/Outputs/Salarie/SalarieMinimalDto.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
namespace ldap_cesi.DTOs.Outputs.Salarie;
|
||||||
|
|
||||||
|
public class SalarieMinimalDto
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public string Nom { get; set; } = null!;
|
||||||
|
|
||||||
|
public string Prenom { get; set; } = null!;
|
||||||
|
|
||||||
|
public string TelephoneFixe { get; set; } = null!;
|
||||||
|
|
||||||
|
public string TelephonePortable { get; set; } = null!;
|
||||||
|
|
||||||
|
public string Email { get; set; } = null!;
|
||||||
|
|
||||||
|
}
|
21
ldap-cesi/DTOs/Outputs/Salarie/SalarieOutputDetail.cs
Normal file
21
ldap-cesi/DTOs/Outputs/Salarie/SalarieOutputDetail.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
using ldap_cesi.DTOs.Outputs.Service;
|
||||||
|
|
||||||
|
namespace ldap_cesi.DTOs.Outputs.Salarie;
|
||||||
|
|
||||||
|
public class SalarieOutputDetail
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public string Nom { get; set; }
|
||||||
|
|
||||||
|
public string Prenom { get; set; }
|
||||||
|
|
||||||
|
public string TelephoneFixe { get; set; }
|
||||||
|
|
||||||
|
public string TelephonePortable { get; set; }
|
||||||
|
|
||||||
|
public string Email { get; set; }
|
||||||
|
|
||||||
|
public ServiceMinimalDto Service { get; set; }
|
||||||
|
public SiteMinimalDto Site { get; set; }
|
||||||
|
}
|
8
ldap-cesi/DTOs/Outputs/Service/ServiceMinimalDto.cs
Normal file
8
ldap-cesi/DTOs/Outputs/Service/ServiceMinimalDto.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
namespace ldap_cesi.DTOs.Outputs.Service;
|
||||||
|
|
||||||
|
public class ServiceMinimalDto
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public string Nom { get; set; }
|
||||||
|
}
|
8
ldap-cesi/DTOs/Outputs/Site/SiteMinimalDto.cs
Normal file
8
ldap-cesi/DTOs/Outputs/Site/SiteMinimalDto.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
namespace ldap_cesi.DTOs.Outputs.Service;
|
||||||
|
|
||||||
|
public class SiteMinimalDto
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public string Ville { get; set; }
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
namespace ldap_cesi.DTOs.Outputs.Utilisateur;
|
||||||
|
|
||||||
|
public class UtilisateurOutputDto
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string Email { get; set; }
|
||||||
|
public string Nom { get; set; }
|
||||||
|
public string RoleNom { get; set; }
|
||||||
|
}
|
13
ldap-cesi/Entities/Role.cs
Normal file
13
ldap-cesi/Entities/Role.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Entities;
|
||||||
|
|
||||||
|
public partial class Role
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public string Nom { get; set; } = null!;
|
||||||
|
|
||||||
|
public virtual ICollection<Utilisateur> Utilisateurs { get; set; } = new List<Utilisateur>();
|
||||||
|
}
|
27
ldap-cesi/Entities/Salarie.cs
Normal file
27
ldap-cesi/Entities/Salarie.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Entities;
|
||||||
|
|
||||||
|
public partial class Salarie
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public string Nom { get; set; } = null!;
|
||||||
|
|
||||||
|
public string Prenom { get; set; } = null!;
|
||||||
|
|
||||||
|
public string TelephoneFixe { get; set; } = null!;
|
||||||
|
|
||||||
|
public string TelephonePortable { get; set; } = null!;
|
||||||
|
|
||||||
|
public string Email { get; set; } = null!;
|
||||||
|
|
||||||
|
public int IdSite { get; set; }
|
||||||
|
|
||||||
|
public int IdService { get; set; }
|
||||||
|
|
||||||
|
public virtual Service IdServiceNavigation { get; set; } = null!;
|
||||||
|
|
||||||
|
public virtual Site IdSiteNavigation { get; set; } = null!;
|
||||||
|
}
|
13
ldap-cesi/Entities/Service.cs
Normal file
13
ldap-cesi/Entities/Service.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Entities;
|
||||||
|
|
||||||
|
public partial class Service
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public string Nom { get; set; } = null!;
|
||||||
|
|
||||||
|
public virtual ICollection<Salarie> Salaries { get; set; } = new List<Salarie>();
|
||||||
|
}
|
13
ldap-cesi/Entities/Site.cs
Normal file
13
ldap-cesi/Entities/Site.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Entities;
|
||||||
|
|
||||||
|
public partial class Site
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public string Ville { get; set; }
|
||||||
|
|
||||||
|
public virtual ICollection<Salarie> Salaries { get; set; } = new List<Salarie>();
|
||||||
|
}
|
22
ldap-cesi/Entities/Utilisateur.cs
Normal file
22
ldap-cesi/Entities/Utilisateur.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Entities;
|
||||||
|
|
||||||
|
public partial class Utilisateur
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
|
||||||
|
public string Nom { get; set; }
|
||||||
|
|
||||||
|
public string Prenom { get; set; }
|
||||||
|
|
||||||
|
public string MotDePasse { get; set; }
|
||||||
|
public string Email { get; set; }
|
||||||
|
|
||||||
|
public int IdRole { get; set; }
|
||||||
|
[NotMapped]
|
||||||
|
public string AccessToken { get; set; }
|
||||||
|
public virtual Role IdRoleNavigation { get; set; } = null!;
|
||||||
|
}
|
55
ldap-cesi/Mapper/AutoMapperProfile.cs
Normal file
55
ldap-cesi/Mapper/AutoMapperProfile.cs
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using ldap_cesi.DTOs;
|
||||||
|
using ldap_cesi.DTOs.Inputs.Role;
|
||||||
|
using ldap_cesi.DTOs.Inputs.Salarie;
|
||||||
|
using ldap_cesi.DTOs.Inputs.Service;
|
||||||
|
using ldap_cesi.DTOs.Inputs.Site;
|
||||||
|
using ldap_cesi.DTOs.Outputs.Salarie;
|
||||||
|
using ldap_cesi.DTOs.Outputs.Service;
|
||||||
|
using ldap_cesi.DTOs.Outputs.Utilisateur;
|
||||||
|
using ldap_cesi.Entities;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Mapper;
|
||||||
|
|
||||||
|
public class AutoMapperProfile : Profile
|
||||||
|
{
|
||||||
|
public AutoMapperProfile()
|
||||||
|
{
|
||||||
|
// INPUTS MAPPER
|
||||||
|
CreateMap<ServiceCreateDto, Service>();
|
||||||
|
CreateMap<ServiceUpdateDto, Service>();
|
||||||
|
CreateMap<SiteCreateDto, Site>();
|
||||||
|
CreateMap<RoleCreateDto, Role>();
|
||||||
|
CreateMap<SiteUpdateDto, Site>();
|
||||||
|
CreateMap<SalarieCreateDto, Salarie>()
|
||||||
|
.ForMember(dest => dest.TelephoneFixe, opt => opt.MapFrom(src => src.TelephoneFixe))
|
||||||
|
.ForMember(dest => dest.TelephonePortable, opt => opt.MapFrom(src => src.TelephonePortable));
|
||||||
|
CreateMap<SalarieUpdateDto, Salarie>()
|
||||||
|
.ForMember(dest => dest.TelephoneFixe, opt => opt.MapFrom(src => src.TelephoneFixe))
|
||||||
|
.ForMember(dest => dest.TelephonePortable, opt => opt.MapFrom(src => src.TelephonePortable));
|
||||||
|
|
||||||
|
|
||||||
|
//OUTPUTS MAPPER
|
||||||
|
CreateMap<Utilisateur, UtilisateurOutputDto>()
|
||||||
|
.ForMember(dest => dest.RoleNom, opt => opt.MapFrom(src => src.IdRoleNavigation.Nom));
|
||||||
|
CreateMap<Salarie, SalarieDto>()
|
||||||
|
.ForMember(dest => dest.Service, opt => opt.MapFrom(src => src.IdServiceNavigation))
|
||||||
|
.ForMember(dest => dest.Site, opt => opt.MapFrom(src => src.IdSiteNavigation));
|
||||||
|
CreateMap<Salarie, SalarieOutputDetail>()
|
||||||
|
.ForMember(dest => dest.Service, opt => opt.MapFrom(src => src.IdServiceNavigation))
|
||||||
|
.ForMember(dest => dest.Site, opt => opt.MapFrom(src => src.IdSiteNavigation));
|
||||||
|
CreateMap<Service, ServiceDto>();
|
||||||
|
CreateMap<Service, ServiceMinimalDto>();
|
||||||
|
CreateMap<Site, SiteMinimalDto>();
|
||||||
|
CreateMap<Site, SiteDto>()
|
||||||
|
.ForMember(dest => dest.Salaries, opt => opt.MapFrom(src => src.Salaries));
|
||||||
|
CreateMap<Salarie, SalarieListDto>()
|
||||||
|
.ForMember(dest => dest.Service, opt => opt.MapFrom(src => src.IdServiceNavigation))
|
||||||
|
.ForMember(dest => dest.Site, opt => opt.MapFrom(src => src.IdSiteNavigation));
|
||||||
|
CreateMap<Service, ServiceDto>();
|
||||||
|
CreateMap<Salarie, SalarieMinimalDto>();
|
||||||
|
CreateMap<Salarie, SalarieListDto>()
|
||||||
|
.ForMember(dest => dest.Service, opt => opt.MapFrom(src => src.IdServiceNavigation.Nom))
|
||||||
|
.ForMember(dest => dest.Site, opt => opt.MapFrom(src => src.IdSiteNavigation.Ville));
|
||||||
|
}
|
||||||
|
}
|
7
ldap-cesi/Models/IResponseDataModel.cs
Normal file
7
ldap-cesi/Models/IResponseDataModel.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace ldap_cesi.Models;
|
||||||
|
|
||||||
|
public interface IResponseDataModel<T> : IResponseModel
|
||||||
|
{
|
||||||
|
public T Data { get; set; }
|
||||||
|
string Token { get; set; }
|
||||||
|
}
|
8
ldap-cesi/Models/IResponseModel.cs
Normal file
8
ldap-cesi/Models/IResponseModel.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
namespace ldap_cesi.Models;
|
||||||
|
|
||||||
|
public interface IResponseModel
|
||||||
|
{
|
||||||
|
public int StatusCode { get; set; }
|
||||||
|
public string? Message { get; set; }
|
||||||
|
public bool Success { get; set; }
|
||||||
|
}
|
22
ldap-cesi/Models/PaginatedList.cs
Normal file
22
ldap-cesi/Models/PaginatedList.cs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
namespace ldap_cesi.Models
|
||||||
|
{
|
||||||
|
public class PaginatedList<T>
|
||||||
|
{
|
||||||
|
public List<T> Data { get; }
|
||||||
|
public int TotalCount { get; }
|
||||||
|
public int PageNumber { get; }
|
||||||
|
public int PageSize { get; }
|
||||||
|
public int TotalPages => (int)Math.Ceiling((double)TotalCount / PageSize);
|
||||||
|
|
||||||
|
public PaginatedList(List<T> data, int totalCount, int pageNumber, int pageSize)
|
||||||
|
{
|
||||||
|
Data = data;
|
||||||
|
TotalCount = totalCount;
|
||||||
|
PageNumber = pageNumber;
|
||||||
|
PageSize = pageSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool HasPreviousPage => PageNumber > 1;
|
||||||
|
public bool HasNextPage => PageNumber < TotalPages;
|
||||||
|
}
|
||||||
|
}
|
10
ldap-cesi/Models/ResponseDataModel.cs
Normal file
10
ldap-cesi/Models/ResponseDataModel.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
namespace ldap_cesi.Models;
|
||||||
|
|
||||||
|
public class ResponseDataModel<T> : ResponseModel, IResponseDataModel<T> where T : class
|
||||||
|
{
|
||||||
|
public T Data { get; set; } = null!;
|
||||||
|
public int? TotalPages { get; set; }
|
||||||
|
public int? TotalCount { get; set; }
|
||||||
|
public int? PageNumber { get; set; }
|
||||||
|
public int? PageSize { get; set; }
|
||||||
|
}
|
10
ldap-cesi/Models/ResponseModel.cs
Normal file
10
ldap-cesi/Models/ResponseModel.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
namespace ldap_cesi.Models;
|
||||||
|
|
||||||
|
public class ResponseModel : IResponseModel
|
||||||
|
{
|
||||||
|
public bool Success { get; set; }
|
||||||
|
public string? Message { get; set; }
|
||||||
|
public string? Token { get; set; }
|
||||||
|
|
||||||
|
public int StatusCode { get; set; }
|
||||||
|
}
|
44
ldap-cesi/Program.cs
Normal file
44
ldap-cesi/Program.cs
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
using ldap_cesi.Configurations;
|
||||||
|
using ldap_cesi.Context;
|
||||||
|
using ldap_cesi.Seeders;
|
||||||
|
|
||||||
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
builder.BuildConf();
|
||||||
|
var app = builder.Build();
|
||||||
|
|
||||||
|
// Configure the HTTP request pipeline.
|
||||||
|
if (app.Environment.IsDevelopment())
|
||||||
|
{
|
||||||
|
app.UseSwagger();
|
||||||
|
app.UseSwaggerUI();
|
||||||
|
|
||||||
|
app.Use(async (context, next) =>
|
||||||
|
{
|
||||||
|
if (context.Request.Path == "/")
|
||||||
|
{
|
||||||
|
context.Response.Redirect("/swagger");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await next();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
using (var scope = app.Services.CreateScope())
|
||||||
|
{
|
||||||
|
var services = scope.ServiceProvider;
|
||||||
|
var context = services.GetRequiredService<PgContext>();
|
||||||
|
var seeder = new Seeders(context);
|
||||||
|
|
||||||
|
if (app.Environment.IsDevelopment())
|
||||||
|
{
|
||||||
|
await seeder.GenerateSalaries(500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
app.UseHttpsRedirection();
|
||||||
|
app.UseRouting();
|
||||||
|
app.UseCors("AllowAll");
|
||||||
|
app.UseAuthentication();
|
||||||
|
app.UseAuthorization();
|
||||||
|
app.MapControllers();
|
||||||
|
app.Run();
|
23
ldap-cesi/Properties/launchSettings.json
Normal file
23
ldap-cesi/Properties/launchSettings.json
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||||
|
"profiles": {
|
||||||
|
"http": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"dotnetRunMessages": true,
|
||||||
|
"launchBrowser": false,
|
||||||
|
"applicationUrl": "http://localhost:5080",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"https": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"dotnetRunMessages": true,
|
||||||
|
"launchBrowser": false,
|
||||||
|
"applicationUrl": "https://localhost:7079;http://localhost:5080",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
29
ldap-cesi/Repositories/Interfaces/IRepositoryBase.cs
Normal file
29
ldap-cesi/Repositories/Interfaces/IRepositoryBase.cs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
using System.Linq.Expressions;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Repository.Services;
|
||||||
|
|
||||||
|
public interface IRepositoryBase<TEntity> where TEntity : class
|
||||||
|
{
|
||||||
|
Task<TEntity> AddAsync(TEntity entity, CancellationToken cancellationToken = default);
|
||||||
|
Task<bool> AnyAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default);
|
||||||
|
Task<TEntity> GetByIdAsync<TId>(TId id, CancellationToken cancellationToken = default) where TId : notnull;
|
||||||
|
|
||||||
|
Task<(List<TEntity> Data, int TotalPages, int TotalItems)> GetAllAsync(int pageNumber = 1, int pageSize = 10, CancellationToken cancellationToken = default);
|
||||||
|
Task<bool> UpdateAsync(TEntity entity, CancellationToken cancellationToken = default);
|
||||||
|
Task<bool> DeleteAsync(TEntity entity, CancellationToken cancellationToken = default);
|
||||||
|
Task<TEntity> GetWithRelationsAsync(int id, params Expression<Func<TEntity, object>>[] relationsAInclude);
|
||||||
|
|
||||||
|
Task<(List<TEntity> Data, int TotalPages, int TotalItems)> GetAllWithRelationsAsync(int pageNumber = 1, int pageSize = 10, params Expression<Func<TEntity, object>>[] relationInclues);
|
||||||
|
|
||||||
|
Task<(List<TEntity> Data, int TotalPages, int TotalItems)> SearchAsync(
|
||||||
|
Expression<Func<TEntity, bool>> predicate,
|
||||||
|
int pageNumber = 1,
|
||||||
|
int pageSize = 10,
|
||||||
|
params Expression<Func<TEntity, object>>[] relationsAInclude);
|
||||||
|
Task<int> CountRelatedEntitiesAsync<TRelated>(int id, Expression<Func<TRelated, bool>> predicate) where TRelated : class;
|
||||||
|
|
||||||
|
Task<TEntity?> FirstOrDefaultAsync(Expression<Func<TEntity, bool>> predicate,
|
||||||
|
CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
|
Task<int> CountAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default);
|
||||||
|
}
|
8
ldap-cesi/Repositories/Interfaces/IRepositoryRole.cs
Normal file
8
ldap-cesi/Repositories/Interfaces/IRepositoryRole.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
using ldap_cesi.Entities;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Repository.Services;
|
||||||
|
|
||||||
|
public interface IRepositoryRole : IRepositoryBase<Role>
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
11
ldap-cesi/Repositories/Interfaces/IRepositorySalarie.cs
Normal file
11
ldap-cesi/Repositories/Interfaces/IRepositorySalarie.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
using ldap_cesi.Entities;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Repository.Services;
|
||||||
|
|
||||||
|
public interface IRepositorySalarie : IRepositoryBase<Salarie>
|
||||||
|
{
|
||||||
|
Task<Salarie> GetSalarieWithRelationsAsync(int id);
|
||||||
|
Task<List<Salarie>> SearchByNameAsync(string inputRecherche);
|
||||||
|
Task<List<Salarie>> GetSalariesBySiteAsync(int siteId);
|
||||||
|
Task<List<Salarie>> GetSalariesByServiceAsync(int serviceId);
|
||||||
|
}
|
8
ldap-cesi/Repositories/Interfaces/IRepositoryService.cs
Normal file
8
ldap-cesi/Repositories/Interfaces/IRepositoryService.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
using ldap_cesi.Entities;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Repository.Services;
|
||||||
|
|
||||||
|
public interface IRepositoryService : IRepositoryBase<Service>
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
8
ldap-cesi/Repositories/Interfaces/IRepositorySite.cs
Normal file
8
ldap-cesi/Repositories/Interfaces/IRepositorySite.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
using ldap_cesi.Entities;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Repository.Services;
|
||||||
|
|
||||||
|
public interface IRepositorySite : IRepositoryBase<Site>
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
using ldap_cesi.Entities;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Repository.Services;
|
||||||
|
|
||||||
|
public interface IRepositoryUtilisateur : IRepositoryBase<Utilisateur>
|
||||||
|
{
|
||||||
|
Task<Utilisateur> GetByEmailAsync(string email);
|
||||||
|
Task<Utilisateur> GetByIdIncludeRoleAsync(int id);
|
||||||
|
}
|
184
ldap-cesi/Repositories/RepositoryBase.cs
Normal file
184
ldap-cesi/Repositories/RepositoryBase.cs
Normal file
@ -0,0 +1,184 @@
|
|||||||
|
using System.Linq.Expressions;
|
||||||
|
using ldap_cesi.Context;
|
||||||
|
using ldap_cesi.Models;
|
||||||
|
using ldap_cesi.Repository.Services;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Repository;
|
||||||
|
|
||||||
|
public class RepositoryBase<TEntity> : IRepositoryBase<TEntity> where TEntity : class
|
||||||
|
{
|
||||||
|
protected readonly PgContext _context;
|
||||||
|
protected readonly DbSet<TEntity> _dbSet;
|
||||||
|
public RepositoryBase(PgContext context)
|
||||||
|
{
|
||||||
|
_context = context ?? throw new ArgumentNullException(nameof(context));
|
||||||
|
_dbSet = context.Set<TEntity>();
|
||||||
|
}
|
||||||
|
public virtual async Task<TEntity> AddAsync(TEntity entity, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_context.Set<TEntity>().Add(entity);
|
||||||
|
await SaveChangesAsync(cancellationToken);
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new Exception("Erreur pendant l'ajout de l'entité.", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual async Task<bool> AnyAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return await _context.Set<TEntity>().AnyAsync(predicate, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual async Task<TEntity?> GetByIdAsync<TId>(TId id, CancellationToken cancellationToken = default) where TId : notnull
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return await _context.FindAsync<TEntity>(id, cancellationToken);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new Exception($"Erreur lors de la récupération avec l'id : {id}.", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public virtual async Task<(List<TEntity> Data, int TotalPages, int TotalItems)> GetAllAsync(int pageNumber = 1, int pageSize = 10, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var totalCount = await _dbSet.CountAsync(cancellationToken);
|
||||||
|
var totalPages = (int)Math.Ceiling(totalCount / (double)pageSize);
|
||||||
|
|
||||||
|
var data = await _dbSet
|
||||||
|
.Skip((pageNumber - 1) * pageSize)
|
||||||
|
.Take(pageSize)
|
||||||
|
.ToListAsync(cancellationToken);
|
||||||
|
|
||||||
|
return (data, totalPages, totalCount);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new Exception("Erreur pendant la récupération des entités.", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual async Task<TEntity?> FirstOrDefaultAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return await _context.Set<TEntity>().FirstOrDefaultAsync(predicate, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual async Task<bool> UpdateAsync(TEntity entity, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_context.Set<TEntity>().Update(entity);
|
||||||
|
await SaveChangesAsync(cancellationToken);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new Exception("Erreur pendant la mis à jour", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual async Task<(List<TEntity> Data, int TotalPages, int TotalItems)> GetAllWithRelationsAsync(int pageNumber = 1, int pageSize = 10, params Expression<Func<TEntity, object>>[] relationInclues)
|
||||||
|
{
|
||||||
|
IQueryable<TEntity> query = _dbSet;
|
||||||
|
|
||||||
|
foreach (var relationInclue in relationInclues)
|
||||||
|
{
|
||||||
|
query = query.Include(relationInclue);
|
||||||
|
}
|
||||||
|
|
||||||
|
var totalCount = await query.CountAsync();
|
||||||
|
var totalPages = (int)Math.Ceiling(totalCount / (double)pageSize);
|
||||||
|
|
||||||
|
var data = await query
|
||||||
|
.Skip((pageNumber - 1) * pageSize)
|
||||||
|
.Take(pageSize)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
return (data, totalPages, totalCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual async Task<bool> DeleteAsync(TEntity entity, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_context.Set<TEntity>().Remove(entity);
|
||||||
|
await SaveChangesAsync(cancellationToken);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new Exception("Erreur pendant la suppression de l'entité", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async Task<int> SaveChangesAsync(CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return await _context.SaveChangesAsync(cancellationToken);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new Exception("Erreur pendant le sauvegarde en base de donnése.", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public virtual async Task<TEntity> GetWithRelationsAsync(int id, params Expression<Func<TEntity, object>>[] relationInclues)
|
||||||
|
{
|
||||||
|
IQueryable<TEntity> query = _dbSet;
|
||||||
|
|
||||||
|
foreach (var relationInclue in relationInclues)
|
||||||
|
{
|
||||||
|
query = query.Include(relationInclue);
|
||||||
|
}
|
||||||
|
|
||||||
|
return await query.FirstOrDefaultAsync(e => EF.Property<int>(e, "Id") == id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual async Task<(List<TEntity> Data, int TotalPages, int TotalItems)> SearchAsync(
|
||||||
|
Expression<Func<TEntity, bool>> predicate,
|
||||||
|
int pageNumber = 1,
|
||||||
|
int pageSize = 10,
|
||||||
|
params Expression<Func<TEntity, object>>[] relationsAInclude)
|
||||||
|
{
|
||||||
|
IQueryable<TEntity> query = _dbSet;
|
||||||
|
|
||||||
|
foreach (var relationInclue in relationsAInclude)
|
||||||
|
{
|
||||||
|
query = query.Include(relationInclue);
|
||||||
|
}
|
||||||
|
|
||||||
|
query = query.Where(predicate);
|
||||||
|
|
||||||
|
var totalCount = await query.CountAsync();
|
||||||
|
var totalPages = (int)Math.Ceiling(totalCount / (double)pageSize);
|
||||||
|
|
||||||
|
var data = await query
|
||||||
|
.Skip((pageNumber - 1) * pageSize)
|
||||||
|
.Take(pageSize)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
return (data, totalPages, totalCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual async Task<int> CountAsync(Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return await _dbSet.CountAsync(predicate, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual async Task<int> CountRelatedEntitiesAsync<TRelated>(int id, Expression<Func<TRelated, bool>> predicate) where TRelated : class
|
||||||
|
{
|
||||||
|
return await _context.Set<TRelated>().CountAsync(predicate);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
13
ldap-cesi/Repositories/RoleRepository.cs
Normal file
13
ldap-cesi/Repositories/RoleRepository.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using ldap_cesi.Context;
|
||||||
|
using ldap_cesi.Entities;
|
||||||
|
using ldap_cesi.Repository.Services;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Repository;
|
||||||
|
|
||||||
|
public class RoleRepository : RepositoryBase<Role>, IRepositoryRole
|
||||||
|
{
|
||||||
|
public RoleRepository(PgContext context) : base(context)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
49
ldap-cesi/Repositories/SalarieRepository.cs
Normal file
49
ldap-cesi/Repositories/SalarieRepository.cs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
using ldap_cesi.Context;
|
||||||
|
using ldap_cesi.Entities;
|
||||||
|
using ldap_cesi.Repository.Services;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Repository;
|
||||||
|
|
||||||
|
public class SalarieRepository : RepositoryBase<Salarie>, IRepositorySalarie
|
||||||
|
{
|
||||||
|
public SalarieRepository(PgContext context) : base(context)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Salarie> GetSalarieWithRelationsAsync(int id)
|
||||||
|
{
|
||||||
|
return await _context.Salaries
|
||||||
|
.Include(s => s.IdServiceNavigation)
|
||||||
|
.Include(s => s.IdSiteNavigation)
|
||||||
|
.FirstOrDefaultAsync(s => s.Id == id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<List<Salarie>> SearchByNameAsync(string inputRecherche)
|
||||||
|
{
|
||||||
|
return await _context.Salaries
|
||||||
|
.Where(s => s.Nom.Contains(inputRecherche) || s.Prenom.Contains(inputRecherche))
|
||||||
|
.Include(s => s.IdServiceNavigation)
|
||||||
|
.Include(s => s.IdSiteNavigation)
|
||||||
|
.ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<List<Salarie>> GetSalariesBySiteAsync(int siteId)
|
||||||
|
{
|
||||||
|
return await _context.Salaries
|
||||||
|
.Where(s => s.IdSite == siteId)
|
||||||
|
.Include(s => s.IdServiceNavigation)
|
||||||
|
.Include(s => s.IdSiteNavigation)
|
||||||
|
.ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<List<Salarie>> GetSalariesByServiceAsync(int serviceId)
|
||||||
|
{
|
||||||
|
return await _context.Salaries
|
||||||
|
.Where(s => s.IdService == serviceId)
|
||||||
|
.Include(s => s.IdServiceNavigation)
|
||||||
|
.Include(s => s.IdSiteNavigation)
|
||||||
|
.ToListAsync();
|
||||||
|
}
|
||||||
|
}
|
13
ldap-cesi/Repositories/ServiceRepository.cs
Normal file
13
ldap-cesi/Repositories/ServiceRepository.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using ldap_cesi.Context;
|
||||||
|
using ldap_cesi.Entities;
|
||||||
|
using ldap_cesi.Repository.Services;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Repository;
|
||||||
|
|
||||||
|
public class ServiceRepository : RepositoryBase<Service>, IRepositoryService
|
||||||
|
{
|
||||||
|
public ServiceRepository(PgContext context) : base(context)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
13
ldap-cesi/Repositories/SiteRepository.cs
Normal file
13
ldap-cesi/Repositories/SiteRepository.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using ldap_cesi.Context;
|
||||||
|
using ldap_cesi.Entities;
|
||||||
|
using ldap_cesi.Repository.Services;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Repository;
|
||||||
|
|
||||||
|
public class SiteRepository : RepositoryBase<Site>, IRepositorySite
|
||||||
|
{
|
||||||
|
public SiteRepository(PgContext context) : base(context)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
27
ldap-cesi/Repositories/UtilisateurRepository.cs
Normal file
27
ldap-cesi/Repositories/UtilisateurRepository.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
using ldap_cesi.Context;
|
||||||
|
using ldap_cesi.Entities;
|
||||||
|
using ldap_cesi.Repository.Services;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Repository;
|
||||||
|
|
||||||
|
public class UtilisateurRepository : RepositoryBase<Utilisateur>, IRepositoryUtilisateur
|
||||||
|
{
|
||||||
|
public UtilisateurRepository(PgContext context) : base(context)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<Utilisateur> GetByEmailAsync(string email)
|
||||||
|
{
|
||||||
|
return await _context.Utilisateurs
|
||||||
|
.Include(u => u.IdRoleNavigation)
|
||||||
|
.FirstOrDefaultAsync(u => u.Email == email);
|
||||||
|
}
|
||||||
|
public async Task<Utilisateur> GetByIdIncludeRoleAsync(int id)
|
||||||
|
{
|
||||||
|
return await _context.Utilisateurs
|
||||||
|
.Include(u => u.IdRoleNavigation)
|
||||||
|
.FirstOrDefaultAsync(u => u.Id == id);
|
||||||
|
}
|
||||||
|
}
|
49
ldap-cesi/Seeders/Seeders.cs
Normal file
49
ldap-cesi/Seeders/Seeders.cs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
using Bogus;
|
||||||
|
using ldap_cesi.Context;
|
||||||
|
using ldap_cesi.Entities;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Seeders;
|
||||||
|
|
||||||
|
public class Seeders
|
||||||
|
{
|
||||||
|
private readonly PgContext _context;
|
||||||
|
|
||||||
|
public Seeders(PgContext context)
|
||||||
|
{
|
||||||
|
_context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task GenerateSalaries(int count = 1000)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (await _context.Salaries.AnyAsync())
|
||||||
|
{
|
||||||
|
Console.WriteLine("Des salariés existent déjà dans la base de données. Aucune donnée insérée.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var salarieFaker = new Faker<Salarie>("fr")
|
||||||
|
.RuleFor(s => s.Nom, f => f.Name.LastName())
|
||||||
|
.RuleFor(s => s.Prenom, f => f.Name.FirstName())
|
||||||
|
.RuleFor(s => s.TelephoneFixe, f => f.Phone.PhoneNumber())
|
||||||
|
.RuleFor(s => s.TelephonePortable, f => f.Phone.PhoneNumber())
|
||||||
|
.RuleFor(s => s.Email, (f, s) => f.Internet.Email(s.Prenom, s.Nom));
|
||||||
|
|
||||||
|
var salaries = salarieFaker.Generate(count);
|
||||||
|
|
||||||
|
// on s'assure que les relations (Service, Site) existent avant d'ajouter les salariés
|
||||||
|
var services = await _context.Services.ToListAsync();
|
||||||
|
var sites = await _context.Sites.ToListAsync();
|
||||||
|
|
||||||
|
var random = new Random();
|
||||||
|
foreach (var salarie in salaries)
|
||||||
|
{
|
||||||
|
salarie.IdServiceNavigation = services[random.Next(services.Count)];
|
||||||
|
salarie.IdSiteNavigation = sites[random.Next(sites.Count)];
|
||||||
|
}
|
||||||
|
|
||||||
|
await _context.Salaries.AddRangeAsync(salaries);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
}
|
11
ldap-cesi/Services/Interfaces/IJwtService.cs
Normal file
11
ldap-cesi/Services/Interfaces/IJwtService.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
using ldap_cesi.Entities;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Services.Interfaces;
|
||||||
|
|
||||||
|
public interface IJwtService
|
||||||
|
{
|
||||||
|
string GenerateToken(Utilisateur utilisateur);
|
||||||
|
string GetPublicKey();
|
||||||
|
Task<bool> ValidateToken(string token, int userId);
|
||||||
|
Task<bool> InvalidateToken(string token);
|
||||||
|
}
|
10
ldap-cesi/Services/Interfaces/IRoleService.cs
Normal file
10
ldap-cesi/Services/Interfaces/IRoleService.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
using ldap_cesi.Entities;
|
||||||
|
using ldap_cesi.DTOs;
|
||||||
|
using ldap_cesi.DTOs.Inputs.Role;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Services.Interfaces
|
||||||
|
{
|
||||||
|
public interface IRoleService : IServiceBase<Role, RoleDto, RoleCreateDto, RoleUpdateDto>
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
8
ldap-cesi/Services/Interfaces/IRsaKeyService.cs
Normal file
8
ldap-cesi/Services/Interfaces/IRsaKeyService.cs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
using System.Security.Cryptography;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Services.Interfaces;
|
||||||
|
|
||||||
|
public interface IRsaKeyService
|
||||||
|
{
|
||||||
|
RSA GetRsaKey();
|
||||||
|
}
|
17
ldap-cesi/Services/Interfaces/ISalarieService.cs
Normal file
17
ldap-cesi/Services/Interfaces/ISalarieService.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
using ldap_cesi.DTOs;
|
||||||
|
using ldap_cesi.DTOs.Inputs.Salarie;
|
||||||
|
using ldap_cesi.DTOs.Inputs.Service;
|
||||||
|
using ldap_cesi.DTOs.Outputs.Salarie;
|
||||||
|
using ldap_cesi.Entities;
|
||||||
|
using ldap_cesi.Models;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Services.Interfaces;
|
||||||
|
|
||||||
|
public interface ISalarieService : IServiceBase<Salarie, SalarieOutputDetail, SalarieCreateDto, SalarieUpdateDto>
|
||||||
|
{
|
||||||
|
Task<IResponseDataModel<List<SalarieOutputDetail>>> GetSalariesByService(int serviceId, int pageNumber = 1,
|
||||||
|
int pageSize = 25);
|
||||||
|
|
||||||
|
Task<IResponseDataModel<List<SalarieOutputDetail>>> GetSalariesBySite(int siteId, int pageNumber = 1,
|
||||||
|
int pageSize = 25);
|
||||||
|
}
|
23
ldap-cesi/Services/Interfaces/IServiceBase.cs
Normal file
23
ldap-cesi/Services/Interfaces/IServiceBase.cs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
using System.Linq.Expressions;
|
||||||
|
using ldap_cesi.Models;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Services.Interfaces;
|
||||||
|
|
||||||
|
public interface IServiceBase<T, TDto, TCreateDto, TUpdateDto>
|
||||||
|
where T : class
|
||||||
|
where TDto : class
|
||||||
|
where TCreateDto : class
|
||||||
|
where TUpdateDto : class
|
||||||
|
{
|
||||||
|
Task<IResponseDataModel<List<T>>> GetAll(int pageNumber, int pageSize);
|
||||||
|
Task<IResponseDataModel<T>> GetById(int id);
|
||||||
|
Task<IResponseDataModel<TDto>> GetByIdWithRelations(int id, params Expression<Func<T, object>>[] relationsAInclures); // préciser avec une ou des fonctions lambda les relations à inclure dans la réponse
|
||||||
|
Task<IResponseDataModel<List<TDto>>> GetAllWithRelationsAsync(int pageNumber, int pageSize, params Expression<Func<T, object>>[] relationsAInclure);
|
||||||
|
|
||||||
|
Task<IResponseDataModel<List<TDto>>> SearchWithRelations(string searchTerm, int pageNumber, int pageSize,
|
||||||
|
params Expression<Func<T, object>>[] includeProperties);
|
||||||
|
Task<IResponseDataModel<T>> Create(TCreateDto dto);
|
||||||
|
Task<IResponseDataModel<T>> Update(TUpdateDto dto);
|
||||||
|
Task<IResponseDataModel<string>> Delete(int id);
|
||||||
|
Task<IResponseDataModel<string>> DeleteWithDependencyCheck<TRelated>(int id, Expression<Func<TRelated, bool>> relationPredicate, string relationErrorMessage) where TRelated : class;
|
||||||
|
}
|
12
ldap-cesi/Services/Interfaces/IServiceService.cs
Normal file
12
ldap-cesi/Services/Interfaces/IServiceService.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
using ldap_cesi.DTOs.Inputs.Service;
|
||||||
|
using ldap_cesi.DTOs;
|
||||||
|
using ldap_cesi.Entities;
|
||||||
|
using ldap_cesi.Models;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Services.Interfaces
|
||||||
|
{
|
||||||
|
public interface IServiceService : IServiceBase<Service, ServiceDto, ServiceCreateDto, ServiceUpdateDto>
|
||||||
|
{
|
||||||
|
Task<IResponseDataModel<string>> DeleteWithEntiteCheck(int id);
|
||||||
|
}
|
||||||
|
}
|
11
ldap-cesi/Services/Interfaces/ISiteService.cs
Normal file
11
ldap-cesi/Services/Interfaces/ISiteService.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
using ldap_cesi.DTOs;
|
||||||
|
using ldap_cesi.DTOs.Inputs.Site;
|
||||||
|
using ldap_cesi.Entities;
|
||||||
|
using ldap_cesi.Models;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Services.Interfaces;
|
||||||
|
|
||||||
|
public interface ISiteService : IServiceBase<Site, SiteDto, SiteCreateDto, SiteUpdateDto>
|
||||||
|
{
|
||||||
|
Task<IResponseDataModel<string>> DeleteWithEntiteCheck(int id);
|
||||||
|
}
|
13
ldap-cesi/Services/Interfaces/IUtilisateurService.cs
Normal file
13
ldap-cesi/Services/Interfaces/IUtilisateurService.cs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
using ldap_cesi.DTOs.Inputs;
|
||||||
|
using ldap_cesi.DTOs.Outputs.Utilisateur;
|
||||||
|
using ldap_cesi.Entities;
|
||||||
|
using ldap_cesi.Models;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Services.Interfaces;
|
||||||
|
|
||||||
|
public interface IUtilisateurService
|
||||||
|
{
|
||||||
|
Task<IResponseDataModel<List<UtilisateurOutputDto>>> GetAll();
|
||||||
|
Task<IResponseDataModel<UtilisateurOutputDto>> GetById(int id);
|
||||||
|
Task<IResponseDataModel<UtilisateurOutputDto>> Login(UtilisateurLoginDto utilisateurInput);
|
||||||
|
}
|
167
ldap-cesi/Services/JwtService.cs
Normal file
167
ldap-cesi/Services/JwtService.cs
Normal file
@ -0,0 +1,167 @@
|
|||||||
|
using System.IdentityModel.Tokens.Jwt;
|
||||||
|
using System.Security.Claims;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using ldap_cesi.Context;
|
||||||
|
using ldap_cesi.Entities;
|
||||||
|
using ldap_cesi.Services.Interfaces;
|
||||||
|
using Microsoft.IdentityModel.Tokens;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Services;
|
||||||
|
|
||||||
|
public class JwtService : IJwtService
|
||||||
|
{
|
||||||
|
private readonly IRsaKeyService _rsaKeyService;
|
||||||
|
private readonly IConfiguration _configuration;
|
||||||
|
private readonly PgContext _context;
|
||||||
|
private readonly ILogger<JwtService> _logger;
|
||||||
|
|
||||||
|
public JwtService(
|
||||||
|
IConfiguration configuration,
|
||||||
|
PgContext context,
|
||||||
|
IRsaKeyService rsaKeyService,
|
||||||
|
ILogger<JwtService> logger)
|
||||||
|
{
|
||||||
|
_configuration = configuration;
|
||||||
|
_context = context;
|
||||||
|
_rsaKeyService = rsaKeyService;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GenerateToken(Utilisateur utilisateur)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var claims = new[]
|
||||||
|
{
|
||||||
|
new Claim(JwtRegisteredClaimNames.Sub, utilisateur.Email),
|
||||||
|
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
|
||||||
|
new Claim(ClaimTypes.Name, utilisateur.Nom),
|
||||||
|
new Claim(ClaimTypes.Role, utilisateur.IdRoleNavigation.Nom),
|
||||||
|
new Claim(ClaimTypes.NameIdentifier, utilisateur.Id.ToString())
|
||||||
|
};
|
||||||
|
|
||||||
|
var key = new RsaSecurityKey(_rsaKeyService.GetRsaKey());
|
||||||
|
var creds = new SigningCredentials(key, SecurityAlgorithms.RsaSha256);
|
||||||
|
|
||||||
|
var tokenExpiryMinutes = _configuration.GetValue<int>("Jwt:TokenExpiryMinutes", 30);
|
||||||
|
var token = new JwtSecurityToken(
|
||||||
|
issuer: _configuration["Jwt:Issuer"],
|
||||||
|
audience: _configuration["Jwt:Audience"],
|
||||||
|
claims: claims,
|
||||||
|
expires: DateTime.UtcNow.AddMinutes(tokenExpiryMinutes),
|
||||||
|
signingCredentials: creds);
|
||||||
|
|
||||||
|
var tokenString = new JwtSecurityTokenHandler().WriteToken(token);
|
||||||
|
utilisateur.AccessToken = tokenString;
|
||||||
|
_context.Utilisateurs.Update(utilisateur);
|
||||||
|
_context.SaveChanges();
|
||||||
|
|
||||||
|
return tokenString;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Une erreur s'est produitel lors de la génération du token.");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetPublicKey()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var publicKey = _rsaKeyService.GetRsaKey().ExportSubjectPublicKeyInfo();
|
||||||
|
return Convert.ToBase64String(publicKey);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Une erreur s'est produite pendant la récupération de la clé.");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ajouter cette méthode à votre JwtService.cs
|
||||||
|
public async Task<bool> InvalidateToken(string token)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var tokenHandler = new JwtSecurityTokenHandler();
|
||||||
|
|
||||||
|
// récupération du token
|
||||||
|
var jwtToken = tokenHandler.ReadJwtToken(token);
|
||||||
|
|
||||||
|
// identifiant de l'utilisateur
|
||||||
|
var userIdClaim = jwtToken.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier);
|
||||||
|
|
||||||
|
if (userIdClaim == null || !int.TryParse(userIdClaim.Value, out var userId))
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Erreur d'invalidation du token : Id utilisateur non trouvé ou invalide.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var utilisateur = await _context.Utilisateurs.FindAsync(userId);
|
||||||
|
if (utilisateur == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Erreur d'invalidation du token : Utilisateur non trouvé.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// delte le token stocké
|
||||||
|
utilisateur.AccessToken = null;
|
||||||
|
_context.Utilisateurs.Update(utilisateur);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
_logger.LogInformation($"Token invalidé pour l'utilisateur {userId}.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Une erreur s'est produite pendant l'invalidation du token JWT.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<bool> ValidateToken(string token, int userId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var tokenHandler = new JwtSecurityTokenHandler();
|
||||||
|
var validationParameters = new TokenValidationParameters
|
||||||
|
{
|
||||||
|
ValidateIssuerSigningKey = true,
|
||||||
|
IssuerSigningKey = new RsaSecurityKey(_rsaKeyService.GetRsaKey()),
|
||||||
|
ValidateIssuer = true,
|
||||||
|
ValidateAudience = true,
|
||||||
|
ValidIssuer = _configuration["Jwt:Issuer"],
|
||||||
|
ValidAudience = _configuration["Jwt:Audience"],
|
||||||
|
ClockSkew = TimeSpan.Zero,
|
||||||
|
ValidateLifetime = true
|
||||||
|
};
|
||||||
|
|
||||||
|
var principal = tokenHandler.ValidateToken(token, validationParameters, out var validatedToken);
|
||||||
|
var nameIdClaim = principal.FindFirst(ClaimTypes.NameIdentifier);
|
||||||
|
if (nameIdClaim == null || !int.TryParse(nameIdClaim.Value, out var tokenUserId) || tokenUserId != userId)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Erreur de validation : Id utilisateur invalide.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var utilisateur = await _context.Utilisateurs.FindAsync(userId);
|
||||||
|
if (utilisateur == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Erreur de validation : Utilisateur non trouvé.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
utilisateur.AccessToken = token;
|
||||||
|
_context.Utilisateurs.Update(utilisateur);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Une erreur s'est produite lors pendant la validation du token JWT.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
17
ldap-cesi/Services/RoleService.cs
Normal file
17
ldap-cesi/Services/RoleService.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
using ldap_cesi.Repository.Services;
|
||||||
|
using ldap_cesi.Services.Interfaces;
|
||||||
|
using ldap_cesi.Entities;
|
||||||
|
using ldap_cesi.DTOs;
|
||||||
|
using ldap_cesi.DTOs.Inputs.Role;
|
||||||
|
using AutoMapper;
|
||||||
|
using ldap_cesi.Validator.Role;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Services;
|
||||||
|
|
||||||
|
public class RoleService : ServiceBase<Role, RoleDto, RoleCreateDto, RoleUpdateDto>,IRoleService
|
||||||
|
{
|
||||||
|
public RoleService(IRepositoryRole repositoryRole, IMapper mapper, ILogger<RoleService> logger, RoleCreateValidator roleCreateValidator, RoleUpdateValidator roleUpdateValidator)
|
||||||
|
: base(repositoryRole, mapper, logger, roleCreateValidator, roleUpdateValidator)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
36
ldap-cesi/Services/RsaKeyService.cs
Normal file
36
ldap-cesi/Services/RsaKeyService.cs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
using System.Security.Cryptography;
|
||||||
|
using ldap_cesi.Services.Interfaces;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Services;
|
||||||
|
|
||||||
|
public class RsaKeyService : IRsaKeyService
|
||||||
|
{
|
||||||
|
private readonly RSA _rsa;
|
||||||
|
private readonly string _keyPath;
|
||||||
|
|
||||||
|
public RsaKeyService(IConfiguration configuration)
|
||||||
|
{
|
||||||
|
_rsa = RSA.Create();
|
||||||
|
_keyPath = configuration["Jwt:KeyPath"] ?? "cle.bin";
|
||||||
|
LoadOrCreateRsaKey();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadOrCreateRsaKey()
|
||||||
|
{
|
||||||
|
if (File.Exists(_keyPath))
|
||||||
|
{
|
||||||
|
var keyBytes = File.ReadAllBytes(_keyPath);
|
||||||
|
_rsa.ImportRSAPrivateKey(keyBytes, out _);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var keyBytes = _rsa.ExportRSAPrivateKey();
|
||||||
|
File.WriteAllBytes(_keyPath, keyBytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public RSA GetRsaKey()
|
||||||
|
{
|
||||||
|
return _rsa;
|
||||||
|
}
|
||||||
|
}
|
98
ldap-cesi/Services/SalarieService.cs
Normal file
98
ldap-cesi/Services/SalarieService.cs
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using ldap_cesi.DTOs;
|
||||||
|
using ldap_cesi.DTOs.Inputs.Salarie;
|
||||||
|
using ldap_cesi.DTOs.Inputs.Service;
|
||||||
|
using ldap_cesi.DTOs.Outputs.Salarie;
|
||||||
|
using ldap_cesi.Entities;
|
||||||
|
using ldap_cesi.Models;
|
||||||
|
using ldap_cesi.Repository.Services;
|
||||||
|
using ldap_cesi.Services.Interfaces;
|
||||||
|
using ldap_cesi.Validator.Salarie;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Services;
|
||||||
|
|
||||||
|
public class SalarieService : ServiceBase<Salarie, SalarieOutputDetail, SalarieCreateDto, SalarieUpdateDto>, ISalarieService
|
||||||
|
{
|
||||||
|
private IRepositorySalarie _repositorySalarie;
|
||||||
|
private readonly IRepositorySite _repositorySite;
|
||||||
|
private readonly IRepositoryService _repositoryService;
|
||||||
|
private readonly IMapper _mapper;
|
||||||
|
|
||||||
|
public SalarieService(IRepositorySalarie repositorySalarie, IMapper mapper, IRepositorySite repositorySite, IRepositoryService repositoryService,
|
||||||
|
ILogger<SalarieService> logger, SalarieCreateValidator salarieCreateValidator, SalarieUpdateValidator salarieUpdateValidator)
|
||||||
|
: base(repositorySalarie, mapper, logger, salarieCreateValidator, salarieUpdateValidator)
|
||||||
|
{
|
||||||
|
_repositorySalarie = repositorySalarie;
|
||||||
|
_repositorySite = repositorySite;
|
||||||
|
_repositoryService = repositoryService;
|
||||||
|
_mapper = mapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IResponseDataModel<List<SalarieOutputDetail>>> GetSalariesBySite(int siteId, int pageNumber = 1, int pageSize = 25)
|
||||||
|
{
|
||||||
|
var site = await _repositorySite.GetByIdAsync(siteId);
|
||||||
|
if (site == null)
|
||||||
|
{
|
||||||
|
return new ResponseDataModel<List<SalarieOutputDetail>>
|
||||||
|
{
|
||||||
|
Success = false,
|
||||||
|
Message = "Site non trouvé",
|
||||||
|
StatusCode = 404
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
var salaries = await _repositorySalarie.GetSalariesBySiteAsync(siteId);
|
||||||
|
var totalCount = salaries.Count;
|
||||||
|
var paginatedSalaries = salaries
|
||||||
|
.Skip((pageNumber - 1) * pageSize)
|
||||||
|
.Take(pageSize)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var salariesDto = _mapper.Map<List<SalarieOutputDetail>>(paginatedSalaries);
|
||||||
|
|
||||||
|
return new ResponseDataModel<List<SalarieOutputDetail>>
|
||||||
|
{
|
||||||
|
Success = true,
|
||||||
|
Data = salariesDto,
|
||||||
|
TotalPages = (int)Math.Ceiling((double)totalCount / pageSize),
|
||||||
|
TotalCount = totalCount,
|
||||||
|
PageNumber = pageNumber,
|
||||||
|
PageSize = pageSize,
|
||||||
|
StatusCode = 200
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IResponseDataModel<List<SalarieOutputDetail>>> GetSalariesByService(int serviceId, int pageNumber = 1, int pageSize = 25)
|
||||||
|
{
|
||||||
|
var service = await _repositoryService.GetByIdAsync(serviceId);
|
||||||
|
if (service == null)
|
||||||
|
{
|
||||||
|
return new ResponseDataModel<List<SalarieOutputDetail>>
|
||||||
|
{
|
||||||
|
Success = false,
|
||||||
|
Message = "Service non trouvé",
|
||||||
|
StatusCode = 404
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
var salaries = await _repositorySalarie.GetSalariesByServiceAsync(serviceId);
|
||||||
|
var totalCount = salaries.Count;
|
||||||
|
var paginatedSalaries = salaries
|
||||||
|
.Skip((pageNumber - 1) * pageSize)
|
||||||
|
.Take(pageSize)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var salariesDto = _mapper.Map<List<SalarieOutputDetail>>(paginatedSalaries);
|
||||||
|
|
||||||
|
return new ResponseDataModel<List<SalarieOutputDetail>>
|
||||||
|
{
|
||||||
|
Success = true,
|
||||||
|
Data = salariesDto, // Les salariés paginés
|
||||||
|
TotalPages = (int)Math.Ceiling((double)totalCount / pageSize),
|
||||||
|
TotalCount = totalCount,
|
||||||
|
PageNumber = pageNumber,
|
||||||
|
PageSize = pageSize,
|
||||||
|
StatusCode = 200
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
360
ldap-cesi/Services/ServiceBase.cs
Normal file
360
ldap-cesi/Services/ServiceBase.cs
Normal file
@ -0,0 +1,360 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using ldap_cesi.Models;
|
||||||
|
using ldap_cesi.Repository.Services;
|
||||||
|
using ldap_cesi.Services.Interfaces;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
using FluentValidation;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Services;
|
||||||
|
|
||||||
|
public class ServiceBase<T, TDto, TCreateDto, TUpdateDto> : IServiceBase<T, TDto, TCreateDto, TUpdateDto>
|
||||||
|
where T : class
|
||||||
|
where TDto : class
|
||||||
|
where TCreateDto : class
|
||||||
|
where TUpdateDto : class
|
||||||
|
{
|
||||||
|
protected readonly IRepositoryBase<T> _repository;
|
||||||
|
protected readonly IMapper _mapper;
|
||||||
|
protected readonly ILogger<ServiceBase<T, TDto, TCreateDto, TUpdateDto>> _logger;
|
||||||
|
protected readonly IValidator<TCreateDto> _createDtoValidator;
|
||||||
|
protected readonly IValidator<TUpdateDto> _updateDtoValidator;
|
||||||
|
|
||||||
|
public ServiceBase(IRepositoryBase<T> repository, IMapper mapper, ILogger<ServiceBase<T, TDto, TCreateDto, TUpdateDto>> logger, IValidator<TCreateDto> createDtoValidator, IValidator<TUpdateDto> updateDtoValidator)
|
||||||
|
{
|
||||||
|
_repository = repository;
|
||||||
|
_mapper = mapper;
|
||||||
|
_logger = logger;
|
||||||
|
_createDtoValidator = createDtoValidator;
|
||||||
|
_updateDtoValidator = updateDtoValidator;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Expression<Func<T, bool>> BuildSearchPredicate(string inputSearch)
|
||||||
|
{
|
||||||
|
return entity =>
|
||||||
|
EF.Functions.ILike(EF.Property<string>(entity, "Nom"), $"%{inputSearch}%") ||
|
||||||
|
EF.Functions.ILike(EF.Property<string>(entity, "Prenom"), $"%{inputSearch}%");
|
||||||
|
}
|
||||||
|
public virtual async Task<IResponseDataModel<List<T>>> GetAll(int pageNumber, int pageSize)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var response = await _repository.GetAllAsync( pageNumber, pageSize);
|
||||||
|
return new ResponseDataModel<List<T>>
|
||||||
|
{
|
||||||
|
Success = true,
|
||||||
|
Data = response.Data,
|
||||||
|
TotalPages = response.TotalPages,
|
||||||
|
TotalCount = response.TotalItems,
|
||||||
|
StatusCode = 200,
|
||||||
|
Message = "Liste des entités récupérée avec succès."
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Une erreur s'est produite lors de la récupération des entités.");
|
||||||
|
return new ResponseDataModel<List<T>>
|
||||||
|
{
|
||||||
|
Success = false,
|
||||||
|
Message = "Une erreur s'est produite lors de la récupération des entités.",
|
||||||
|
StatusCode = 500
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual async Task<IResponseDataModel<T>> GetById(int id)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var entity = await _repository.GetByIdAsync(id);
|
||||||
|
if (entity == null)
|
||||||
|
{
|
||||||
|
return new ResponseDataModel<T>
|
||||||
|
{
|
||||||
|
Success = false,
|
||||||
|
Message = $"Aucune entité trouvée avec l'identifiant {id}.",
|
||||||
|
StatusCode = 404
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ResponseDataModel<T>
|
||||||
|
{
|
||||||
|
Success = true,
|
||||||
|
Data = entity,
|
||||||
|
StatusCode = 200,
|
||||||
|
Message = "Entité récupérée avec succès."
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, $"Une erreur s'est produite lors de la récupération de l'entité avec l'identifiant {id}.");
|
||||||
|
return new ResponseDataModel<T>
|
||||||
|
{
|
||||||
|
Success = false,
|
||||||
|
Message = "Une erreur s'est produite lors de la récupération de l'entité.",
|
||||||
|
StatusCode = 500
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual async Task<IResponseDataModel<List<TDto>>> GetAllWithRelationsAsync(int pageNumber, int pageSize,params Expression<Func<T, object>>[] relationsAInclure)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var response = await _repository.GetAllWithRelationsAsync(pageNumber, pageSize,relationsAInclure);
|
||||||
|
var dtos = _mapper.Map<List<TDto>>(response.Data);
|
||||||
|
return new ResponseDataModel<List<TDto>>
|
||||||
|
{
|
||||||
|
Success = true,
|
||||||
|
Data = dtos,
|
||||||
|
TotalPages = response.TotalPages,
|
||||||
|
TotalCount = response.TotalItems,
|
||||||
|
StatusCode = 200,
|
||||||
|
Message = "Liste des entités récupérée avec succès."
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Une erreur s'est produite lors de la récupération des entités.");
|
||||||
|
return new ResponseDataModel<List<TDto>>
|
||||||
|
{
|
||||||
|
Success = false,
|
||||||
|
Message = "Une erreur s'est produite lors de la récupération des entités.",
|
||||||
|
StatusCode = 500
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual async Task<IResponseDataModel<TDto>> GetByIdWithRelations(int id, params Expression<Func<T, object>>[] relationsAInclure)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var entity = await _repository.GetWithRelationsAsync(id, relationsAInclure);
|
||||||
|
if (entity == null)
|
||||||
|
{
|
||||||
|
return new ResponseDataModel<TDto>
|
||||||
|
{
|
||||||
|
Success = false,
|
||||||
|
Message = $"Aucune entité trouvée avec l'identifiant {id}.",
|
||||||
|
StatusCode = 404
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
var dto = _mapper.Map<TDto>(entity);
|
||||||
|
return new ResponseDataModel<TDto>
|
||||||
|
{
|
||||||
|
Success = true,
|
||||||
|
Data = dto,
|
||||||
|
StatusCode = 200,
|
||||||
|
Message = "Entité avec relations récupérée avec succès."
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, $"Une erreur s'est produite lors de la récupération de l'entité avec l'identifiant {id}.");
|
||||||
|
return new ResponseDataModel<TDto>
|
||||||
|
{
|
||||||
|
Success = false,
|
||||||
|
Message = "Une erreur s'est produite lors de la récupération de l'entité avec relations.",
|
||||||
|
StatusCode = 500
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual async Task<IResponseDataModel<T>> Create(TCreateDto dto)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var validationResult = _createDtoValidator.Validate(dto);
|
||||||
|
if (!validationResult.IsValid)
|
||||||
|
{
|
||||||
|
return new ResponseDataModel<T>
|
||||||
|
{
|
||||||
|
Success = false,
|
||||||
|
Message = string.Join("; ", validationResult.Errors.Select(e => e.ErrorMessage)),
|
||||||
|
StatusCode = 400
|
||||||
|
};
|
||||||
|
}
|
||||||
|
var entity = _mapper.Map<T>(dto);
|
||||||
|
var createdEntity = await _repository.AddAsync(entity);
|
||||||
|
return new ResponseDataModel<T>
|
||||||
|
{
|
||||||
|
Success = createdEntity != null,
|
||||||
|
Data = createdEntity,
|
||||||
|
StatusCode = createdEntity != null ? 201 : 500,
|
||||||
|
Message = createdEntity != null ? "Entité créée avec succès." : "Échec de la création de l'entité."
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Une erreur s'est produite lors de la création de l'entité.");
|
||||||
|
return new ResponseDataModel<T>
|
||||||
|
{
|
||||||
|
Success = false,
|
||||||
|
Message = "Une erreur s'est produite lors de la création de l'entité.",
|
||||||
|
StatusCode = 500
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual async Task<IResponseDataModel<T>> Update(TUpdateDto dto)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var validationResult = _updateDtoValidator.Validate(dto);
|
||||||
|
if (!validationResult.IsValid)
|
||||||
|
{
|
||||||
|
return new ResponseDataModel<T>
|
||||||
|
{
|
||||||
|
Success = false,
|
||||||
|
Message = string.Join("; ", validationResult.Errors.Select(e => e.ErrorMessage)),
|
||||||
|
StatusCode = 400
|
||||||
|
};
|
||||||
|
}
|
||||||
|
var entity = _mapper.Map<T>(dto);
|
||||||
|
bool isUpdated = await _repository.UpdateAsync(entity);
|
||||||
|
return new ResponseDataModel<T>
|
||||||
|
{
|
||||||
|
Success = isUpdated,
|
||||||
|
Data = isUpdated ? entity : default,
|
||||||
|
StatusCode = isUpdated ? 200 : 500,
|
||||||
|
Message = isUpdated ? "Entité mise à jour avec succès." : "Échec de la mise à jour de l'entité."
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Une erreur s'est produite lors de la mise à jour de l'entité.");
|
||||||
|
return new ResponseDataModel<T>
|
||||||
|
{
|
||||||
|
Success = false,
|
||||||
|
Message = "Une erreur s'est produite lors de la mise à jour de l'entité.",
|
||||||
|
StatusCode = 500
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual async Task<IResponseDataModel<string>> Delete(int id)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var entity = await _repository.GetByIdAsync(id);
|
||||||
|
if (entity == null)
|
||||||
|
{
|
||||||
|
return new ResponseDataModel<string>
|
||||||
|
{
|
||||||
|
Success = false,
|
||||||
|
Message = $"Aucune entité trouvée avec l'identifiant {id}.",
|
||||||
|
StatusCode = 404
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
var isDeleted = await _repository.DeleteAsync(entity);
|
||||||
|
return new ResponseDataModel<string>
|
||||||
|
{
|
||||||
|
Success = isDeleted,
|
||||||
|
Data = isDeleted ? id.ToString() : null,
|
||||||
|
StatusCode = isDeleted ? 200 : 500,
|
||||||
|
Message = isDeleted ? "Entité supprimée avec succès." : "Échec de la suppression de l'entité."
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, $"Une erreur s'est produite lors de la suppression de l'entité avec l'identifiant {id}.");
|
||||||
|
return new ResponseDataModel<string>
|
||||||
|
{
|
||||||
|
Success = false,
|
||||||
|
Message = "Une erreur s'est produite lors de la suppression de l'entité.",
|
||||||
|
StatusCode = 500
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual async Task<IResponseDataModel<List<TDto>>> SearchWithRelations(string searchTerm, int pageNumber, int pageSize, params Expression<Func<T, object>>[] includeProperties)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(searchTerm) || searchTerm.Length < 2)
|
||||||
|
{
|
||||||
|
return new ResponseDataModel<List<TDto>>
|
||||||
|
{
|
||||||
|
Success = false,
|
||||||
|
Message = "Le terme de recherche doit contenir au moins deux caractères.",
|
||||||
|
StatusCode = 400
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var predicate = BuildSearchPredicate(searchTerm);
|
||||||
|
var response = await _repository.SearchAsync(predicate, pageNumber, pageSize, includeProperties);
|
||||||
|
var dtos = _mapper.Map<List<TDto>>(response.Data);
|
||||||
|
|
||||||
|
return new ResponseDataModel<List<TDto>>
|
||||||
|
{
|
||||||
|
Success = true,
|
||||||
|
Data = dtos,
|
||||||
|
TotalPages = response.TotalPages,
|
||||||
|
TotalCount = response.TotalItems,
|
||||||
|
StatusCode = 200,
|
||||||
|
Message = "Recherche effectuée avec succès."
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Une erreur s'est produite lors de la recherche des entités.");
|
||||||
|
return new ResponseDataModel<List<TDto>>
|
||||||
|
{
|
||||||
|
Success = false,
|
||||||
|
Message = "Une erreur s'est produite lors de la recherche des entités.",
|
||||||
|
StatusCode = 500
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual async Task<IResponseDataModel<string>> DeleteWithDependencyCheck<TRelated>(int id, Expression<Func<TRelated, bool>> relationPredicate, string relationErrorMessage) where TRelated : class
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var entity = await _repository.GetByIdAsync(id);
|
||||||
|
if (entity == null)
|
||||||
|
{
|
||||||
|
return new ResponseDataModel<string>
|
||||||
|
{
|
||||||
|
Success = false,
|
||||||
|
Message = $"Aucune entité trouvée avec l'identifiant {id}.",
|
||||||
|
StatusCode = 404
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vérifier si des entités dépendantes existent
|
||||||
|
var relatedCount = await (_repository as IRepositoryBase<T>).CountRelatedEntitiesAsync<TRelated>(id, relationPredicate);
|
||||||
|
if (relatedCount > 0)
|
||||||
|
{
|
||||||
|
return new ResponseDataModel<string>
|
||||||
|
{
|
||||||
|
Success = false,
|
||||||
|
Message = relationErrorMessage,
|
||||||
|
StatusCode = 400
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
var isDeleted = await _repository.DeleteAsync(entity);
|
||||||
|
return new ResponseDataModel<string>
|
||||||
|
{
|
||||||
|
Success = isDeleted,
|
||||||
|
Data = isDeleted ? id.ToString() : null,
|
||||||
|
StatusCode = isDeleted ? 200 : 500,
|
||||||
|
Message = isDeleted ? "Entité supprimée avec succès." : "Échec de la suppression de l'entité."
|
||||||
|
};
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, $"Une erreur s'est produite lors de la suppression de l'entité avec l'identifiant {id}.");
|
||||||
|
return new ResponseDataModel<string>
|
||||||
|
{
|
||||||
|
Success = false,
|
||||||
|
Message = "Une erreur s'est produite lors de la suppression de l'entité.",
|
||||||
|
StatusCode = 500
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
28
ldap-cesi/Services/ServiceService.cs
Normal file
28
ldap-cesi/Services/ServiceService.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using ldap_cesi.DTOs.Inputs.Service;
|
||||||
|
using ldap_cesi.Entities;
|
||||||
|
using ldap_cesi.Models;
|
||||||
|
using ldap_cesi.Repository.Services;
|
||||||
|
using ldap_cesi.Services.Interfaces;
|
||||||
|
using ldap_cesi.Validator.Service;
|
||||||
|
using ldap_cesi.DTOs;
|
||||||
|
using ldap_cesi.DTOs.Inputs.Service;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Services;
|
||||||
|
|
||||||
|
public class ServiceService : ServiceBase<Service, ServiceDto, ServiceCreateDto, ServiceUpdateDto>, IServiceService
|
||||||
|
{
|
||||||
|
|
||||||
|
public ServiceService(IRepositoryService repositoryService, IMapper mapper, ILogger<ServiceService> logger, ServiceCreateValidator serviceCreateValidator, ServiceUpdateValidator serviceUpdateValidator)
|
||||||
|
: base(repositoryService, mapper, logger, serviceCreateValidator, serviceUpdateValidator)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public async Task<IResponseDataModel<string>> DeleteWithEntiteCheck(int id)
|
||||||
|
{
|
||||||
|
return await DeleteWithDependencyCheck<Salarie>(
|
||||||
|
id,
|
||||||
|
salarie => salarie.IdServiceNavigation.Id == id,
|
||||||
|
"il n'est pas possible de supprimer ce service car des salariés y sont liés"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
32
ldap-cesi/Services/SiteService.cs
Normal file
32
ldap-cesi/Services/SiteService.cs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using ldap_cesi.DTOs;
|
||||||
|
using ldap_cesi.DTOs.Inputs.Site;
|
||||||
|
using ldap_cesi.Entities;
|
||||||
|
using ldap_cesi.Models;
|
||||||
|
using ldap_cesi.Repository.Services;
|
||||||
|
using ldap_cesi.Services.Interfaces;
|
||||||
|
using ldap_cesi.Validator.Site;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Services;
|
||||||
|
|
||||||
|
public class SiteService : ServiceBase<Site, SiteDto, SiteCreateDto, SiteUpdateDto>, ISiteService
|
||||||
|
{
|
||||||
|
|
||||||
|
private readonly IRepositorySite _repositorySite;
|
||||||
|
|
||||||
|
public SiteService(IRepositorySite repositorySite, IMapper mapper,
|
||||||
|
ILogger<SiteService> logger, SiteCreateValidator siteCreateValidator, SiteUpdateValidator siteUpdateValidator)
|
||||||
|
: base(repositorySite, mapper, logger, siteCreateValidator, siteUpdateValidator)
|
||||||
|
{
|
||||||
|
_repositorySite = repositorySite;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IResponseDataModel<string>> DeleteWithEntiteCheck(int id)
|
||||||
|
{
|
||||||
|
return await DeleteWithDependencyCheck<Salarie>(
|
||||||
|
id,
|
||||||
|
salarie => salarie.IdSiteNavigation.Id == id,
|
||||||
|
"il n'est pas possible de supprimer ce site car des salariés y sont liés"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
94
ldap-cesi/Services/UtilisateurService.cs
Normal file
94
ldap-cesi/Services/UtilisateurService.cs
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using ldap_cesi.DTOs.Inputs;
|
||||||
|
using ldap_cesi.DTOs.Outputs.Utilisateur;
|
||||||
|
using ldap_cesi.Models;
|
||||||
|
using ldap_cesi.Repository.Services;
|
||||||
|
using ldap_cesi.Services.Interfaces;
|
||||||
|
using ldap_cesi.Validator.Utilisateur;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Services;
|
||||||
|
|
||||||
|
public class UtilisateurService : IUtilisateurService
|
||||||
|
{
|
||||||
|
private readonly IRepositoryUtilisateur _repositoryUtilisateur;
|
||||||
|
private readonly IJwtService _jwtService;
|
||||||
|
private readonly IMapper _mapper;
|
||||||
|
public UtilisateurService(IRepositoryUtilisateur repositoryUtilisateur, IJwtService jwtService, IMapper mapper)
|
||||||
|
{
|
||||||
|
_repositoryUtilisateur = repositoryUtilisateur;
|
||||||
|
_jwtService = jwtService;
|
||||||
|
_mapper = mapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IResponseDataModel<List<UtilisateurOutputDto>>> GetAll()
|
||||||
|
{
|
||||||
|
var utilisateurs = await _repositoryUtilisateur.GetAllAsync(1,10);
|
||||||
|
var utilisateursOutputDto = _mapper.Map<List<UtilisateurOutputDto>>(utilisateurs);
|
||||||
|
return new ResponseDataModel<List<UtilisateurOutputDto>>
|
||||||
|
{
|
||||||
|
Success = true,
|
||||||
|
StatusCode = 200,
|
||||||
|
Data = utilisateursOutputDto,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IResponseDataModel<UtilisateurOutputDto>> GetById(int id)
|
||||||
|
{
|
||||||
|
var utililisateur = await _repositoryUtilisateur.GetByIdIncludeRoleAsync(id);
|
||||||
|
var utilisateurOutput = _mapper.Map<UtilisateurOutputDto>(utililisateur);
|
||||||
|
return new ResponseDataModel<UtilisateurOutputDto>
|
||||||
|
{
|
||||||
|
Success = true,
|
||||||
|
StatusCode = 200,
|
||||||
|
Data = utilisateurOutput,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IResponseDataModel<UtilisateurOutputDto>> Login(UtilisateurLoginDto utilisateurInput)
|
||||||
|
{
|
||||||
|
var validation = new UtilisateurLoginValidator();
|
||||||
|
var result = validation.Validate(utilisateurInput);
|
||||||
|
if (!result.IsValid)
|
||||||
|
{
|
||||||
|
return new ResponseDataModel<UtilisateurOutputDto>
|
||||||
|
{
|
||||||
|
StatusCode = 400,
|
||||||
|
Success = false,
|
||||||
|
Message = "Données utilisateur invalides: " + string.Join(", ", result.Errors)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
var utilisateur = await _repositoryUtilisateur.GetByEmailAsync(utilisateurInput.Email);
|
||||||
|
|
||||||
|
if (utilisateur == null)
|
||||||
|
{
|
||||||
|
return new ResponseDataModel<UtilisateurOutputDto>
|
||||||
|
{
|
||||||
|
Success = false,
|
||||||
|
StatusCode = 404,
|
||||||
|
Message = "Utilisateur non trouvé."
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!BCrypt.Net.BCrypt.Verify(utilisateurInput.MotDePasse, utilisateur.MotDePasse))
|
||||||
|
{
|
||||||
|
return new ResponseDataModel<UtilisateurOutputDto>
|
||||||
|
{
|
||||||
|
Success = false,
|
||||||
|
StatusCode = 401,
|
||||||
|
Message = "Mot de passe incorrect."
|
||||||
|
};
|
||||||
|
}
|
||||||
|
var token = _jwtService.GenerateToken(utilisateur);
|
||||||
|
var utilisateurOutputDto = _mapper.Map<UtilisateurOutputDto>(utilisateur);
|
||||||
|
|
||||||
|
return new ResponseDataModel<UtilisateurOutputDto>
|
||||||
|
{
|
||||||
|
Success = true,
|
||||||
|
StatusCode = 200,
|
||||||
|
Data = utilisateurOutputDto,
|
||||||
|
Token = token,
|
||||||
|
Message = "Connexion réussie."
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
14
ldap-cesi/Validator/Role/RoleCreateValidator.cs
Normal file
14
ldap-cesi/Validator/Role/RoleCreateValidator.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using FluentValidation;
|
||||||
|
using ldap_cesi.DTOs.Inputs.Role;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Validator.Role;
|
||||||
|
|
||||||
|
public class RoleCreateValidator : AbstractValidator<RoleCreateDto>
|
||||||
|
{
|
||||||
|
public RoleCreateValidator()
|
||||||
|
{
|
||||||
|
RuleFor(x => x.Nom)
|
||||||
|
.NotEmpty().WithMessage("Le nom est requis.")
|
||||||
|
.MaximumLength(50).WithMessage("Le nom ne doit pas dépasser 50 caractères.");
|
||||||
|
}
|
||||||
|
}
|
16
ldap-cesi/Validator/Role/RoleUpdateValidator.cs
Normal file
16
ldap-cesi/Validator/Role/RoleUpdateValidator.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
using FluentValidation;
|
||||||
|
using ldap_cesi.DTOs.Inputs.Role;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Validator.Role;
|
||||||
|
|
||||||
|
public class RoleUpdateValidator : AbstractValidator<RoleUpdateDto>
|
||||||
|
{
|
||||||
|
public RoleUpdateValidator()
|
||||||
|
{
|
||||||
|
RuleFor(x => x.Nom)
|
||||||
|
.NotEmpty().WithMessage("Le nom est requis.")
|
||||||
|
.MaximumLength(50).WithMessage("Le nom ne doit pas dépasser 50 caractères.");
|
||||||
|
RuleFor(x => x.Id)
|
||||||
|
.NotEmpty().WithMessage("L'identifiant du Rôle est requis.");
|
||||||
|
}
|
||||||
|
}
|
41
ldap-cesi/Validator/Salarie/SalarieCreateValidator.cs
Normal file
41
ldap-cesi/Validator/Salarie/SalarieCreateValidator.cs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
using FluentValidation;
|
||||||
|
using ldap_cesi.DTOs.Inputs.Salarie;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Validator.Salarie;
|
||||||
|
|
||||||
|
public class SalarieCreateValidator : AbstractValidator<SalarieCreateDto>
|
||||||
|
{
|
||||||
|
public SalarieCreateValidator()
|
||||||
|
{
|
||||||
|
RuleFor(x => x.Nom)
|
||||||
|
.NotEmpty().WithMessage("Le nom est requis.")
|
||||||
|
.MaximumLength(50).WithMessage("Le nom ne doit pas dépasser 50 caractères.");
|
||||||
|
|
||||||
|
RuleFor(x => x.Prenom)
|
||||||
|
.NotEmpty().WithMessage("Le prénom est requis.")
|
||||||
|
.MaximumLength(50).WithMessage("Le prénom ne doit pas dépasser 50 caractères.");
|
||||||
|
|
||||||
|
RuleFor(x => x.TelephoneFixe)
|
||||||
|
.NotEmpty().WithMessage("Le téléphone fixe est requis.")
|
||||||
|
.Matches(@"^(\+33|0)[1-9](\d{2}){4}$")
|
||||||
|
.WithMessage("Le numéro de téléphone fixe n'est pas valide. Format attendu : +33XXXXXXXXX ou 0XXXXXXXXX.")
|
||||||
|
.MaximumLength(15).WithMessage("Le téléphone fixe ne doit pas dépasser 15 caractères.");
|
||||||
|
|
||||||
|
RuleFor(x => x.TelephonePortable)
|
||||||
|
.NotEmpty().WithMessage("Le téléphone portable est requis.")
|
||||||
|
.Matches(@"^(\+33|0)[6-7](\d{2}){4}$")
|
||||||
|
.WithMessage("Le numéro de téléphone portable n'est pas valide. Format attendu : +33XXXXXXXXX ou 0XXXXXXXXX.")
|
||||||
|
.MaximumLength(15).WithMessage("Le téléphone portable ne doit pas dépasser 15 caractères.");
|
||||||
|
|
||||||
|
RuleFor(x => x.Email)
|
||||||
|
.NotEmpty().WithMessage("L'email est requis.")
|
||||||
|
.EmailAddress().WithMessage("L'email n'est pas valide.")
|
||||||
|
.MaximumLength(50).WithMessage("L'email ne doit pas dépasser 50 caractères.");
|
||||||
|
|
||||||
|
RuleFor(x => x.IdSite)
|
||||||
|
.NotEmpty().WithMessage("L'ID du site est requis.");
|
||||||
|
|
||||||
|
RuleFor(x => x.IdService)
|
||||||
|
.NotEmpty().WithMessage("L'ID du service est requis.");
|
||||||
|
}
|
||||||
|
}
|
43
ldap-cesi/Validator/Salarie/SalarieUpdateValidator.cs
Normal file
43
ldap-cesi/Validator/Salarie/SalarieUpdateValidator.cs
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
using FluentValidation;
|
||||||
|
using ldap_cesi.DTOs.Inputs.Service;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Validator.Salarie;
|
||||||
|
|
||||||
|
public class SalarieUpdateValidator : AbstractValidator<SalarieUpdateDto>
|
||||||
|
{
|
||||||
|
public SalarieUpdateValidator()
|
||||||
|
{
|
||||||
|
RuleFor(x => x.Id)
|
||||||
|
.NotEmpty().WithMessage("L'identifiant du salarié est requis.");
|
||||||
|
RuleFor(x => x.Nom)
|
||||||
|
.NotEmpty().WithMessage("Le nom est requis.")
|
||||||
|
.MaximumLength(50).WithMessage("Le nom ne doit pas dépasser 50 caractères.");
|
||||||
|
|
||||||
|
RuleFor(x => x.Prenom)
|
||||||
|
.NotEmpty().WithMessage("Le prénom est requis.")
|
||||||
|
.MaximumLength(50).WithMessage("Le prénom ne doit pas dépasser 50 caractères.");
|
||||||
|
|
||||||
|
RuleFor(x => x.TelephoneFixe)
|
||||||
|
.NotEmpty().WithMessage("Le téléphone fixe est requis.")
|
||||||
|
.Matches(@"^(\+33|0)[1-9](\d{2}){4}$")
|
||||||
|
.WithMessage("Le numéro de téléphone fixe n'est pas valide. Format attendu : +33XXXXXXXXX ou 0XXXXXXXXX.")
|
||||||
|
.MaximumLength(15).WithMessage("Le téléphone fixe ne doit pas dépasser 15 caractères.");
|
||||||
|
|
||||||
|
RuleFor(x => x.TelephonePortable)
|
||||||
|
.NotEmpty().WithMessage("Le téléphone portable est requis.")
|
||||||
|
.Matches(@"^(\+33|0)[6-7](\d{2}){4}$")
|
||||||
|
.WithMessage("Le numéro de téléphone portable n'est pas valide. Format attendu : +33XXXXXXXXX ou 0XXXXXXXXX.")
|
||||||
|
.MaximumLength(15).WithMessage("Le téléphone portable ne doit pas dépasser 15 caractères.");
|
||||||
|
|
||||||
|
RuleFor(x => x.Email)
|
||||||
|
.NotEmpty().WithMessage("L'email est requis.")
|
||||||
|
.EmailAddress().WithMessage("L'email n'est pas valide.")
|
||||||
|
.MaximumLength(50).WithMessage("L'email ne doit pas dépasser 50 caractères.");
|
||||||
|
|
||||||
|
RuleFor(x => x.IdSite)
|
||||||
|
.NotEmpty().WithMessage("L'ID du site est requis.");
|
||||||
|
|
||||||
|
RuleFor(x => x.IdService)
|
||||||
|
.NotEmpty().WithMessage("L'ID du service est requis.");
|
||||||
|
}
|
||||||
|
}
|
14
ldap-cesi/Validator/Service/ServiceCreateValidator.cs
Normal file
14
ldap-cesi/Validator/Service/ServiceCreateValidator.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using FluentValidation;
|
||||||
|
using ldap_cesi.DTOs.Inputs.Service;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Validator.Service;
|
||||||
|
|
||||||
|
public class ServiceCreateValidator : AbstractValidator<ServiceCreateDto>
|
||||||
|
{
|
||||||
|
public ServiceCreateValidator()
|
||||||
|
{
|
||||||
|
RuleFor(x => x.Nom)
|
||||||
|
.NotEmpty().WithMessage("Le nom est requis.")
|
||||||
|
.MaximumLength(50).WithMessage("Le nom ne doit pas dépasser 50 caractères.");
|
||||||
|
}
|
||||||
|
}
|
18
ldap-cesi/Validator/Service/ServiceUpdateValidator.cs
Normal file
18
ldap-cesi/Validator/Service/ServiceUpdateValidator.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
using FluentValidation;
|
||||||
|
using ldap_cesi.DTOs.Inputs.Service;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Validator.Service;
|
||||||
|
|
||||||
|
public class ServiceUpdateValidator : AbstractValidator<ServiceUpdateDto>
|
||||||
|
{
|
||||||
|
public ServiceUpdateValidator()
|
||||||
|
{
|
||||||
|
RuleFor(x => x.Nom)
|
||||||
|
.NotEmpty().WithMessage("Le nom est requis.")
|
||||||
|
.MaximumLength(50).WithMessage("Le nom ne doit pas dépasser 50 caractères.");
|
||||||
|
RuleFor(x => x.Id)
|
||||||
|
.NotEmpty().WithMessage("L'identifiant du service est requis.");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
14
ldap-cesi/Validator/Site/SiteCreateValidator.cs
Normal file
14
ldap-cesi/Validator/Site/SiteCreateValidator.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using FluentValidation;
|
||||||
|
using ldap_cesi.DTOs.Inputs.Site;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Validator.Site;
|
||||||
|
|
||||||
|
public class SiteCreateValidator : AbstractValidator<SiteCreateDto>
|
||||||
|
{
|
||||||
|
public SiteCreateValidator()
|
||||||
|
{
|
||||||
|
RuleFor(x => x.Ville)
|
||||||
|
.NotEmpty().WithMessage("Le nom est requis.")
|
||||||
|
.MaximumLength(150).WithMessage("Le nom de la ville ne doit pas dépasser 150 caractères.");
|
||||||
|
}
|
||||||
|
}
|
16
ldap-cesi/Validator/Site/SiteUpdateValidator.cs
Normal file
16
ldap-cesi/Validator/Site/SiteUpdateValidator.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
using FluentValidation;
|
||||||
|
using ldap_cesi.DTOs.Inputs.Site;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Validator.Site;
|
||||||
|
|
||||||
|
public class SiteUpdateValidator : AbstractValidator<SiteUpdateDto>
|
||||||
|
{
|
||||||
|
public SiteUpdateValidator()
|
||||||
|
{
|
||||||
|
RuleFor(x => x.Ville)
|
||||||
|
.NotEmpty().WithMessage("Le nom est requis.")
|
||||||
|
.MaximumLength(150).WithMessage("Le nom de la ville ne doit pas dépasser 150 caractères.");
|
||||||
|
RuleFor(x => x.Id)
|
||||||
|
.NotEmpty().WithMessage("L'identifiant du site est requis.");
|
||||||
|
}
|
||||||
|
}
|
20
ldap-cesi/Validator/Utilisateur/UtilisateurLoginValidator.cs
Normal file
20
ldap-cesi/Validator/Utilisateur/UtilisateurLoginValidator.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
using FluentValidation;
|
||||||
|
using ldap_cesi.DTOs.Inputs;
|
||||||
|
|
||||||
|
namespace ldap_cesi.Validator.Utilisateur;
|
||||||
|
|
||||||
|
public class UtilisateurLoginValidator : AbstractValidator<UtilisateurLoginDto>
|
||||||
|
{
|
||||||
|
public UtilisateurLoginValidator()
|
||||||
|
{
|
||||||
|
RuleFor(x => x.Email)
|
||||||
|
.NotEmpty().WithMessage("L'email est requis.")
|
||||||
|
.EmailAddress().WithMessage("L'email n'est pas valide.")
|
||||||
|
.MaximumLength(50).WithMessage("L'email ne doit pas dépasser 50 caractères.");
|
||||||
|
|
||||||
|
RuleFor(x => x.MotDePasse)
|
||||||
|
.NotEmpty().WithMessage("Le mot de passe est requis.")
|
||||||
|
.MinimumLength(6).WithMessage("Le mot de passe doit contenir au moins 6 caractères.")
|
||||||
|
.MaximumLength(20).WithMessage("Le mot de passe ne doit pas dépasser 20 caractères.");
|
||||||
|
}
|
||||||
|
}
|
39
ldap-cesi/ldap-cesi.csproj
Normal file
39
ldap-cesi/ldap-cesi.csproj
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<RootNamespace>ldap_cesi</RootNamespace>
|
||||||
|
<NoWarn>CS0472,CS1591,CS1587</NoWarn>
|
||||||
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="AutoMapper" Version="14.0.0" />
|
||||||
|
<PackageReference Include="BCrypt.Net-Next" Version="4.0.3" />
|
||||||
|
<PackageReference Include="Bogus" Version="35.6.2" />
|
||||||
|
<PackageReference Include="FluentValidation" Version="11.11.0" />
|
||||||
|
<PackageReference Include="FluentValidation.AspNetCore" Version="11.3.0" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.2" />
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.2" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.2" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0.2">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.ApiDescription.Server" Version="10.0.0-preview.1.25120.3">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.2" />
|
||||||
|
<PackageReference Include="OpenAI" Version="2.2.0-beta.2" />
|
||||||
|
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
|
||||||
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.3.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Migrations\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
Loading…
x
Reference in New Issue
Block a user