public async Task <IActionResult> UpdateExampleAggregate( [FromServices] ICommandHandlerResolver bus, [FromCommandId] Guid commandId, [FromRoute] Guid exampleAggregateId, [FromBody] UpdateExampleAggregateRequest request, CancellationToken cancellationToken = default) { if (request != null) { request.Id = exampleAggregateId; } await new UpdateExampleAggregateRequestValidator() .ValidateAndThrowAsync(request, cancellationToken: cancellationToken); var command = UpdateExampleAggregateRequestMapping.Map(request); return(Accepted( $"/v1/example-aggregates/{command.ExampleAggregateId}", await bus.Dispatch( commandId, command, GetMetadata(), cancellationToken))); }
public async Task <IActionResult> AddGoogleSuiteService( [FromServices] ICommandHandlerResolver bus, [FromServices] ApiProjectionsContext context, [FromCommandId] Guid commandId, [FromRoute] string secondLevelDomain, [FromRoute] string topLevelDomain, [FromBody] AddGoogleSuiteServiceRequest request, CancellationToken cancellationToken = default) { if (request != null) { request.SecondLevelDomain = secondLevelDomain; request.TopLevelDomain = topLevelDomain; } // TODO: We can check in the eventstore if those aggregates even exist await new AddGoogleSuiteServiceRequestValidator() .ValidateAndThrowAsync(request, cancellationToken: cancellationToken); var command = AddGoogleSuiteServiceRequestMapping.Map( new DomainName( new SecondLevelDomain(secondLevelDomain), TopLevelDomain.FromValue(topLevelDomain)), request); return(Accepted( $"/v1/domains/{command.DomainName}/services/{command.ServiceId}", new LastObservedPositionResponse( await bus.Dispatch( commandId, command, GetMetadata(), cancellationToken)))); }
public async Task <IActionResult> CreateDomain( [FromServices] ICommandHandlerResolver bus, [FromCommandId] Guid commandId, [FromBody] CreateDomainRequest request, CancellationToken cancellationToken = default) { // TODO: Get this validator from DI await new CreateDomainRequestValidator() .ValidateAndThrowAsync(request, cancellationToken: cancellationToken); var command = CreateDomainRequestMapping.Map(request); // TODO: Sending null for top level domain should give a decent error, not 500 // TODO: Apikey description in documentation should be translatable // TODO: Add bad format response code if it is not json return(Accepted( $"/v1/domains/{command.DomainName}", new LastObservedPositionResponse( await bus.Dispatch( commandId, command, GetMetadata(), cancellationToken)))); }
public async Task <IActionResult> RemoveService( [FromServices] ICommandHandlerResolver bus, [FromServices] ApiProjectionsContext context, [FromCommandId] Guid commandId, [FromRoute] string secondLevelDomain, [FromRoute] string topLevelDomain, [FromRoute] Guid?serviceId, CancellationToken cancellationToken = default) { var request = new RemoveServiceRequest { SecondLevelDomain = secondLevelDomain, TopLevelDomain = topLevelDomain, ServiceId = serviceId }; // TODO: We can check in the eventstore if those aggregates even exist await new RemoveServiceRequestValidator() .ValidateAndThrowAsync(request, cancellationToken: cancellationToken); var command = RemoveServiceRequestMapping.Map(request); return(Accepted( $"/v1/domains/{command.DomainName}/services", new LastObservedPositionResponse( await bus.Dispatch( commandId, command, GetMetadata(), cancellationToken)))); }
public async Task <IActionResult> AddAddress( [FromServices] ICommandHandlerResolver bus, [FromServices] AddressCrabEditClient editClient, [FromServices] Func <IAddresses> getAddresses, [FromBody] AddAddressRequest request, CancellationToken cancellationToken) { // TODO: Turn this into proper VBR API Validation if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var crabAddAddress = await AddToCrab(editClient, request, cancellationToken); var addressId = crabAddAddress.Result; // todo: add command implementation for BoxNumber var command = new RegisterAddress( addressId, StreetNameId.CreateForPersistentId(request.StreetNameId.AsIdentifier().Map(IdentifierMappings.StreetNameId)), PostalCode.CreateForPersistentId(request.PostalCode.AsIdentifier().Map(IdentifierMappings.PostalCode)), new HouseNumber(request.HouseNumber), new BoxNumber(request.BoxNumber)); var position = await bus.Dispatch( Guid.NewGuid(), command, GetMetadata(), cancellationToken); // Because we don't use the addressId as an identifier, we are stuck with the mess of retrieving our aggregate // and getting the surrogate identifier from it.... PersistentLocalIdentifier var addresses = getAddresses(); var address = await addresses.GetOptionalAsync(addressId, cancellationToken); if (!address.HasValue) { throw new ApiException("Er is een fout opgetreden.", StatusCodes.Status500InternalServerError); } return(CreatedWithPosition( $"/v1/adressen/{address.Value.PersistentLocalId}", position, crabAddAddress.ExecutionTime)); }
public async Task <IActionResult> CreateDomain( [FromServices] ICommandHandlerResolver bus, [FromCommandId] Guid commandId, [FromBody] RegisterOrganisationRequest request, CancellationToken cancellationToken = default) { await new RegisterOrganisationRequestValidator() .ValidateAndThrowAsync(request, cancellationToken: cancellationToken); var command = RegisterOrganisationRequestMapping.Map(request); return(Accepted( $"/v1/organisations/{command.OvoNumber}", await bus.Dispatch( commandId, command, GetMetadata(), cancellationToken))); }
public async Task <IActionResult> CreateAccount( [FromServices] ICommandHandlerResolver bus, [FromCommandId] Guid commandId, [FromBody] CreateAccountRequest request, CancellationToken cancellationToken = default) { await new CreateAccountRequestValidator() .ValidateAndThrowAsync(request, cancellationToken: cancellationToken); var command = CreateAccountRequestMapping.Map(request); return(Accepted( $"/v1/accounts/{command.AccountId}", await bus.Dispatch( commandId, command, GetMetadata(), cancellationToken))); }