refactor: Refactor Get connections

This commit is contained in:
2024-12-26 14:23:50 +01:00
parent feb47b1f8e
commit e33c270fde
11 changed files with 431 additions and 145 deletions

View File

@@ -0,0 +1,14 @@
using System;
namespace ConnectionsAPI.Features.Connections;
public class ConnectionsGroup : Group
{
public ConnectionsGroup()
{
Configure("connections", ep =>
{
ep.AllowAnonymous();
});
}
}

View File

@@ -0,0 +1,35 @@
using ConnectionsAPI.Database.Repository;
using ConnectionsAPI.Models.Request;
using ConnectionsAPI.Models.Response;
namespace ConnectionsAPI.Features.Connections.Get;
public class GetConnectionsEndpoint(PuzzleRepository _puzzleRepo) : Endpoint<GetPuzzleRequest, ConnectionsPuzzleDTO>
{
public override void Configure()
{
Get("{PrintDate}");
Group<ConnectionsGroup>();
}
public override async Task HandleAsync(GetPuzzleRequest req, CancellationToken ct)
{
bool hideSolutions = Query<bool>("hideSolutions", isRequired: false);
// query for the puzzle
var puzzle = await _puzzleRepo.GetPuzzleByDateAsync(req.PrintDate, includeSolutions: !hideSolutions);
// if not found, done here
if (puzzle == null)
{
await SendNotFoundAsync(ct);
return;
}
// get response from cache
var response = ConnectionsPuzzleDTO.FromEntity(puzzle);
// done
await SendAsync(response, cancellation: ct);
}
}