Skip to content

Commit

Permalink
fx
Browse files Browse the repository at this point in the history
  • Loading branch information
oskogstad committed Dec 2, 2024
1 parent 08395a4 commit 1056bc1
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 9 deletions.
12 changes: 12 additions & 0 deletions docs/schema/V1/swagger.verified.json
Original file line number Diff line number Diff line change
Expand Up @@ -5945,6 +5945,9 @@
},
"description": "The given dialog ID was not found or is already deleted."
},
"410": {
"description": "Entity with the given key(s) is removed"
},
"412": {
"content": {
"application/problem\u002Bjson": {
Expand Down Expand Up @@ -6193,6 +6196,9 @@
},
"description": "The given dialog ID was not found or is already deleted."
},
"410": {
"description": "Entity with the given key(s) is removed"
},
"412": {
"content": {
"application/problem\u002Bjson": {
Expand Down Expand Up @@ -6488,6 +6494,9 @@
},
"description": "The given dialog ID was not found or is already deleted."
},
"410": {
"description": "Entity with the given key(s) is removed"
},
"412": {
"content": {
"application/problem\u002Bjson": {
Expand Down Expand Up @@ -6830,6 +6839,9 @@
},
"description": "The given dialog ID was not found or is already deleted."
},
"410": {
"description": "Entity with the given key(s) is removed"
},
"412": {
"content": {
"application/problem\u002Bjson": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public sealed class DeleteDialogCommand : IRequest<DeleteDialogResult>
}

[GenerateOneOf]
public sealed partial class DeleteDialogResult : OneOfBase<Success, EntityNotFound, BadRequest, Forbidden, ConcurrencyError>;
public sealed partial class DeleteDialogResult : OneOfBase<Success, EntityNotFound, EntityDeleted, Forbidden, ConcurrencyError>;

internal sealed class DeleteDialogCommandHandler : IRequestHandler<DeleteDialogCommand, DeleteDialogResult>
{
Expand Down Expand Up @@ -56,7 +56,7 @@ public async Task<DeleteDialogResult> Handle(DeleteDialogCommand request, Cancel
{
// TODO: https://github.com/digdir/dialogporten/issues/1543
// When restoration is implemented, add a hint to the error message.
return new BadRequest($"Entity '{nameof(DialogEntity)}' with key '{request.Id}' has already been removed and cannot be deleted again.");
return new EntityDeleted<DialogEntity>(request.Id);
}

if (!_userResourceRegistry.UserCanModifyResourceType(dialog.ServiceResourceType))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public async Task<UpdateDialogResult> Handle(UpdateDialogCommand request, Cancel
{
// TODO: https://github.com/digdir/dialogporten/issues/1543
// When restoration is implemented, add a hint to the error message.
return new EntityDeleted($"Entity '{nameof(DialogEntity)}' with key '{request.Id}' is removed, and cannot be updated.");
return new EntityDeleted<DialogEntity>(request.Id);
}

// Ensure transmissions have a UUIDv7 ID, needed for the transmission hierarchy validation.
Expand Down
1 change: 1 addition & 0 deletions src/Digdir.Domain.Dialogporten.WebApi/Common/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ internal static class SwaggerSummary
internal const string ServiceOwnerAuthenticationFailure = "Missing or invalid authentication token. Requires a Maskinporten-token with the scope \"{0}\".";
internal const string EndUserAuthenticationFailure = "Missing or invalid authentication token. Requires a Maskinporten-token with the scope \"digdir:dialogporten\".";
internal const string DialogNotFound = "The given dialog ID was not found or is already deleted.";
internal const string DialogDeleted = $"Entity with the given key(s) is removed";
internal const string DialogActivityNotFound = "The given dialog ID was not found or was deleted, or the given activity ID was not found.";
internal const string DialogTransmissionNotFound = "The given dialog ID was not found or was deleted, or the given transmission ID was not found.";
internal const string RevisionMismatch = "The supplied If-Match header did not match the current Revision value for the dialog. The request was not applied.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public override void Configure()
StatusCodes.Status201Created,
StatusCodes.Status400BadRequest,
StatusCodes.Status404NotFound,
StatusCodes.Status410Gone,
StatusCodes.Status412PreconditionFailed,
StatusCodes.Status422UnprocessableEntity));
}
Expand Down Expand Up @@ -66,7 +67,7 @@ await errors.Match(
await result.Match(
success => SendCreatedAtAsync<GetDialogActivityEndpoint>(new GetActivityQuery { DialogId = dialog.Id, ActivityId = req.Id.Value }, req.Id, cancellation: ct),
notFound => this.NotFoundAsync(notFound, ct),
badRequest => this.BadRequestAsync(badRequest, ct),
gone => this.GoneAsync(gone, ct),
validationError => this.BadRequestAsync(validationError, ct),
forbidden => this.ForbiddenAsync(forbidden, ct),
domainError => this.UnprocessableEntityAsync(domainError, ct),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The activity is created with the given configuration. For more information see t
Responses[StatusCodes.Status401Unauthorized] = Constants.SwaggerSummary.ServiceOwnerAuthenticationFailure.FormatInvariant(AuthorizationScope.ServiceProvider);
Responses[StatusCodes.Status403Forbidden] = Constants.SwaggerSummary.AccessDeniedToDialogForChildEntity.FormatInvariant("create");
Responses[StatusCodes.Status404NotFound] = Constants.SwaggerSummary.DialogNotFound;
Responses[StatusCodes.Status410Gone] = Constants.SwaggerSummary.DialogDeleted;
Responses[StatusCodes.Status412PreconditionFailed] = Constants.SwaggerSummary.RevisionMismatch;
Responses[StatusCodes.Status422UnprocessableEntity] = Constants.SwaggerSummary.DomainError;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public override void Configure()
StatusCodes.Status201Created,
StatusCodes.Status400BadRequest,
StatusCodes.Status404NotFound,
StatusCodes.Status410Gone,
StatusCodes.Status412PreconditionFailed,
StatusCodes.Status422UnprocessableEntity));
}
Expand Down Expand Up @@ -67,7 +68,7 @@ await errors.Match(
await result.Match(
success => SendCreatedAtAsync<GetDialogTransmissionEndpoint>(new GetTransmissionQuery { DialogId = dialog.Id, TransmissionId = req.Id.Value }, req.Id, cancellation: ct),
notFound => this.NotFoundAsync(notFound, ct),
badRequest => this.BadRequestAsync(badRequest, ct),
gone => this.GoneAsync(gone, ct),
validationError => this.BadRequestAsync(validationError, ct),
forbidden => this.ForbiddenAsync(forbidden, ct),
domainError => this.UnprocessableEntityAsync(domainError, ct),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The transmission is created with the given configuration. For more information s
Responses[StatusCodes.Status401Unauthorized] = Constants.SwaggerSummary.ServiceOwnerAuthenticationFailure.FormatInvariant(AuthorizationScope.ServiceProvider);
Responses[StatusCodes.Status403Forbidden] = Constants.SwaggerSummary.AccessDeniedToDialogForChildEntity.FormatInvariant("create");
Responses[StatusCodes.Status404NotFound] = Constants.SwaggerSummary.DialogNotFound;
Responses[StatusCodes.Status410Gone] = Constants.SwaggerSummary.DialogDeleted;
Responses[StatusCodes.Status412PreconditionFailed] = Constants.SwaggerSummary.RevisionMismatch;
Responses[StatusCodes.Status422UnprocessableEntity] = Constants.SwaggerSummary.DomainError;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public override void Configure()
StatusCodes.Status204NoContent,
StatusCodes.Status400BadRequest,
StatusCodes.Status404NotFound,
StatusCodes.Status410Gone,
StatusCodes.Status412PreconditionFailed));
}

Expand All @@ -37,7 +38,7 @@ public override async Task HandleAsync(DeleteDialogRequest req, CancellationToke
await result.Match(
success => SendNoContentAsync(ct),
notFound => this.NotFoundAsync(notFound, ct),
badRequest => this.BadRequestAsync(badRequest, ct),
gone => this.GoneAsync(gone, ct),
forbidden => this.ForbiddenAsync(forbidden, ct),
concurrencyError => this.PreconditionFailed(ct));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Deletes a given dialog (soft delete). For more information see the documentation
Responses[StatusCodes.Status403Forbidden] = Constants.SwaggerSummary.AccessDeniedToDialog.FormatInvariant("delete");
Responses[StatusCodes.Status400BadRequest] = Constants.SwaggerSummary.ValidationError;
Responses[StatusCodes.Status404NotFound] = Constants.SwaggerSummary.DialogNotFound;
Responses[StatusCodes.Status410Gone] = Constants.SwaggerSummary.DialogDeleted;
Responses[StatusCodes.Status412PreconditionFailed] = Constants.SwaggerSummary.RevisionMismatch;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public override void Configure()
StatusCodes.Status204NoContent,
StatusCodes.Status400BadRequest,
StatusCodes.Status404NotFound,
StatusCodes.Status410Gone,
StatusCodes.Status412PreconditionFailed,
StatusCodes.Status422UnprocessableEntity));
}
Expand All @@ -44,7 +45,7 @@ public override async Task HandleAsync(UpdateDialogRequest req, CancellationToke
await updateDialogResult.Match(
success => SendNoContentAsync(ct),
notFound => this.NotFoundAsync(notFound, ct),
badRequest => this.BadRequestAsync(badRequest, ct),
gone => this.GoneAsync(gone, ct),
validationFailed => this.BadRequestAsync(validationFailed, ct),
forbidden => this.ForbiddenAsync(forbidden, ct),
domainError => this.UnprocessableEntityAsync(domainError, ct),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Replaces a given dialog with the supplied model. For more information see the do
Responses[StatusCodes.Status403Forbidden] =
Constants.SwaggerSummary.AccessDeniedToDialog.FormatInvariant("update");
Responses[StatusCodes.Status404NotFound] = Constants.SwaggerSummary.DialogNotFound;
Responses[StatusCodes.Status410Gone] = Constants.SwaggerSummary.DialogDeleted;
Responses[StatusCodes.Status412PreconditionFailed] = Constants.SwaggerSummary.RevisionMismatch;
Responses[StatusCodes.Status422UnprocessableEntity] = Constants.SwaggerSummary.DomainError;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ public async Task Updating_Deleted_Dialog_Should_Return_BadRequest()
// Assert
updateDialogResponse.TryPickT2(out var validationError, out _).Should().BeTrue();
validationError.Should().NotBeNull();
validationError.Reasons.Should().Contain(e => e.Contains("cannot be updated"));
validationError.Reasons.Should().Contain(e => e.Contains(dialogId.ToString()));
validationError.Message.Should().Contain(dialogId.ToString());
}
}

0 comments on commit 1056bc1

Please sign in to comment.