feat/service-base #15
@ -1,6 +1,8 @@
|
||||
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;
|
||||
@ -48,6 +50,8 @@ public static class Conf
|
||||
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)
|
||||
{
|
||||
|
@ -1,7 +1,7 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using ldap_cesi.DTOs.Inputs.Role;
|
||||
using ldap_cesi.Services.Interfaces;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
|
||||
namespace ldap_cesi.Controllers
|
||||
{
|
||||
@ -17,68 +17,72 @@ namespace ldap_cesi.Controllers
|
||||
}
|
||||
|
||||
// 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()
|
||||
{
|
||||
var result = await _roleService.GetAll();
|
||||
if (result.Success)
|
||||
{
|
||||
return Ok(result.Data);
|
||||
}
|
||||
return StatusCode(result.StatusCode, result.Message);
|
||||
return result.Success ? Ok(result.Data) : BadRequest(result.Message);
|
||||
}
|
||||
|
||||
// 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);
|
||||
if (result.Success)
|
||||
{
|
||||
return Ok(result.Data);
|
||||
}
|
||||
return StatusCode(result.StatusCode, result.Message);
|
||||
return result.Success ? Ok(result.Data) : BadRequest(result.Message);
|
||||
}
|
||||
|
||||
// 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);
|
||||
if (result.Success)
|
||||
{
|
||||
return CreatedAtAction(nameof(GetRoleById), new { id = result.Data }, result.Data);
|
||||
}
|
||||
return StatusCode(result.StatusCode, result.Message);
|
||||
return result.Success ? Ok(result.Data) : BadRequest(result.Message);
|
||||
}
|
||||
|
||||
// PUT: api/Role/{id}
|
||||
[HttpPut("{id}")]
|
||||
public async Task<IActionResult> UpdateRole(int id, [FromBody] RoleUpdateDto roleDto)
|
||||
// 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)
|
||||
{
|
||||
if (id != roleDto.Id)
|
||||
{
|
||||
return BadRequest("Role ID mismatch");
|
||||
}
|
||||
|
||||
var result = await _roleService.Update(roleDto);
|
||||
if (result.Success)
|
||||
{
|
||||
return NoContent();
|
||||
}
|
||||
return StatusCode(result.StatusCode, result.Message);
|
||||
return result.Success ? Ok(result.Data) : BadRequest(result.Message);
|
||||
}
|
||||
|
||||
// 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);
|
||||
if (result.Success)
|
||||
{
|
||||
return NoContent();
|
||||
}
|
||||
return StatusCode(result.StatusCode, result.Message);
|
||||
return result.Success ? Ok(result.Data) : BadRequest(result.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -56,11 +56,21 @@ public class SalarieController : ControllerBase
|
||||
/// <param name="id">L'ID du salarié.</param>
|
||||
/// <returns>Le salarié correspondant à l'ID.</returns>
|
||||
[HttpGet("/complet/{id}")]
|
||||
[Authorize(Roles = "admin")]
|
||||
public async Task<IActionResult> GetSalarieCompletById(int id)
|
||||
{
|
||||
var result = await _salarieService.GetCompletById(id);
|
||||
return result.Success ? Ok(result.Data) : BadRequest(result.Message);
|
||||
}
|
||||
|
||||
/// <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()
|
||||
{
|
||||
var result = await _salarieService.GetAllWithRelationsAsync(s => s.IdServiceNavigation, s => s.IdSiteNavigation);
|
||||
return result.Success ? Ok(result.Data) : BadRequest(result.Message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -1,3 +1,4 @@
|
||||
|
||||
namespace ldap_cesi.DTOs.Inputs.Role;
|
||||
|
||||
public class RoleCreateDto
|
||||
|
@ -1,5 +1,6 @@
|
||||
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;
|
||||
@ -17,6 +18,7 @@ public class AutoMapperProfile : Profile
|
||||
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.TelephoneFix))
|
||||
@ -29,14 +31,14 @@ public class AutoMapperProfile : Profile
|
||||
//OUTPUTS MAPPER
|
||||
CreateMap<Utilisateur, UtilisateurOutputDto>()
|
||||
.ForMember(dest => dest.RoleNom, opt => opt.MapFrom(src => src.IdRoleNavigation.Nom));
|
||||
CreateMap<Salarie, SalarieOutputDetail>()
|
||||
CreateMap<Salarie, SalarieDto>()
|
||||
.ForMember(dest => dest.Service, opt => opt.MapFrom(src => src.IdServiceNavigation))
|
||||
.ForMember(dest => dest.Site, opt => opt.MapFrom(src => src.IdSiteNavigation));
|
||||
CreateMap<Service, ServiceDto>();
|
||||
CreateMap<Site, SiteDto>();
|
||||
CreateMap<Salarie, SalarieListDto>();
|
||||
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));
|
||||
CreateMap<Salarie, SalarieListDto>();
|
||||
CreateMap<Service, ServiceDto>();
|
||||
CreateMap<Site, SiteDto>();
|
||||
}
|
||||
}
|
@ -10,6 +10,8 @@ public interface IRepositoryBase<TEntity> where TEntity : class
|
||||
Task<List<TEntity>> GetAllAsync(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>> GetAllWithRelationsAsync(params Expression<Func<TEntity, object>>[] relationsAInclude);
|
||||
Task<TEntity?> FirstOrDefaultAsync(Expression<Func<TEntity, bool>> predicate,
|
||||
CancellationToken cancellationToken = default);
|
||||
}
|
@ -9,10 +9,11 @@ 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)
|
||||
{
|
||||
@ -113,5 +114,28 @@ public class RepositoryBase<TEntity> : IRepositoryBase<TEntity> where TEntity :
|
||||
throw new Exception("Erreur qui concerne le listing des entités", ex);
|
||||
}
|
||||
}
|
||||
public virtual async Task<List<TEntity>> GetAllWithRelationsAsync(params Expression<Func<TEntity, object>>[] relationInclues)
|
||||
{
|
||||
IQueryable<TEntity> query = _dbSet;
|
||||
|
||||
foreach (var relationInclue in relationInclues)
|
||||
{
|
||||
query = query.Include(relationInclue);
|
||||
}
|
||||
|
||||
return await query.ToListAsync();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
@ -1,9 +1,6 @@
|
||||
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;
|
||||
|
||||
namespace ldap_cesi.Services.Interfaces
|
||||
{
|
||||
|
@ -12,5 +12,5 @@ public interface ISalarieService : IServiceBase<Salarie, SalarieDto, SalarieCrea
|
||||
Task<IResponseDataModel<List<Salarie>>> GetAllWithoutIService();
|
||||
Task<IResponseDataModel<List<SalarieListDto>>> GetSalariesBySite(int siteId);
|
||||
Task<IResponseDataModel<List<SalarieListDto>>> GetSalariesByService(int serviceId);
|
||||
Task<IResponseDataModel<SalarieOutputDetail>> GetCompletById(int id);
|
||||
Task<IResponseDataModel<SalarieDto>> GetCompletById(int id);
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
using System.Linq.Expressions;
|
||||
using ldap_cesi.Models;
|
||||
|
||||
namespace ldap_cesi.Services.Interfaces;
|
||||
@ -10,6 +11,8 @@ public interface IServiceBase<T, TDto, TCreateDto, TUpdateDto>
|
||||
{
|
||||
Task<IResponseDataModel<List<T>>> GetAll();
|
||||
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(params Expression<Func<T, object>>[] relationsAInclure);
|
||||
Task<IResponseDataModel<T>> Create(TCreateDto dto);
|
||||
Task<IResponseDataModel<T>> Update(TUpdateDto dto);
|
||||
Task<IResponseDataModel<string>> Delete(int id);
|
||||
|
@ -4,13 +4,14 @@ 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)
|
||||
: base(repositoryRole, mapper, logger)
|
||||
public RoleService(IRepositoryRole repositoryRole, IMapper mapper, ILogger<RoleService> logger, RoleCreateValidator roleCreateValidator, RoleUpdateValidator roleUpdateValidator)
|
||||
: base(repositoryRole, mapper, logger, roleCreateValidator, roleUpdateValidator)
|
||||
{
|
||||
}
|
||||
}
|
@ -18,7 +18,9 @@ public class SalarieService : ServiceBase<Salarie, SalarieDto, SalarieCreateDto,
|
||||
private readonly IRepositoryService _repositoryService;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public SalarieService(IRepositorySalarie repositorySalarie, IMapper mapper, IRepositorySite repositorySite, IRepositoryService repositoryService, ILogger<SalarieService> logger) : base(repositorySalarie, mapper, logger)
|
||||
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;
|
||||
@ -48,11 +50,11 @@ public class SalarieService : ServiceBase<Salarie, SalarieDto, SalarieCreateDto,
|
||||
// };
|
||||
// }
|
||||
|
||||
public async Task<IResponseDataModel<SalarieOutputDetail>> GetCompletById(int id)
|
||||
public async Task<IResponseDataModel<SalarieDto>> GetCompletById(int id)
|
||||
{
|
||||
var salarie = await _repositorySalarie.GetSalarieWithRelationsAsync(id);
|
||||
var salarieOutput = _mapper.Map<SalarieOutputDetail>(salarie);
|
||||
return new ResponseDataModel<SalarieOutputDetail>
|
||||
var salarieOutput = _mapper.Map<SalarieDto>(salarie);
|
||||
return new ResponseDataModel<SalarieDto>
|
||||
{
|
||||
Success = true,
|
||||
Data = salarieOutput,
|
||||
|
@ -7,7 +7,9 @@ using ldap_cesi.Services.Interfaces;
|
||||
using ldap_cesi.Validator.Site;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using FluentValidation;
|
||||
|
||||
namespace ldap_cesi.Services;
|
||||
|
||||
@ -20,12 +22,16 @@ public class ServiceBase<T, TDto, TCreateDto, TUpdateDto> : IServiceBase<T, TDto
|
||||
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)
|
||||
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;
|
||||
}
|
||||
|
||||
public virtual async Task<IResponseDataModel<List<T>>> GetAll()
|
||||
@ -87,11 +93,83 @@ public class ServiceBase<T, TDto, TCreateDto, TUpdateDto> : IServiceBase<T, TDto
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public virtual async Task<IResponseDataModel<List<TDto>>> GetAllWithRelationsAsync(params Expression<Func<T, object>>[] relationsAInclure)
|
||||
{
|
||||
try
|
||||
{
|
||||
var entities = await _repository.GetAllWithRelationsAsync(relationsAInclure);
|
||||
var dtos = _mapper.Map<List<TDto>>(entities);
|
||||
return new ResponseDataModel<List<TDto>>
|
||||
{
|
||||
Success = true,
|
||||
Data = dtos,
|
||||
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>
|
||||
@ -118,6 +196,16 @@ public class ServiceBase<T, TDto, TCreateDto, TUpdateDto> : IServiceBase<T, TDto
|
||||
{
|
||||
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>
|
||||
|
@ -13,7 +13,8 @@ namespace ldap_cesi.Services;
|
||||
public class ServiceService : ServiceBase<Service, ServiceDto, ServiceCreateDto, ServiceUpdateDto>, IServiceService
|
||||
{
|
||||
|
||||
public ServiceService(IRepositoryService repositoryService, IMapper mapper, ILogger<ServiceService> logger) : base(repositoryService, mapper, logger)
|
||||
public ServiceService(IRepositoryService repositoryService, IMapper mapper, ILogger<ServiceService> logger, ServiceCreateValidator serviceCreateValidator, ServiceUpdateValidator serviceUpdateValidator)
|
||||
: base(repositoryService, mapper, logger, serviceCreateValidator, serviceUpdateValidator)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ public class UtilisateurService : IUtilisateurService
|
||||
|
||||
public async Task<IResponseDataModel<UtilisateurOutputDto>> Login(UtilisateurLoginDto utilisateurInput)
|
||||
{
|
||||
var validation = new UtilisateurCreateValidator();
|
||||
var validation = new UtilisateurLoginValidator();
|
||||
var result = validation.Validate(utilisateurInput);
|
||||
if (!result.IsValid)
|
||||
{
|
||||
|
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.");
|
||||
}
|
||||
}
|
@ -16,11 +16,15 @@ public class SalarieCreateValidator : AbstractValidator<SalarieCreateDto>
|
||||
.MaximumLength(50).WithMessage("Le prénom ne doit pas dépasser 50 caractères.");
|
||||
|
||||
RuleFor(x => x.TelephoneFix)
|
||||
.NotEmpty().WithMessage("Le téléphone fixe est requis.")
|
||||
.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)
|
||||
|
@ -18,11 +18,15 @@ public class SalarieUpdateValidator : AbstractValidator<SalarieUpdateDto>
|
||||
.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.")
|
||||
.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)
|
||||
|
@ -3,16 +3,18 @@ using ldap_cesi.DTOs.Inputs;
|
||||
|
||||
namespace ldap_cesi.Validator.Utilisateur;
|
||||
|
||||
public class UtilisateurCreateValidator : AbstractValidator<UtilisateurLoginDto>
|
||||
public class UtilisateurLoginValidator : AbstractValidator<UtilisateurLoginDto>
|
||||
{
|
||||
public UtilisateurCreateValidator()
|
||||
public UtilisateurLoginValidator()
|
||||
{
|
||||
RuleFor(x => x.Email)
|
||||
.NotEmpty().WithMessage("L'email est requis.")
|
||||
.EmailAddress().WithMessage("L'email n'est pas valide.");
|
||||
.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.");
|
||||
.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.");
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user