| | 1 | | using StronglyTypedIds; |
| | 2 | |
|
| | 3 | | namespace Syki.Back.Commands; |
| | 4 | |
|
| | 5 | | public class CommandBatch |
| | 6 | | { |
| 0 | 7 | | public CommandBatchId Id { get; set; } |
| 0 | 8 | | public Guid InstitutionId { get; set; } |
| 0 | 9 | | public CommandBatchType Type { get; set; } |
| 0 | 10 | | public CommandBatchStatus Status { get; set; } |
| 0 | 11 | | public DateTime CreatedAt { get; set; } |
| 0 | 12 | | public DateTime? ProcessedAt { get; set; } |
| | 13 | |
|
| | 14 | | /// <summary> |
| | 15 | | /// Id do evento que gerou o lote |
| | 16 | | /// </summary> |
| 0 | 17 | | public DomainEventId? EventId { get; set; } |
| | 18 | |
|
| | 19 | | /// <summary> |
| | 20 | | /// Id do comando que gerou o lote |
| | 21 | | /// </summary> |
| 0 | 22 | | public CommandId? SourceCommandId { get; set; } |
| | 23 | |
|
| | 24 | | /// <summary> |
| | 25 | | /// Id do comando que será executado quando o lote for processado com sucesso |
| | 26 | | /// </summary> |
| 0 | 27 | | public CommandId? NextCommandId { get; set; } |
| | 28 | |
|
| 0 | 29 | | public int Size { get; set; } |
| | 30 | |
|
| 0 | 31 | | private CommandBatch() { } |
| | 32 | |
|
| | 33 | | public static CommandBatch New( |
| | 34 | | Guid institutionId, |
| | 35 | | CommandBatchType type, |
| | 36 | | DomainEventId? eventId = null, |
| | 37 | | CommandId? sourceCommandId = null) |
| | 38 | | { |
| 0 | 39 | | return new() |
| 0 | 40 | | { |
| 0 | 41 | | Type = type, |
| 0 | 42 | | Id = CommandBatchId.CreateNew(), |
| 0 | 43 | | CreatedAt = DateTime.UtcNow, |
| 0 | 44 | | InstitutionId = institutionId, |
| 0 | 45 | | Status = CommandBatchStatus.Pending, |
| 0 | 46 | | EventId = eventId, |
| 0 | 47 | | SourceCommandId = sourceCommandId, |
| 0 | 48 | | }; |
| | 49 | | } |
| | 50 | |
|
| | 51 | | public void ContinueWith(Command command) |
| | 52 | | { |
| 0 | 53 | | NextCommandId = command.Id; |
| 0 | 54 | | command.SetAwaiting(); |
| 0 | 55 | | } |
| | 56 | | } |
| | 57 | |
|
| | 58 | | [StronglyTypedId] |
| | 59 | | public partial struct CommandBatchId |
| | 60 | | { |
| | 61 | | public static CommandBatchId CreateNew() |
| | 62 | | { |
| | 63 | | return new CommandBatchId(Guid.CreateVersion7()); |
| | 64 | | } |
| | 65 | |
|
| | 66 | | public class CommandBatchIdEfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConvert |
| | 67 | | { |
| | 68 | | public CommandBatchIdEfCoreValueConverter() : this(null) { } |
| | 69 | |
|
| | 70 | | public CommandBatchIdEfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMapping |
| | 71 | | : base( |
| | 72 | | id => id.Value, |
| | 73 | | value => new CommandBatchId(value), |
| | 74 | | mappingHints |
| | 75 | | ) |
| | 76 | | { } |
| | 77 | | } |
| | 78 | | } |