-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTokenPriceEndpoints.cs
More file actions
40 lines (33 loc) · 1.27 KB
/
TokenPriceEndpoints.cs
File metadata and controls
40 lines (33 loc) · 1.27 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
33
34
35
36
37
38
39
40
using Microsoft.AspNetCore.Mvc;
using Train.Solver.Common.Enums;
using Train.Solver.Data.Abstractions.Entities;
using Train.Solver.Data.Abstractions.Models;
using Train.Solver.Data.Abstractions.Repositories;
using Train.Solver.Infrastructure.Abstractions.Models;
using Train.Solver.Infrastructure.Extensions;
namespace Train.Solver.AdminAPI.Endpoints;
public static class TokenPriceEndpoints
{
public static RouteGroupBuilder MapTokenPriceEndpoints(this RouteGroupBuilder group)
{
group.MapGet("/token-prices", GetAllTokenPricesAsync)
.Produces<List<TokenPriceDto>>();
group.MapPost("/token-prices", CreateTokenPriceAsync)
.Produces(200);
return group;
}
private static async Task<IResult> GetAllTokenPricesAsync(ITokenPriceRepository repository)
{
var tokenPrices = await repository.GetAllAsync();
return Results.Ok(tokenPrices.Select(x => x.ToDto()));
}
private static async Task<IResult> CreateTokenPriceAsync(
ITokenPriceRepository repository,
CreateTokenPriceRequest request)
{
var tokenPrice = await repository.CreateAsync(request);
return tokenPrice is null
? Results.BadRequest("Failed to create token price")
: Results.Ok();
}
}