Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for supplied transmission attachment ID on create/update #1242

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions docs/schema/V1/swagger.verified.json
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@
"type": "string"
},
"process": {
"description": "Optional process identifier used to indicate a business process this dialog belongs to ",
"description": "Optional process identifier used to indicate a business process this dialog belongs to",
"nullable": true,
"type": "string"
},
Expand Down Expand Up @@ -262,7 +262,7 @@
]
},
"systemLabel": {
"description": "Set the system label of the dialog Migration purposes ",
"description": "Set the system label of the dialog Migration purposes",
"nullable": true,
"oneOf": [
{
Expand Down Expand Up @@ -751,6 +751,13 @@
},
"type": "array"
},
"id": {
"description": "A self-defined UUIDv7 may be provided to support idempotent creation of transmission attachments. If not provided, a new UUIDv7 will be generated.",
"example": "01913cd5-784f-7d3b-abef-4c77b1f0972d",
"format": "guid",
"nullable": true,
"type": "string"
},
"urls": {
"description": "The URLs associated with the attachment, each referring to a different representation of the attachment.",
"items": {
Expand Down Expand Up @@ -4089,6 +4096,13 @@
},
"type": "array"
},
"id": {
"description": "A self-defined UUIDv7 may be provided to support idempotent creation of transmission attachments. If not provided, a new UUIDv7 will be generated.",
"example": "01913cd5-784f-7d3b-abef-4c77b1f0972d",
"format": "guid",
"nullable": true,
"type": "string"
},
"urls": {
"description": "The URLs associated with the attachment, each referring to a different representation of the attachment.",
"items": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,11 @@ private async Task EnsureNoExistingUserDefinedIds(DialogEntity dialog, Cancellat
{
_domainContext.AddError(DomainFailure.EntityExists<DialogTransmission>(existingTransmissionIds));
}

var existingTransmissionAttachmentIds = await _db.GetExistingIds(dialog.Transmissions.SelectMany(t => t.Attachments), cancellationToken);
if (existingTransmissionAttachmentIds.Count != 0)
{
_domainContext.AddError(DomainFailure.EntityExists<DialogTransmissionAttachment>(existingTransmissionAttachmentIds));
}
oskogstad marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ public CreateDialogTransmissionAttachmentDtoValidator(
IValidator<IEnumerable<LocalizationDto>> localizationsValidator,
IValidator<CreateDialogTransmissionAttachmentUrlDto> urlValidator)
{
RuleFor(x => x.Id)
.IsValidUuidV7()
.UuidV7TimestampIsInPast();

oskogstad marked this conversation as resolved.
Show resolved Hide resolved
RuleFor(x => x.DisplayName)
.SetValidator(localizationsValidator);
RuleFor(x => x.Urls)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class CreateDialogDto
public DateTimeOffset? DueAt { get; set; }

/// <summary>
/// Optional process identifier used to indicate a business process this dialog belongs to
/// Optional process identifier used to indicate a business process this dialog belongs to
/// </summary>
public string? Process { get; set; }
/// <summary>
Expand Down Expand Up @@ -104,7 +104,7 @@ public class CreateDialogDto
public DialogStatus.Values Status { get; set; }

/// <summary>
/// Set the system label of the dialog Migration purposes
/// Set the system label of the dialog Migration purposes
/// </summary>
public SystemLabel.Values? SystemLabel { get; set; }
/// <summary>
Expand Down Expand Up @@ -527,6 +527,12 @@ public sealed class CreateDialogDialogAttachmentUrlDto

public sealed class CreateDialogTransmissionAttachmentDto
{
/// <summary>
/// A self-defined UUIDv7 may be provided to support idempotent creation of transmission attachments. If not provided, a new UUIDv7 will be generated.
/// </summary>
/// <example>01913cd5-784f-7d3b-abef-4c77b1f0972d</example>
public Guid? Id { get; set; }

oskogstad marked this conversation as resolved.
Show resolved Hide resolved
/// <summary>
/// The display name of the attachment that should be used in GUIs.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ public MappingProfile()
.ForMember(dest => dest.ActorType, opt => opt.Ignore())
.ForMember(dest => dest.ActorTypeId, opt => opt.MapFrom(src => src.ActorType));

CreateMap<UpdateDialogTransmissionAttachmentDto, DialogTransmissionAttachment>()
.ForMember(x => x.Id, opt => opt.Ignore());
CreateMap<UpdateDialogTransmissionAttachmentDto, DialogTransmissionAttachment>();

CreateMap<UpdateDialogTransmissionAttachmentUrlDto, AttachmentUrl>()
.ForMember(x => x.Id, opt => opt.Ignore())
oskogstad marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,17 @@ private async Task AppendTransmission(DialogEntity dialog, UpdateDialogDto dto,
return;
}

var newTransmissionAttachments = newDialogTransmissions
.SelectMany(x => x.Attachments)
.ToList();

var existingTransmissionAttachmentIds = await _db.GetExistingIds(newTransmissionAttachments, cancellationToken);
if (existingTransmissionAttachmentIds.Count != 0)
{
_domainContext.AddError(DomainFailure.EntityExists<DialogTransmissionAttachment>(existingTransmissionAttachmentIds));
return;
}
oskogstad marked this conversation as resolved.
Show resolved Hide resolved

dialog.Transmissions.AddRange(newDialogTransmissions);
// Tell ef explicitly to add transmissions as new to the database.
_db.DialogTransmissions.AddRange(newDialogTransmissions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ public UpdateDialogTransmissionAttachmentDtoValidator(
IValidator<IEnumerable<LocalizationDto>> localizationsValidator,
IValidator<UpdateDialogTransmissionAttachmentUrlDto> urlValidator)
{
RuleFor(x => x.Id)
.IsValidUuidV7()
.UuidV7TimestampIsInPast();

oskogstad marked this conversation as resolved.
Show resolved Hide resolved
RuleFor(x => x.DisplayName)
.SetValidator(localizationsValidator);
RuleFor(x => x.Urls)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,12 @@ public sealed class UpdateDialogDialogAttachmentUrlDto

public sealed class UpdateDialogTransmissionAttachmentDto
{
/// <summary>
/// A self-defined UUIDv7 may be provided to support idempotent creation of transmission attachments. If not provided, a new UUIDv7 will be generated.
/// </summary>
/// <example>01913cd5-784f-7d3b-abef-4c77b1f0972d</example>
public Guid? Id { get; set; }
oskogstad marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// The display name of the attachment that should be used in GUIs.
/// </summary>
Expand Down
Loading