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

fix: 412 status on multiple requests without revision header #427

Merged
merged 18 commits into from
Feb 12, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Rename to IfMatchDialogRevision
oskogstad committed Feb 9, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 7657c68e44952c2cf14f8e422523784fdf4936e1
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ namespace Digdir.Domain.Dialogporten.Application.Features.V1.EndUser.Dialogs.Que
public sealed class GetDialogDto
{
public Guid Id { get; set; }
public Guid Revision { get; set; }
public Guid IfMatchDialogRevision { get; set; }
oskogstad marked this conversation as resolved.
Show resolved Hide resolved
public string Org { get; set; } = null!;
public string ServiceResource { get; set; } = null!;
public string Party { get; set; } = null!;
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ namespace Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialog
public sealed class DeleteDialogCommand : IRequest<DeleteDialogResult>
{
public Guid Id { get; set; }
public Guid? Revision { get; set; }
public Guid? IfMatchDialogRevision { get; set; }
}

[GenerateOneOf]
@@ -51,9 +51,9 @@ public async Task<DeleteDialogResult> Handle(DeleteDialogCommand request, Cancel
return new EntityNotFound<DialogEntity>(request.Id);
}

_db.TrySetOriginalRevision(dialog, request.Revision);
_db.TrySetOriginalRevision(dialog, request.IfMatchDialogRevision);
_db.Dialogs.SoftRemove(dialog);
var saveResult = await _unitOfWork.SaveChangesAsync(optimisticConcurrency: !request.Revision.HasValue, cancellationToken);
var saveResult = await _unitOfWork.SaveChangesAsync(optimisticConcurrency: !request.IfMatchDialogRevision.HasValue, cancellationToken);
oskogstad marked this conversation as resolved.
Show resolved Hide resolved
return saveResult.Match<DeleteDialogResult>(
success => success,
domainError => throw new UnreachableException("Should never get a domain error when creating a new dialog"),
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ namespace Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialog
public sealed class UpdateDialogCommand : IRequest<UpdateDialogResult>
{
public Guid Id { get; set; }
public Guid? Revision { get; set; }
public Guid? IfMatchDialogRevision { get; set; }
public UpdateDialogDto Dto { get; set; } = null!;
}

@@ -75,7 +75,7 @@ public async Task<UpdateDialogResult> Handle(UpdateDialogCommand request, Cancel
return new EntityNotFound<DialogEntity>(request.Id);
}

_db.TrySetOriginalRevision(dialog, request.Revision);
_db.TrySetOriginalRevision(dialog, request.IfMatchDialogRevision);

// Update primitive properties
_mapper.Map(request.Dto, dialog);
@@ -123,7 +123,7 @@ await dialog.Elements
update: UpdateApiActions,
delete: DeleteDelegate.NoOp);

var saveResult = await _unitOfWork.SaveChangesAsync(optimisticConcurrency: !request.Revision.HasValue, cancellationToken);
var saveResult = await _unitOfWork.SaveChangesAsync(optimisticConcurrency: !request.IfMatchDialogRevision.HasValue, cancellationToken);
oskogstad marked this conversation as resolved.
Show resolved Hide resolved
return saveResult.Match<UpdateDialogResult>(
success => success,
domainError => domainError,
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ namespace Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialog
public sealed class GetDialogDto
{
public Guid Id { get; set; }
public Guid Revision { get; set; }
public Guid IfMatchDialogRevision { get; set; }
public string Org { get; set; } = null!;
public string ServiceResource { get; set; } = null!;
public string Party { get; set; } = null!;
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ internal sealed class MappingProfile : Profile
public MappingProfile()
{
CreateMap<DialogEntity, GetDialogDto>()
.ForMember(dest => dest.IfMatchDialogRevision, opt => opt.MapFrom(src => src.Revision))
.ForMember(dest => dest.Status, opt => opt.MapFrom(src => src.StatusId));

CreateMap<DialogActivity, GetDialogDialogActivityDto>()
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ public override async Task HandleAsync(GetDialogQuery req, CancellationToken ct)
await result.Match(
dto =>
{
HttpContext.Response.Headers.ETag = dto.Revision.ToString();
HttpContext.Response.Headers.ETag = dto.IfMatchDialogRevision.ToString();
return SendOkAsync(dto, ct);
},
notFound => this.NotFoundAsync(notFound, ct),
Original file line number Diff line number Diff line change
@@ -60,7 +60,7 @@ public override async Task HandleAsync(CreateDialogActivityRequest req, Cancella

updateDialogDto.Activities.Add(req);

var updateDialogCommand = new UpdateDialogCommand { Id = req.DialogId, Revision = req.IfMatchDialogRevision, Dto = updateDialogDto };
var updateDialogCommand = new UpdateDialogCommand { Id = req.DialogId, IfMatchDialogRevision = req.IfMatchDialogRevision, Dto = updateDialogDto };

var result = await _sender.Send(updateDialogCommand, ct);
await result.Match(
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@ public override async Task HandleAsync(CreateDialogElementRequest req, Cancellat

updateDialogDto.Elements.Add(req);

var updateDialogCommand = new UpdateDialogCommand { Id = req.DialogId, Revision = req.IfMatchDialogRevision, Dto = updateDialogDto };
var updateDialogCommand = new UpdateDialogCommand { Id = req.DialogId, IfMatchDialogRevision = req.IfMatchDialogRevision, Dto = updateDialogDto };

var result = await _sender.Send(updateDialogCommand, ct);
await result.Match(
Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@ public override async Task HandleAsync(DeleteDialogElementRequest req, Cancellat
updateDialogDto.Elements.Remove(dialogElement);

var updateDialogCommand = new UpdateDialogCommand
{ Id = req.DialogId, Revision = req.Revision, Dto = updateDialogDto };
{ Id = req.DialogId, IfMatchDialogRevision = req.IfMatchDialogRevision, Dto = updateDialogDto };

var result = await _sender.Send(updateDialogCommand, ct);
await result.Match(
@@ -82,7 +82,7 @@ public sealed class DeleteDialogElementRequest
public Guid ElementId { get; set; }

[FromHeader(headerName: Constants.IfMatch, isRequired: false, removeFromSchema: true)]
public Guid? Revision { get; set; }
public Guid? IfMatchDialogRevision { get; set; }
}

public sealed class DeleteDialogElementEndpointSummary : Summary<DeleteDialogElementEndpoint>
Original file line number Diff line number Diff line change
@@ -66,7 +66,7 @@ await this.NotFoundAsync(
updateDialogDto.Elements.Add(updateDialogElementDto);

var updateDialogCommand = new UpdateDialogCommand
{ Id = req.DialogId, Revision = req.IfMatchDialogRevision, Dto = updateDialogDto };
{ Id = req.DialogId, IfMatchDialogRevision = req.IfMatchDialogRevision, Dto = updateDialogDto };

var result = await _sender.Send(updateDialogCommand, ct);
await result.Match(
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ public override void Configure()

public override async Task HandleAsync(DeleteDialogRequest req, CancellationToken ct)
{
var command = new DeleteDialogCommand { Id = req.DialogId, Revision = req.Revision };
var command = new DeleteDialogCommand { Id = req.DialogId, IfMatchDialogRevision = req.IfMatchDialogRevision };
var result = await _sender.Send(command, ct);
await result.Match(
success => SendNoContentAsync(ct),
@@ -47,7 +47,7 @@ public sealed class DeleteDialogRequest
public Guid DialogId { get; set; }

[FromHeader(headerName: Constants.IfMatch, isRequired: false, removeFromSchema: true)]
public Guid? Revision { get; set; }
public Guid? IfMatchDialogRevision { get; set; }
}

public sealed class DeleteDialogEndpointSummary : Summary<DeleteDialogEndpoint>
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ public override async Task HandleAsync(GetDialogQuery req, CancellationToken ct)
await result.Match(
dto =>
{
HttpContext.Response.Headers.ETag = dto.Revision.ToString();
HttpContext.Response.Headers.ETag = dto.IfMatchDialogRevision.ToString();
return SendOkAsync(dto, ct);
},
notFound => this.NotFoundAsync(notFound, ct));
Original file line number Diff line number Diff line change
@@ -77,7 +77,7 @@ public async Task<IActionResult> Patch(
return BadRequest(ModelState);
}

var command = new UpdateDialogCommand { Id = dialogId, Revision = etag, Dto = updateDialogDto };
var command = new UpdateDialogCommand { Id = dialogId, IfMatchDialogRevision = etag, Dto = updateDialogDto };
var result = await _sender.Send(command, ct);
return result.Match(
success => (IActionResult)NoContent(),
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ public override void Configure()

public override async Task HandleAsync(UpdateDialogRequest req, CancellationToken ct)
{
var command = new UpdateDialogCommand { Id = req.DialogId, Revision = req.IfMatchDialogRevision, Dto = req.Dto };
var command = new UpdateDialogCommand { Id = req.DialogId, IfMatchDialogRevision = req.IfMatchDialogRevision, Dto = req.Dto };
var updateDialogResult = await _sender.Send(command, ct);
await updateDialogResult.Match(
success => SendNoContentAsync(ct),