Add proposal workflow and voting API
This commit is contained in:
1 parent
9ca23a2c15
commit
1ff4a0a814
17 files changed
+796
-83
No files matched your search
@@ -1,10 +1,14 @@
|
||||
using System.Data;
|
||||
using Helpdesk.Application.Abstractions;
|
||||
using Helpdesk.Domain.Auth;
|
||||
using Helpdesk.Domain.Catalogs;
|
||||
using Helpdesk.Domain.Issues;
|
||||
using Helpdesk.Domain.Notifications;
|
||||
using Helpdesk.Domain.Proposals;
|
||||
using Helpdesk.Domain.Users;
|
||||
using Helpdesk.Infrastructure.Security;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Storage;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
namespace Helpdesk.Infrastructure.Persistence;
|
||||
@@ -24,10 +28,24 @@ public sealed class HelpdeskDbContext(DbContextOptions<HelpdeskDbContext> option
|
||||
public DbSet<Issue> Issues => Set<Issue>();
|
||||
public DbSet<IssueEvent> IssueEvents => Set<IssueEvent>();
|
||||
public DbSet<Attachment> Attachments => Set<Attachment>();
|
||||
public DbSet<IssueNotification> IssueNotifications => Set<IssueNotification>();
|
||||
public DbSet<Proposal> Proposals => Set<Proposal>();
|
||||
public DbSet<ProposalEvent> ProposalEvents => Set<ProposalEvent>();
|
||||
public DbSet<ProposalVote> ProposalVotes => Set<ProposalVote>();
|
||||
public DbSet<ProposalScore> ProposalScores => Set<ProposalScore>();
|
||||
public DbSet<Notification> Notifications => Set<Notification>();
|
||||
public DbSet<NotificationDelivery> NotificationDeliveries => Set<NotificationDelivery>();
|
||||
public DbSet<PushDevice> PushDevices => Set<PushDevice>();
|
||||
|
||||
public Task<IDbContextTransaction> BeginProposalWriteAsync(CancellationToken ct) =>
|
||||
Database.BeginTransactionAsync(IsolationLevel.ReadCommitted, ct);
|
||||
|
||||
public async Task<Proposal?> LockProposalAsync(int id, CancellationToken ct)
|
||||
{
|
||||
// Všechny zápisy nad návrhem zamykají stejný řádek před čtením stavu a hlasů.
|
||||
var rows = await Proposals.FromSql($"SELECT * FROM proposal WHERE id = {id} FOR UPDATE").ToListAsync(ct);
|
||||
return rows.SingleOrDefault();
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.ApplyConfiguration(new UserConfiguration(encryptor));
|
||||
@@ -38,7 +56,11 @@ public sealed class HelpdeskDbContext(DbContextOptions<HelpdeskDbContext> option
|
||||
modelBuilder.ApplyConfiguration(new IssueConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new IssueEventConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new AttachmentConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new IssueNotificationConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new ProposalConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new ProposalEventConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new ProposalVoteConfiguration());
|
||||
modelBuilder.Entity<ProposalScore>().HasNoKey().ToView("v_proposal_score");
|
||||
modelBuilder.ApplyConfiguration(new NotificationConfiguration());
|
||||
modelBuilder.ApplyConfiguration(new NotificationDeliveryConfiguration());
|
||||
modelBuilder.Entity<PushDevice>().ToTable("push_device");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using Helpdesk.Domain.Catalogs;
|
||||
using Helpdesk.Domain.Issues;
|
||||
using Helpdesk.Domain.Notifications;
|
||||
using Helpdesk.Domain.Proposals;
|
||||
using Helpdesk.Domain.Users;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
@@ -50,15 +52,16 @@ internal sealed class AttachmentConfiguration : IEntityTypeConfiguration<Attachm
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class IssueNotificationConfiguration : IEntityTypeConfiguration<IssueNotification>
|
||||
internal sealed class NotificationConfiguration : IEntityTypeConfiguration<Notification>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<IssueNotification> b)
|
||||
public void Configure(EntityTypeBuilder<Notification> b)
|
||||
{
|
||||
b.ToTable("notification");
|
||||
b.Property(x => x.Type).HasConversion<EnumCodeConverter<NotificationType>>().HasMaxLength(40);
|
||||
b.Property(x => x.Title).HasMaxLength(200);
|
||||
b.Property(x => x.Message).HasMaxLength(1000);
|
||||
b.HasOne(x => x.Issue).WithMany().HasForeignKey(x => x.IssueId).IsRequired(false);
|
||||
b.HasOne<Proposal>().WithMany().HasForeignKey(x => x.ProposalId);
|
||||
b.HasOne<User>().WithMany().HasForeignKey(x => x.UserId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
using Helpdesk.Domain.Catalogs;
|
||||
using Helpdesk.Domain.Proposals;
|
||||
using Helpdesk.Domain.Users;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Helpdesk.Infrastructure.Persistence;
|
||||
|
||||
internal sealed class ProposalConfiguration : IEntityTypeConfiguration<Proposal>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Proposal> b)
|
||||
{
|
||||
b.ToTable("proposal");
|
||||
b.Property(x => x.Title).HasMaxLength(200);
|
||||
b.Property(x => x.Description).HasColumnType("text");
|
||||
b.Property(x => x.Status).HasConversion<EnumCodeConverter<ProposalStatus>>().HasMaxLength(30);
|
||||
b.HasOne<ProposalCategory>().WithMany().HasForeignKey(x => x.CategoryId);
|
||||
b.HasOne<User>().WithMany().HasForeignKey(x => x.AuthorId);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class ProposalEventConfiguration : IEntityTypeConfiguration<ProposalEvent>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<ProposalEvent> b)
|
||||
{
|
||||
b.ToTable("proposal_event");
|
||||
b.Property(x => x.EventType).HasConversion<EnumCodeConverter<ProposalEventType>>().HasMaxLength(20);
|
||||
b.Property(x => x.FromStatus).HasConversion<EnumCodeConverter<ProposalStatus>>().HasMaxLength(30);
|
||||
b.Property(x => x.ToStatus).HasConversion<EnumCodeConverter<ProposalStatus>>().HasMaxLength(30);
|
||||
b.Property(x => x.Note).HasColumnType("text");
|
||||
b.HasOne(x => x.Proposal).WithMany().HasForeignKey(x => x.ProposalId);
|
||||
b.HasOne<User>().WithMany().HasForeignKey(x => x.ActorId);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class ProposalVoteConfiguration : IEntityTypeConfiguration<ProposalVote>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<ProposalVote> b)
|
||||
{
|
||||
b.ToTable("proposal_vote");
|
||||
b.HasKey(x => new { x.ProposalId, x.UserId });
|
||||
b.Property(x => x.Value).HasColumnType("tinyint");
|
||||
b.HasOne<Proposal>().WithMany().HasForeignKey(x => x.ProposalId);
|
||||
b.HasOne<User>().WithMany().HasForeignKey(x => x.UserId);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user