feat: WIP connections query endpoint
This commit is contained in:
@@ -7,7 +7,7 @@ public class PuzzleRepository(ConnectionsContext _db)
|
||||
{
|
||||
private readonly ConnectionsContext _db = _db;
|
||||
|
||||
public async Task<ConnectionsPuzzle?> GetPuzzleByDateAsync(string printDate, bool includeSolutions = true)
|
||||
public async Task<ConnectionsPuzzle?> GetConnectionsByDateAsync(string printDate, bool includeSolutions = true)
|
||||
{
|
||||
// query for the puzzle
|
||||
var query = _db.ConnectionsPuzzles.AsNoTracking();
|
||||
@@ -27,12 +27,12 @@ public class PuzzleRepository(ConnectionsContext _db)
|
||||
return null;
|
||||
}
|
||||
|
||||
await EnhancePuzzleWithDatesAsync(puzzle);
|
||||
await EnhanceConnectionsWithDatesAsync(puzzle);
|
||||
|
||||
return puzzle;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<ConnectionsPuzzle>> GetAllPuzzlesAsync(bool includeSolutions = true)
|
||||
public async Task<IEnumerable<ConnectionsPuzzle>> GetAllConnectionsAsync(bool includeSolutions = true)
|
||||
{
|
||||
// query all, ordered by print date
|
||||
var query = _db.ConnectionsPuzzles
|
||||
@@ -49,13 +49,13 @@ public class PuzzleRepository(ConnectionsContext _db)
|
||||
|
||||
foreach (var puzzle in result)
|
||||
{
|
||||
await EnhancePuzzleWithDatesAsync(puzzle);
|
||||
await EnhanceConnectionsWithDatesAsync(puzzle);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task EnhancePuzzleWithDatesAsync(ConnectionsPuzzle puzzle)
|
||||
private async Task EnhanceConnectionsWithDatesAsync(ConnectionsPuzzle puzzle)
|
||||
{
|
||||
string? previousPuzzleDate = await _db.ConnectionsPuzzles.AsNoTracking()
|
||||
.Where(x => x.PrintDate.CompareTo(puzzle.PrintDate) < 0)
|
||||
|
||||
@@ -17,7 +17,7 @@ public class GetConnectionsEndpoint(PuzzleRepository _puzzleRepo) : Endpoint<Get
|
||||
bool hideSolutions = Query<bool>("hideSolutions", isRequired: false);
|
||||
|
||||
// query for the puzzle
|
||||
var puzzle = await _puzzleRepo.GetPuzzleByDateAsync(req.PrintDate, includeSolutions: !hideSolutions);
|
||||
var puzzle = await _puzzleRepo.GetConnectionsByDateAsync(req.PrintDate, includeSolutions: !hideSolutions);
|
||||
|
||||
// if not found, done here
|
||||
if (puzzle == null)
|
||||
|
||||
17
Features/Connections/Query/Endpoint.cs
Normal file
17
Features/Connections/Query/Endpoint.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using ConnectionsAPI.Models.Request;
|
||||
using ConnectionsAPI.Models.Response;
|
||||
|
||||
namespace ConnectionsAPI.Features.Connections.Query;
|
||||
|
||||
public class Endpoint : Endpoint<QueryPuzzlesRequest, PagedDataResponse<ConnectionsPuzzleDTO>>
|
||||
{
|
||||
public override void Configure()
|
||||
{
|
||||
Get("query");
|
||||
}
|
||||
|
||||
public override Task HandleAsync(QueryPuzzlesRequest req, CancellationToken ct)
|
||||
{
|
||||
return base.HandleAsync(req, ct);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
|
||||
using System.Text;
|
||||
|
||||
namespace ConnectionsAPI.Features.Version.Get
|
||||
namespace ConnectionsAPI.Features.Version.Get;
|
||||
public class GetVersionEndpoint : EndpointWithoutRequest<string>
|
||||
{
|
||||
public class GetVersionEndpoint : EndpointWithoutRequest<string>
|
||||
{
|
||||
private static readonly int START_YEAR = 2024;
|
||||
|
||||
public override void Configure()
|
||||
@@ -36,5 +35,4 @@ namespace ConnectionsAPI.Features.Version.Get
|
||||
|
||||
await SendStringAsync(responseBuilder.ToString(), cancellation: ct);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
7
Models/Request/QueryPuzzlesRequest.cs
Normal file
7
Models/Request/QueryPuzzlesRequest.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace ConnectionsAPI.Models.Request;
|
||||
|
||||
public class QueryPuzzlesRequest
|
||||
{
|
||||
[QueryParam] public int Page { get; set; }
|
||||
[QueryParam] public int Count { get; set; }
|
||||
}
|
||||
8
Models/Response/PagedDataResponse.cs
Normal file
8
Models/Response/PagedDataResponse.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace ConnectionsAPI.Models.Response;
|
||||
|
||||
public record PagedDataResponse<T>(
|
||||
int Page,
|
||||
int Count,
|
||||
int MaxCount,
|
||||
ICollection<T> Data
|
||||
);
|
||||
19
Validators/QueryPuzzlesRequestValidator.cs
Normal file
19
Validators/QueryPuzzlesRequestValidator.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using ConnectionsAPI.Models.Request;
|
||||
using FluentValidation;
|
||||
|
||||
namespace ConnectionsAPI.Validators;
|
||||
|
||||
public class QueryPuzzlesRequestValidator : Validator<QueryPuzzlesRequest>
|
||||
{
|
||||
public QueryPuzzlesRequestValidator()
|
||||
{
|
||||
RuleFor(x => x.Page)
|
||||
.Must(x => x > 0)
|
||||
.WithMessage("Page number must be a positive integer");
|
||||
|
||||
RuleFor(x => x.Count)
|
||||
.Must(x => x > 0)
|
||||
.WithMessage(x => "Item count must be a positive integer");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user