feat: add an annotation to the data

This commit is contained in:
2024-12-22 05:26:10 +03:00
parent e4b942d062
commit 544ad6e791
4 changed files with 10 additions and 5 deletions

View File

@ -6,7 +6,9 @@ using Mirea.Api.DataAccess.Application.Cqrs.Professor.Queries.GetProfessorDetail
using Mirea.Api.DataAccess.Application.Cqrs.Professor.Queries.GetProfessorList;
using Mirea.Api.Dto.Responses;
using Mirea.Api.Endpoint.Common.Attributes;
using Mirea.Api.Endpoint.Common.Exceptions;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
@ -24,7 +26,7 @@ public class ProfessorController(IMediator mediator) : BaseController
/// <returns>A list of professors.</returns>
[HttpGet]
[BadRequestResponse]
public async Task<ActionResult<List<ProfessorResponse>>> Get([FromQuery] int? page, [FromQuery] int? pageSize)
public async Task<ActionResult<List<ProfessorResponse>>> Get([FromQuery][Range(0, int.MaxValue)] int? page, [FromQuery][Range(1, int.MaxValue)] int? pageSize)
{
var result = await mediator.Send(new GetProfessorListQuery()
{
@ -78,7 +80,7 @@ public class ProfessorController(IMediator mediator) : BaseController
[HttpGet("{name:required}")]
[BadRequestResponse]
[NotFoundResponse]
public async Task<ActionResult<List<ProfessorResponse>>> GetDetails(string name)
public async Task<ActionResult<List<ProfessorResponse>>> GetDetails([MinLength(4)] string name)
{
if (string.IsNullOrEmpty(name) || name.Length < 4)
throw new ControllerArgumentException($"The minimum number of characters is 4 (current: {name.Length}).");