48 lines
2.3 KiB
C#
48 lines
2.3 KiB
C#
|
|
using Microsoft.AspNetCore.Authorization;
|
|||
|
|
using Microsoft.AspNetCore.Http;
|
|||
|
|
using Microsoft.AspNetCore.Mvc;
|
|||
|
|
using WatchIt.Common.Model.Genres;
|
|||
|
|
using WatchIt.WebAPI.Services.Controllers.Genres;
|
|||
|
|
|
|||
|
|
namespace WatchIt.WebAPI.Controllers;
|
|||
|
|
|
|||
|
|
[ApiController]
|
|||
|
|
[Route("genres")]
|
|||
|
|
public class GenresController(IGenresControllerService genresControllerService) : ControllerBase
|
|||
|
|
{
|
|||
|
|
[HttpGet]
|
|||
|
|
[AllowAnonymous]
|
|||
|
|
[ProducesResponseType(typeof(IEnumerable<GenreResponse>), StatusCodes.Status200OK)]
|
|||
|
|
public async Task<ActionResult> GetAll(GenreQueryParameters query) => await genresControllerService.GetAll(query);
|
|||
|
|
|
|||
|
|
[HttpGet("{id}")]
|
|||
|
|
[AllowAnonymous]
|
|||
|
|
[ProducesResponseType(typeof(GenreResponse), StatusCodes.Status200OK)]
|
|||
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
|||
|
|
public async Task<ActionResult> Get([FromRoute]short id) => await genresControllerService.Get(id);
|
|||
|
|
|
|||
|
|
[HttpPost]
|
|||
|
|
[Authorize]
|
|||
|
|
[ProducesResponseType(typeof(GenreResponse), StatusCodes.Status201Created)]
|
|||
|
|
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
|||
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]
|
|||
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
|
|||
|
|
public async Task<ActionResult> Post([FromBody]GenreRequest body) => await genresControllerService.Post(body);
|
|||
|
|
|
|||
|
|
[HttpPut("{id}")]
|
|||
|
|
[Authorize]
|
|||
|
|
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
|||
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]
|
|||
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
|
|||
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
|||
|
|
public async Task<ActionResult> Put([FromRoute]short id, [FromBody]GenreRequest body) => await genresControllerService.Put(id, body);
|
|||
|
|
|
|||
|
|
[HttpDelete("{id}")]
|
|||
|
|
[Authorize]
|
|||
|
|
[ProducesResponseType(typeof(GenreResponse), StatusCodes.Status200OK)]
|
|||
|
|
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
|||
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]
|
|||
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
|
|||
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
|||
|
|
public async Task<ActionResult> Delete([FromRoute]short id) => await genresControllerService.Delete(id);
|
|||
|
|
}
|