WebApi + ClientApp, GraphQL, Reflection
This commit is contained in:
74
Events.GraphQL/Events.GraphQLServer/SetupGraphQL/Queries.cs
Normal file
74
Events.GraphQL/Events.GraphQLServer/SetupGraphQL/Queries.cs
Normal 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();
|
||||
}
|
||||
Reference in New Issue
Block a user