Skip to content

Instantly share code, notes, and snippets.

@ankitvijay
Created October 8, 2021 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ankitvijay/374b1aff919ab362a46af20e5529361b to your computer and use it in GitHub Desktop.
Save ankitvijay/374b1aff919ab362a46af20e5529361b to your computer and use it in GitHub Desktop.
NServiceBus Cosmos Sample - Add API
app.MapPost("/create", async (IMessageSession messageSession, [FromBody] Post post) =>
{
var addPostCommand = new Messages.AddPost(post.Title, post.Description, post.Author);
await messageSession.Send(addPostCommand);
return Results.Accepted(null, new { addPostCommand.PostId });
});
app.MapPost("/add-comment", async (IMessageSession messageSession, [FromBody] Comment comment) =>
{
var addCommentCommand = new Messages.AddComment(comment.PostId, comment.Content, comment.CommentBy);
await messageSession.Send(addCommentCommand);
return Results.Accepted(null, new { addCommentCommand.CommentId });
});
app.Run();
public record Post(string Title, string Description, string Author);
public record Comment(string PostId, string Content, string CommentBy);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment