diff --git a/Moonlight.ApiServer/Http/Controllers/Admin/ApiKeys/ApiKeysController.cs b/Moonlight.ApiServer/Http/Controllers/Admin/ApiKeys/ApiKeysController.cs index c77f303e..8cedfb93 100644 --- a/Moonlight.ApiServer/Http/Controllers/Admin/ApiKeys/ApiKeysController.cs +++ b/Moonlight.ApiServer/Http/Controllers/Admin/ApiKeys/ApiKeysController.cs @@ -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> Get( - [FromQuery] [Range(0, int.MaxValue)] int page, - [FromQuery] [Range(1, 100)] int pageSize - ) + public async Task> 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() { - 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 }; } diff --git a/Moonlight.ApiServer/Http/Controllers/Admin/Sys/Customisation/ThemesController.cs b/Moonlight.ApiServer/Http/Controllers/Admin/Sys/Customisation/ThemesController.cs index 356f39bc..73867116 100644 --- a/Moonlight.ApiServer/Http/Controllers/Admin/Sys/Customisation/ThemesController.cs +++ b/Moonlight.ApiServer/Http/Controllers/Admin/Sys/Customisation/ThemesController.cs @@ -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.Mappers; @@ -25,17 +26,14 @@ public class ThemesController : Controller [HttpGet] [Authorize(Policy = "permissions:admin.system.customisation.themes.read")] - public async Task> Get( - [FromQuery] [Range(0, int.MaxValue)] int page, - [FromQuery] [Range(1, 100)] int pageSize - ) + public async Task> Get([FromQuery] PagedOptions options) { var count = await ThemeRepository.Get().CountAsync(); var items = await ThemeRepository .Get() - .Skip(page * pageSize) - .Take(pageSize) + .Skip(options.Page * options.PageSize) + .Take(options.PageSize) .ToArrayAsync(); var mappedItems = items @@ -44,11 +42,11 @@ public class ThemesController : Controller return new PagedData() { - CurrentPage = page, + CurrentPage = options.Page, Items = mappedItems, - PageSize = pageSize, + PageSize = options.PageSize, TotalItems = count, - TotalPages = count == 0 ? 0 : (count - 1) / pageSize + TotalPages = count == 0 ? 0 : (count - 1) / options.PageSize }; } diff --git a/Moonlight.ApiServer/Http/Controllers/Admin/Users/UsersController.cs b/Moonlight.ApiServer/Http/Controllers/Admin/Users/UsersController.cs index 5c5c14f9..247617bc 100644 --- a/Moonlight.ApiServer/Http/Controllers/Admin/Users/UsersController.cs +++ b/Moonlight.ApiServer/Http/Controllers/Admin/Users/UsersController.cs @@ -6,6 +6,7 @@ using Microsoft.Extensions.DependencyInjection; using MoonCore.Exceptions; using MoonCore.Extended.Abstractions; using MoonCore.Extended.Helpers; +using MoonCore.Extended.Models; using MoonCore.Models; using Moonlight.ApiServer.Database.Entities; using Moonlight.ApiServer.Services; @@ -27,18 +28,15 @@ public class UsersController : Controller [HttpGet] [Authorize(Policy = "permissions:admin.users.get")] - public async Task> Get( - [FromQuery] [Range(0, int.MaxValue)] int page, - [FromQuery] [Range(1, 100)] int pageSize - ) + public async Task> Get([FromQuery] PagedOptions options) { var count = await UserRepository.Get().CountAsync(); var users = await UserRepository .Get() .OrderBy(x => x.Id) - .Skip(page * pageSize) - .Take(pageSize) + .Skip(options.Page * options.PageSize) + .Take(options.PageSize) .ToArrayAsync(); var mappedUsers = users @@ -53,11 +51,11 @@ public class UsersController : Controller return new PagedData() { - CurrentPage = page, + CurrentPage = options.Page, Items = mappedUsers, - PageSize = pageSize, + PageSize = options.PageSize, TotalItems = count, - TotalPages = count == 0 ? 0 : (count - 1) / pageSize + TotalPages = count == 0 ? 0 : (count - 1) / options.PageSize }; } diff --git a/Moonlight.Shared/Http/Requests/Admin/Sys/Files/DecompressRequest.cs b/Moonlight.Shared/Http/Requests/Admin/Sys/Files/DecompressRequest.cs index 79866eec..d37379c0 100644 --- a/Moonlight.Shared/Http/Requests/Admin/Sys/Files/DecompressRequest.cs +++ b/Moonlight.Shared/Http/Requests/Admin/Sys/Files/DecompressRequest.cs @@ -1,8 +1,15 @@ -namespace Moonlight.Shared.Http.Requests.Admin.Sys.Files; +using System.ComponentModel.DataAnnotations; + +namespace Moonlight.Shared.Http.Requests.Admin.Sys.Files; public class DecompressRequest { + [Required(ErrorMessage = "You need to provide a format")] public string Format { get; set; } + + [Required(ErrorMessage = "You need to provide a path")] public string Path { get; set; } + + [Required(ErrorMessage = "You need to provide a destination")] public string Destination { get; set; } } \ No newline at end of file diff --git a/Moonlight.Shared/Http/Requests/Admin/Sys/GenerateDiagnoseRequest.cs b/Moonlight.Shared/Http/Requests/Admin/Sys/GenerateDiagnoseRequest.cs index 3757ab8e..91df3c01 100644 --- a/Moonlight.Shared/Http/Requests/Admin/Sys/GenerateDiagnoseRequest.cs +++ b/Moonlight.Shared/Http/Requests/Admin/Sys/GenerateDiagnoseRequest.cs @@ -1,6 +1,9 @@ +using System.ComponentModel.DataAnnotations; + namespace Moonlight.Shared.Http.Requests.Admin.Sys; public class GenerateDiagnoseRequest { + [Required(ErrorMessage = "You need to define providers")] public string[] Providers { get; set; } = []; } \ No newline at end of file diff --git a/Moonlight.Shared/Http/Requests/Admin/Users/CreateUserRequest.cs b/Moonlight.Shared/Http/Requests/Admin/Users/CreateUserRequest.cs index b67361de..60b4ddd4 100644 --- a/Moonlight.Shared/Http/Requests/Admin/Users/CreateUserRequest.cs +++ b/Moonlight.Shared/Http/Requests/Admin/Users/CreateUserRequest.cs @@ -17,5 +17,6 @@ public class CreateUserRequest [MaxLength(256, ErrorMessage = "Your password should not exceed the length of 256 characters")] public string Password { get; set; } + [Required(ErrorMessage = "You need to provide permissions")] public string[] Permissions { get; set; } = []; } \ No newline at end of file