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
@@ -0,0 +1,66 @@
|
||||
namespace Helpdesk.Domain.Proposals;
|
||||
|
||||
public sealed class ProposalEvent
|
||||
{
|
||||
private ProposalEvent() { }
|
||||
|
||||
public ProposalEvent(Proposal proposal, ProposalEventType eventType, ProposalStatus? fromStatus, int actorId,
|
||||
string? note, DateTime occurredAt)
|
||||
{
|
||||
Proposal = proposal;
|
||||
EventType = eventType;
|
||||
FromStatus = fromStatus;
|
||||
ToStatus = proposal.Status;
|
||||
ActorId = actorId;
|
||||
Note = note;
|
||||
OccurredAt = occurredAt;
|
||||
}
|
||||
|
||||
public int Id { get; private set; }
|
||||
public int ProposalId { get; private set; }
|
||||
public Proposal Proposal { get; private set; } = null!;
|
||||
public ProposalEventType EventType { get; private set; }
|
||||
public ProposalStatus? FromStatus { get; private set; }
|
||||
public ProposalStatus ToStatus { get; private set; }
|
||||
public int ActorId { get; private set; }
|
||||
public string? Note { get; private set; }
|
||||
public DateTime OccurredAt { get; private set; }
|
||||
}
|
||||
|
||||
public sealed class ProposalVote
|
||||
{
|
||||
private ProposalVote() { }
|
||||
|
||||
public ProposalVote(Proposal proposal, int userId, sbyte value, DateTime now)
|
||||
{
|
||||
ProposalId = proposal.Id;
|
||||
UserId = userId;
|
||||
SetValue(proposal, value, now);
|
||||
}
|
||||
|
||||
public int ProposalId { get; private set; }
|
||||
public int UserId { get; private set; }
|
||||
public sbyte Value { get; private set; }
|
||||
public DateTime VotedAt { get; private set; }
|
||||
|
||||
public void SetValue(Proposal proposal, sbyte value, DateTime now)
|
||||
{
|
||||
if (proposal.Id != ProposalId || !proposal.CanVote(UserId))
|
||||
throw new InvalidOperationException("O návrhu nelze hlasovat.");
|
||||
if (value is not (1 or -1))
|
||||
throw new ArgumentOutOfRangeException(nameof(value));
|
||||
if (Value == value)
|
||||
return;
|
||||
|
||||
Value = value;
|
||||
VotedAt = now;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ProposalScore
|
||||
{
|
||||
public int ProposalId { get; private set; }
|
||||
public decimal VotesFor { get; private set; }
|
||||
public decimal VotesAgainst { get; private set; }
|
||||
public decimal Score { get; private set; }
|
||||
}
|
||||
Reference in new issue
Block a user