WebApi + ClientApp, GraphQL, Reflection

This commit is contained in:
Boris Milašinović
2026-05-06 20:55:05 +02:00
parent 8f7c704a90
commit 4fb3de19f6
196 changed files with 10395 additions and 0 deletions

View File

@@ -0,0 +1,74 @@
using Events.EF.Data.MSSQL;
using Events.EF.Models;
using Microsoft.EntityFrameworkCore;
namespace GraphQLServer.SetupGraphQL;
public class Queries
{
[UsePaging]
[UseProjection]
[UseFiltering]
[UseSorting]
public IQueryable<Country> GetCountries([Service] EventsContext ctx) => ctx.Countries.AsNoTracking();
[UsePaging]
[UseProjection]
[UseFiltering]
[UseSorting]
public IQueryable<Sport> GetSports([Service] EventsContext ctx) => ctx.Sports.AsNoTracking();
[UsePaging]
[UseProjection]
[UseFiltering]
[UseSorting]
public IQueryable<Person> GetPeople([Service] EventsContext ctx) => ctx.People.AsNoTracking();
public async Task<PeoplePage> GetPeoplePage(
[Service] EventsContext ctx,
int pageNumber = 1,
int pageSize = 10)
{
pageNumber = Math.Max(1, pageNumber);
pageSize = Math.Clamp(pageSize, 1, 100);
var baseQuery = ctx.People
.AsNoTracking()
.OrderBy(p => p.Id);
var totalCount = await baseQuery.CountAsync();
var items = await baseQuery
.Skip((pageNumber - 1) * pageSize)
.Take(pageSize)
.ToListAsync();
return new PeoplePage
{
TotalCount = totalCount,
PageNumber = pageNumber,
PageSize = pageSize,
Items = items
};
}
[UsePaging]
[UseProjection]
[UseFiltering]
[UseSorting]
public IQueryable<Event> GetEvents([Service] EventsContext ctx) => ctx.Events.AsNoTracking();
[UsePaging]
[UseProjection]
[UseFiltering]
[UseSorting]
public IQueryable<Event> GetEventsForDate([Service] EventsContext ctx, DateOnly date) =>
ctx.Events.AsNoTracking()
.Where(e => e.EventDate == date);
[UsePaging]
[UseProjection]
[UseFiltering]
[UseSorting]
public IQueryable<Registration> GetRegistrations([Service] EventsContext ctx) => ctx.Registrations.AsNoTracking();
}