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

@@ -1,34 +1,34 @@
using ConnectionsAPI.Database.Repository;
using ConnectionsAPI.Models;
using LazyCache;
using Microsoft.EntityFrameworkCore;
// using ConnectionsAPI.Database.Repository;
// using ConnectionsAPI.Models;
// using LazyCache;
// using Microsoft.EntityFrameworkCore;
namespace ConnectionsAPI.Features.Puzzle.List
{
public class ListPuzzlesEndpoint(PuzzleRepository puzzleRepo, IAppCache cache) : EndpointWithoutRequest<ICollection<ConnectionsPuzzleDTO>>
{
private readonly PuzzleRepository _puzzleRepo = puzzleRepo;
private readonly IAppCache _cache = cache;
// namespace ConnectionsAPI.Features.Puzzle.List
// {
// public class ListPuzzlesEndpoint(PuzzleRepository puzzleRepo, IAppCache cache) : EndpointWithoutRequest<ICollection<ConnectionsPuzzleDTO>>
// {
// private readonly PuzzleRepository _puzzleRepo = puzzleRepo;
// private readonly IAppCache _cache = cache;
public override void Configure()
{
Get("/all.json",
"/puzzle/all");
AllowAnonymous();
}
// public override void Configure()
// {
// Get("/all.json",
// "/puzzle/all");
// AllowAnonymous();
// }
public override async Task HandleAsync(CancellationToken ct)
{
bool hideSolutions = Query<bool>("hideSolutions", isRequired: false);
// public override async Task HandleAsync(CancellationToken ct)
// {
// bool hideSolutions = Query<bool>("hideSolutions", isRequired: false);
// query all, ordered by print date
var puzzles = await _puzzleRepo.GetAllPuzzlesAsync(includeSolutions: !hideSolutions);
// // query all, ordered by print date
// var puzzles = await _puzzleRepo.GetAllPuzzlesAsync(includeSolutions: !hideSolutions);
// map to response object
var response = puzzles.Select(ConnectionsPuzzleDTO.FromEntity).ToList();
// // map to response object
// var response = puzzles.Select(ConnectionsPuzzleDTO.FromEntity).ToList();
// done
await SendAsync(response, cancellation: ct);
}
}
}
// // done
// await SendAsync(response, cancellation: ct);
// }
// }
// }