Skip to content

Commit

Permalink
pffft
Browse files Browse the repository at this point in the history
  • Loading branch information
oskogstad committed Dec 24, 2024
1 parent 80261d1 commit f88b1ba
Show file tree
Hide file tree
Showing 24 changed files with 254 additions and 144 deletions.
25 changes: 19 additions & 6 deletions docs/schema/V1/swagger.verified.json
Original file line number Diff line number Diff line change
Expand Up @@ -2243,7 +2243,7 @@
},
"type": "object"
},
"V1ServiceOwnerDialogsCommandsCreate_DialogCommand": {
"V1ServiceOwnerDialogsCommandsCreate_Dialog": {
"additionalProperties": false,
"properties": {
"activities": {
Expand Down Expand Up @@ -3221,6 +3221,18 @@
},
"type": "object"
},
"V1ServiceOwnerDialogsCreate_DialogRequest": {
"additionalProperties": false,
"properties": {
"dto": {
"$ref": "#/components/schemas/V1ServiceOwnerDialogsCommandsCreate_Dialog"
},
"produceDialogEvents": {
"type": "boolean"
}
},
"type": "object"
},
"V1ServiceOwnerDialogSeenLogsQueriesGet_SeenLog": {
"additionalProperties": false,
"properties": {
Expand Down Expand Up @@ -4237,6 +4249,9 @@
"properties": {
"dto": {
"$ref": "#/components/schemas/V1ServiceOwnerDialogsCommandsUpdate_Dialog"
},
"produceDialogEvents": {
"type": "boolean"
}
},
"type": "object"
Expand Down Expand Up @@ -5832,14 +5847,12 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/V1ServiceOwnerDialogsCommandsCreate_DialogCommand"
"$ref": "#/components/schemas/V1ServiceOwnerDialogsCommandsCreate_Dialog"
}
}
},
"description": "",
"required": true,
"x-name": "CreateDialogCommand",
"x-position": 1
"x-name": "dto"
},
"responses": {
"201": {
Expand Down Expand Up @@ -6970,4 +6983,4 @@
"url": "https://altinn-dev-api.azure-api.net/dialogporten"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public async Task<SetResourceTypeResult> SetResourceType(DialogEntity dialog, Ca
if (serviceResourceInformation is null)
{
var supportedResourceTypes = string.Join(", ", Constants.SupportedResourceTypes);
_domainContext.AddError(nameof(CreateDialogCommand.ServiceResource),
_domainContext.AddError(nameof(CreateDialogDto.ServiceResource),
$"Service resource '{dialog.ServiceResource}' does not exist in the resource " +
$"registry, or is not of the following supported resource types: " +
$"[{supportedResourceTypes}].");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@

namespace Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Commands.Create;

public sealed class CreateDialogCommand : CreateDialogDto, IRequest<CreateDialogResult>;
public sealed class CreateDialogCommand : IRequest<CreateDialogResult>
{
public bool ProduceDialogEvents { get; init; } = true;
public CreateDialogDto Dto { get; set; } = null!;
}

[GenerateOneOf]
public sealed partial class CreateDialogResult : OneOfBase<Success<Guid>, DomainError, ValidationError, Forbidden>;
Expand Down Expand Up @@ -54,7 +58,7 @@ public CreateDialogCommandHandler(

public async Task<CreateDialogResult> Handle(CreateDialogCommand request, CancellationToken cancellationToken)
{
var dialog = _mapper.Map<DialogEntity>(request);
var dialog = _mapper.Map<DialogEntity>(request.Dto);

await _serviceResourceAuthorizer.SetResourceType(dialog, cancellationToken);
var serviceResourceAuthorizationResult = await _serviceResourceAuthorizer.AuthorizeServiceResources(dialog, cancellationToken);
Expand Down Expand Up @@ -86,7 +90,7 @@ public async Task<CreateDialogResult> Handle(CreateDialogCommand request, Cancel
_domainContext.AddErrors(dialog.Transmissions.ValidateReferenceHierarchy(
keySelector: x => x.Id,
parentKeySelector: x => x.RelatedTransmissionId,
propertyName: nameof(CreateDialogCommand.Transmissions),
propertyName: nameof(CreateDialogDto.Transmissions),
maxDepth: 100,
maxWidth: 1));

Expand All @@ -101,7 +105,7 @@ public async Task<CreateDialogResult> Handle(CreateDialogCommand request, Cancel
private void CreateDialogEndUserContext(CreateDialogCommand request, DialogEntity dialog)
{
dialog.DialogEndUserContext = new();
if (!request.SystemLabel.HasValue)
if (!request.Dto.SystemLabel.HasValue)
{
return;
}
Expand All @@ -113,7 +117,7 @@ private void CreateDialogEndUserContext(CreateDialogCommand request, DialogEntit
}

dialog.DialogEndUserContext.UpdateLabel(
request.SystemLabel.Value,
request.Dto.SystemLabel.Value,
$"{NorwegianOrganizationIdentifier.PrefixWithSeparator}{organizationNumber}",
ActorType.Values.ServiceOwner);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,17 @@ namespace Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialog

internal sealed class CreateDialogCommandValidator : AbstractValidator<CreateDialogCommand>
{
public CreateDialogCommandValidator(
public CreateDialogCommandValidator(IValidator<CreateDialogDto> createDialogDtoValidator)
{
RuleFor(x => x.Dto)
.NotEmpty()
.SetValidator(createDialogDtoValidator);
}
}

internal sealed class CreateDialogDtoValidator : AbstractValidator<CreateDialogDto>
{
public CreateDialogDtoValidator(
IValidator<TransmissionDto> transmissionValidator,
IValidator<AttachmentDto> attachmentValidator,
IValidator<GuiActionDto> guiActionValidator,
Expand All @@ -35,13 +45,13 @@ public CreateDialogCommandValidator(

RuleFor(x => x.CreatedAt)
.NotEmpty()
.WithMessage($"{{PropertyName}} must not be empty when '{nameof(CreateDialogCommand.UpdatedAt)} is set.")
.WithMessage($"{{PropertyName}} must not be empty when '{nameof(CreateDialogDto.UpdatedAt)} is set.")
.When(x => x.UpdatedAt != default);

RuleFor(x => x.UpdatedAt)
.IsInPast()
.GreaterThanOrEqualTo(x => x.CreatedAt)
.WithMessage($"'{{PropertyName}}' must be greater than or equal to '{nameof(CreateDialogCommand.CreatedAt)}'.")
.WithMessage($"'{{PropertyName}}' must be greater than or equal to '{nameof(CreateDialogDto.CreatedAt)}'.")
.When(x => x.CreatedAt != default && x.UpdatedAt != default);

RuleFor(x => x.ServiceResource)
Expand Down Expand Up @@ -136,7 +146,7 @@ public CreateDialogCommandValidator(

RuleFor(x => x.Process)
.NotEmpty()
.WithMessage($"{{PropertyName}} must not be empty when {nameof(CreateDialogCommand.PrecedingProcess)} is set.")
.WithMessage($"{{PropertyName}} must not be empty when {nameof(CreateDialogDto.PrecedingProcess)} is set.")
.When(x => x.PrecedingProcess is not null);

RuleFor(x => x.PrecedingProcess)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Digdir.Domain.Dialogporten.Application.Features.V1.ServiceOwner.Dialogs.Commands.Create;

public class CreateDialogDto
public sealed class CreateDialogDto
{
/// <summary>
/// A self-defined UUIDv7 may be provided to support idempotent creation of dialogs. If not provided, a new UUIDv7 will be generated.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public sealed class UpdateDialogCommand : IRequest<UpdateDialogResult>
public Guid Id { get; set; }
public Guid? IfMatchDialogRevision { get; set; }
public UpdateDialogDto Dto { get; set; } = null!;
public bool ProduceDialogEvents { get; set; } = true;
}

[GenerateOneOf]
Expand Down Expand Up @@ -162,6 +163,12 @@ public async Task<UpdateDialogResult> Handle(UpdateDialogCommand request, Cancel
}

UpdateLabel(dialog);

if (!request.ProduceDialogEvents)
{
_unitOfWork.WithoutAggregateSideEffects();
}

var saveResult = await _unitOfWork
.EnableConcurrencyCheck(dialog, request.IfMatchDialogRevision)
.SaveChangesAsync(cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Digdir.Domain.Dialogporten.WebApi.Endpoints.V1.ServiceOwner.Dialogs.Create;

public sealed class CreateDialogEndpoint : Endpoint<CreateDialogCommand>
public sealed class CreateDialogEndpoint : Endpoint<CreateDialogRequest>
{
private readonly ISender _sender;

Expand All @@ -30,13 +30,22 @@ public override void Configure()
StatusCodes.Status422UnprocessableEntity));
}

public override async Task HandleAsync(CreateDialogCommand req, CancellationToken ct)
public override async Task HandleAsync(CreateDialogRequest req, CancellationToken ct)
{
var result = await _sender.Send(req, ct);
var command = new CreateDialogCommand { Dto = req.Dto, ProduceDialogEvents = req.ProduceDialogEvents };
var result = await _sender.Send(command, ct);
await result.Match(
success => SendCreatedAtAsync<GetDialogEndpoint>(new GetDialogQuery { DialogId = success.Value }, success.Value, cancellation: ct),
domainError => this.UnprocessableEntityAsync(domainError, ct),
validationError => this.BadRequestAsync(validationError, ct),
forbidden => this.ForbiddenAsync(forbidden, ct));
}
}

public sealed class CreateDialogRequest
{
public bool ProduceDialogEvents { get; init; } = true;

[FromBody]
public CreateDialogDto Dto { get; set; } = null!;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public override async Task HandleAsync(UpdateDialogRequest req, CancellationToke
{
Id = req.DialogId,
IfMatchDialogRevision = req.IfMatchDialogRevision,
Dto = req.Dto
Dto = req.Dto,
ProduceDialogEvents = req.ProduceDialogEvents
};

var updateDialogResult = await _sender.Send(command, ct);
Expand All @@ -61,4 +62,6 @@ public sealed class UpdateDialogRequest

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

public bool ProduceDialogEvents { get; init; } = true;
}
Loading

0 comments on commit f88b1ba

Please sign in to comment.