implements a dico
This commit is contained in:
parent
3626be3d8b
commit
91fc7f168b
8 changed files with 502 additions and 5 deletions
|
|
@ -126,6 +126,27 @@ namespace Yavsc.Models
|
|||
builder.Entity<Activity>().Property(a => a.ParentCode).IsRequired(false);
|
||||
builder.Entity<Activity>().Property(a => a.Description).IsRequired(false);
|
||||
|
||||
builder.Entity<DictionnaireMetier>()
|
||||
.HasOne(d => d.DomaineActivite)
|
||||
.WithMany()
|
||||
.HasForeignKey(d => d.DomaineActiviteCode)
|
||||
.HasPrincipalKey(a => a.Code)
|
||||
.OnDelete(DeleteBehavior.Restrict);
|
||||
|
||||
builder.Entity<DictionnaireMetier>()
|
||||
.HasIndex(d => new { d.DomaineActiviteCode, d.Langue, d.Nom })
|
||||
.IsUnique();
|
||||
|
||||
builder.Entity<TermeMetier>()
|
||||
.HasOne(t => t.DictionnaireMetier)
|
||||
.WithMany(d => d.Termes)
|
||||
.HasForeignKey(t => t.DictionnaireMetierId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
builder.Entity<TermeMetier>()
|
||||
.HasIndex(t => new { t.DictionnaireMetierId, t.Langue, t.Mot })
|
||||
.IsUnique();
|
||||
|
||||
builder.Entity<Country>().HasKey(c => c.Code);
|
||||
builder.Entity<PerformerCodeInputValidation>()
|
||||
.HasOne(v => v.Country)
|
||||
|
|
@ -263,6 +284,10 @@ namespace Yavsc.Models
|
|||
/// <returns></returns>
|
||||
public DbSet<Activity> Activities { get; set; }
|
||||
|
||||
public DbSet<DictionnaireMetier> DictionnaireMetier { get; set; }
|
||||
|
||||
public DbSet<TermeMetier> TermeMetier { get; set; }
|
||||
|
||||
public DbSet<UserActivity> UserActivities { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
79
src/Yavsc.Server/Models/Workflow/DictionnaireMetier.cs
Normal file
79
src/Yavsc.Server/Models/Workflow/DictionnaireMetier.cs
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
#nullable enable annotations
|
||||
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Yavsc.Models.Workflow
|
||||
{
|
||||
public enum StatutValidationTerme
|
||||
{
|
||||
Propose,
|
||||
Valide,
|
||||
Rejete
|
||||
}
|
||||
|
||||
public class DictionnaireMetier
|
||||
{
|
||||
[Key]
|
||||
public long Id { get; set; }
|
||||
|
||||
[Required, MaxLength(200)]
|
||||
public string Nom { get; set; } = string.Empty;
|
||||
|
||||
[Required, MaxLength(20)]
|
||||
public string Langue { get; set; } = "fr";
|
||||
|
||||
[Required, MaxLength(128)]
|
||||
[ForeignKey(nameof(DomaineActivite))]
|
||||
public string DomaineActiviteCode { get; set; } = string.Empty;
|
||||
|
||||
[JsonIgnore]
|
||||
public virtual Activity? DomaineActivite { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public virtual ICollection<TermeMetier> Termes { get; set; } = new List<TermeMetier>();
|
||||
}
|
||||
|
||||
public class TermeMetier
|
||||
{
|
||||
[Key]
|
||||
public long Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public long DictionnaireMetierId { get; set; }
|
||||
|
||||
[ForeignKey(nameof(DictionnaireMetierId))]
|
||||
[JsonIgnore]
|
||||
public virtual DictionnaireMetier? DictionnaireMetier { get; set; }
|
||||
|
||||
[Required, MaxLength(200)]
|
||||
public string Mot { get; set; } = string.Empty;
|
||||
|
||||
[Required, MaxLength(2000)]
|
||||
public string Definition { get; set; } = string.Empty;
|
||||
|
||||
[Required, MaxLength(20)]
|
||||
public string Langue { get; set; } = "fr";
|
||||
|
||||
public StatutValidationTerme StatutValidation { get; set; } = StatutValidationTerme.Propose;
|
||||
|
||||
[MaxLength(450)]
|
||||
public string? ProposeParId { get; set; }
|
||||
|
||||
[ForeignKey(nameof(ProposeParId))]
|
||||
[JsonIgnore]
|
||||
public virtual ApplicationUser? ProposePar { get; set; }
|
||||
|
||||
[MaxLength(450)]
|
||||
public string? ValideParId { get; set; }
|
||||
|
||||
[ForeignKey(nameof(ValideParId))]
|
||||
[JsonIgnore]
|
||||
public virtual ApplicationUser? ValidePar { get; set; }
|
||||
|
||||
public DateTime DateSoumission { get; set; } = DateTime.UtcNow;
|
||||
|
||||
public DateTime? DateValidation { get; set; }
|
||||
}
|
||||
}
|
||||
116
src/Yavsc.Server/Services/DictionnaireMetierModerationService.cs
Normal file
116
src/Yavsc.Server/Services/DictionnaireMetierModerationService.cs
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using Yavsc.Models;
|
||||
using Yavsc.Models.Workflow;
|
||||
|
||||
namespace Yavsc.Server.Services
|
||||
{
|
||||
public class DictionnaireMetierModerationService
|
||||
{
|
||||
private readonly ApplicationDbContext _context;
|
||||
|
||||
public DictionnaireMetierModerationService(ApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<TermeMetier> ProposerTermAsync(
|
||||
long dictionnaireId,
|
||||
string mot,
|
||||
string definition,
|
||||
string langue,
|
||||
string userId)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(mot))
|
||||
{
|
||||
throw new ArgumentException("Le terme est requis.", nameof(mot));
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(definition))
|
||||
{
|
||||
throw new ArgumentException("La définition est requise.", nameof(definition));
|
||||
}
|
||||
|
||||
var dictionary = await _context.DictionnaireMetier
|
||||
.SingleOrDefaultAsync(d => d.Id == dictionnaireId);
|
||||
|
||||
if (dictionary is null)
|
||||
{
|
||||
throw new KeyNotFoundException($"Dictionnaire {dictionnaireId} introuvable.");
|
||||
}
|
||||
|
||||
var normalizedMot = mot.Trim();
|
||||
var exists = await _context.TermeMetier
|
||||
.AnyAsync(t => t.DictionnaireMetierId == dictionnaireId
|
||||
&& t.Langue == langue
|
||||
&& t.Mot == normalizedMot);
|
||||
|
||||
if (exists)
|
||||
{
|
||||
throw new InvalidOperationException($"Le terme '{normalizedMot}' existe déjà dans ce dictionnaire.");
|
||||
}
|
||||
|
||||
var term = new TermeMetier
|
||||
{
|
||||
DictionnaireMetierId = dictionnaireId,
|
||||
DictionnaireMetier = dictionary,
|
||||
Mot = normalizedMot,
|
||||
Definition = definition.Trim(),
|
||||
Langue = string.IsNullOrWhiteSpace(langue) ? "fr" : langue,
|
||||
StatutValidation = StatutValidationTerme.Propose,
|
||||
ProposeParId = userId,
|
||||
ValideParId = null,
|
||||
DateSoumission = DateTime.UtcNow,
|
||||
DateValidation = null
|
||||
};
|
||||
|
||||
_context.TermeMetier.Add(term);
|
||||
await _context.SaveChangesAsync();
|
||||
return term;
|
||||
}
|
||||
|
||||
public async Task<TermeMetier> ValiderTermAsync(long termeId, string moderatorId)
|
||||
{
|
||||
var term = await _context.TermeMetier
|
||||
.SingleOrDefaultAsync(t => t.Id == termeId);
|
||||
|
||||
if (term is null)
|
||||
{
|
||||
throw new KeyNotFoundException($"Terme {termeId} introuvable.");
|
||||
}
|
||||
|
||||
term.StatutValidation = StatutValidationTerme.Valide;
|
||||
term.ValideParId = moderatorId;
|
||||
term.DateValidation = DateTime.UtcNow;
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
return term;
|
||||
}
|
||||
|
||||
public async Task<TermeMetier> RejeterTermAsync(long termeId, string moderatorId)
|
||||
{
|
||||
var term = await _context.TermeMetier
|
||||
.SingleOrDefaultAsync(t => t.Id == termeId);
|
||||
|
||||
if (term is null)
|
||||
{
|
||||
throw new KeyNotFoundException($"Terme {termeId} introuvable.");
|
||||
}
|
||||
|
||||
term.StatutValidation = StatutValidationTerme.Rejete;
|
||||
term.ValideParId = moderatorId;
|
||||
term.DateValidation = DateTime.UtcNow;
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
return term;
|
||||
}
|
||||
|
||||
public async Task<List<TermeMetier>> GetPendingAsync(long dictionnaireId)
|
||||
{
|
||||
return await _context.TermeMetier
|
||||
.Where(t => t.DictionnaireMetierId == dictionnaireId
|
||||
&& t.StatutValidation == StatutValidationTerme.Propose)
|
||||
.OrderBy(t => t.DateSoumission)
|
||||
.ToListAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue