-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCreateExampleEndpoint.cs
More file actions
32 lines (29 loc) · 1.12 KB
/
CreateExampleEndpoint.cs
File metadata and controls
32 lines (29 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using MinimalApi.Domain.Examples;
namespace MinimalApi.Features.Examples.CreateExample
{
public class CreateExampleEndpoint(IExampleService s) : RadEndpoint<CreateExampleRequest, CreateExampleResponse, CreateExampleMapper>
{
public override void Configure()
{
Post("/examples")
.Produces<CreateExampleResponse>(StatusCodes.Status201Created)
.ProducesProblem(StatusCodes.Status409Conflict)
.ProducesValidationProblem()
.WithDocument(tag: Constants.ExamplesTag, desc: "Create a new example.");
}
public override async Task Handle(CreateExampleRequest r, CancellationToken ct)
{
var result = await s.InsertExample(Map.ToEntity(r));
result.Switch
(
example =>
{
Response = Map.FromEntity(example);
Response.Message = "Example created successfully";
SendCreatedAt($"/examples/{example.Id}");
},
conflict => SendProblem(conflict)
);
}
}
}