Skip to content

Commit

Permalink
Fixed status mapping for AcceptResponse based on the feedback from @h…
Browse files Browse the repository at this point in the history
  • Loading branch information
oskardudycz authored and jeremydmiller committed Feb 15, 2024
1 parent 072ad19 commit b99574a
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public async Task accept_response_returns_proper_status_and_url()
{
x.Post.Json(new ConfirmOrder(status.OrderId)).ToUrl($"/orders/{status.OrderId}/confirm");

x.StatusCodeShouldBe(204);
x.StatusCodeShouldBe(202);
});

var acceptResponse = await result.ReadAsJsonAsync<AcceptResponse>();
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Wolverine.Http/IHttpAware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public record AcceptResponse(string Url) : IHttpAware
{
public static void PopulateMetadata(MethodInfo method, EndpointBuilder builder)
{
builder.RemoveStatusCodeResponse(202);
builder.RemoveStatusCodeResponse(200);

var create = new MethodCall(method.DeclaringType!, method).Creates.FirstOrDefault()?.VariableType;
var metadata = new WolverineProducesResponseTypeMetadata { Type = create, StatusCode = 202 };
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// <auto-generated/>
#pragma warning disable
using Microsoft.AspNetCore.Routing;
using System;
using System.Linq;
using Wolverine.Http;
using Wolverine.Marten.Publishing;
using Wolverine.Runtime;

namespace Internal.Generated.WolverineHandlers
{
// START: POST_orders_id_confirm
public class POST_orders_id_confirm : Wolverine.Http.HttpHandler
{
private readonly Wolverine.Http.WolverineHttpOptions _wolverineHttpOptions;
private readonly Wolverine.Runtime.IWolverineRuntime _wolverineRuntime;
private readonly Wolverine.Marten.Publishing.OutboxedSessionFactory _outboxedSessionFactory;

public POST_orders_id_confirm(Wolverine.Http.WolverineHttpOptions wolverineHttpOptions, Wolverine.Runtime.IWolverineRuntime wolverineRuntime, Wolverine.Marten.Publishing.OutboxedSessionFactory outboxedSessionFactory) : base(wolverineHttpOptions)
{
_wolverineHttpOptions = wolverineHttpOptions;
_wolverineRuntime = wolverineRuntime;
_outboxedSessionFactory = outboxedSessionFactory;
}



public override async System.Threading.Tasks.Task Handle(Microsoft.AspNetCore.Http.HttpContext httpContext)
{
var messageContext = new Wolverine.Runtime.MessageContext(_wolverineRuntime);
// Reading the request body via JSON deserialization
var (command, jsonContinue) = await ReadJsonAsync<WolverineWebApi.Marten.ConfirmOrder>(httpContext);
if (jsonContinue == Wolverine.HandlerContinuation.Stop) return;
await using var documentSession = _outboxedSessionFactory.OpenSession(messageContext);
var eventStore = documentSession.Events;

// Loading Marten aggregate
var eventStream = await eventStore.FetchForWriting<WolverineWebApi.Marten.Order>(command.OrderId, httpContext.RequestAborted).ConfigureAwait(false);


// The actual HTTP request handler execution
(var acceptResponse_response, var events) = WolverineWebApi.Marten.MarkItemEndpoint.Confirm(command, eventStream.Aggregate);

if (events != null)
{

// Capturing any possible events returned from the command handlers
eventStream.AppendMany(events);

}

// This response type customizes the HTTP response
ApplyHttpAware(acceptResponse_response, httpContext);
await documentSession.SaveChangesAsync(httpContext.RequestAborted).ConfigureAwait(false);
// Writing the response body to JSON because this was the first 'return variable' in the method signature
await WriteJsonAsync(httpContext, acceptResponse_response);
}

}

// END: POST_orders_id_confirm


}

0 comments on commit b99574a

Please sign in to comment.