Improved paged endpoint rage validation. Fixed smaller request model validation issues
This commit is contained in:
@@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using MoonCore.Exceptions;
|
||||
using MoonCore.Extended.Abstractions;
|
||||
using MoonCore.Extended.Models;
|
||||
using MoonCore.Models;
|
||||
using Moonlight.ApiServer.Database.Entities;
|
||||
using Moonlight.ApiServer.Services;
|
||||
@@ -27,18 +28,15 @@ public class ApiKeysController : Controller
|
||||
|
||||
[HttpGet]
|
||||
[Authorize(Policy = "permissions:admin.apikeys.get")]
|
||||
public async Task<IPagedData<ApiKeyResponse>> Get(
|
||||
[FromQuery] [Range(0, int.MaxValue)] int page,
|
||||
[FromQuery] [Range(1, 100)] int pageSize
|
||||
)
|
||||
public async Task<IPagedData<ApiKeyResponse>> Get([FromQuery] PagedOptions options)
|
||||
{
|
||||
var count = await ApiKeyRepository.Get().CountAsync();
|
||||
|
||||
var apiKeys = await ApiKeyRepository
|
||||
.Get()
|
||||
.OrderBy(x => x.Id)
|
||||
.Skip(page * pageSize)
|
||||
.Take(pageSize)
|
||||
.Skip(options.Page * options.PageSize)
|
||||
.Take(options.PageSize)
|
||||
.ToArrayAsync();
|
||||
|
||||
var mappedApiKey = apiKeys
|
||||
@@ -53,11 +51,11 @@ public class ApiKeysController : Controller
|
||||
|
||||
return new PagedData<ApiKeyResponse>()
|
||||
{
|
||||
CurrentPage = page,
|
||||
CurrentPage = options.Page,
|
||||
Items = mappedApiKey,
|
||||
PageSize = pageSize,
|
||||
PageSize = options.PageSize,
|
||||
TotalItems = count,
|
||||
TotalPages = count == 0 ? 0 : (count - 1) / pageSize
|
||||
TotalPages = count == 0 ? 0 : (count - 1) / options.PageSize
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user