2024-04-27 22:36:16 +02:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
using WatchIt.Common.Model.Genres;
|
2024-11-08 17:53:23 +01:00
|
|
|
|
using WatchIt.Common.Model.Media;
|
2024-04-27 22:36:16 +02:00
|
|
|
|
using WatchIt.WebAPI.Services.Controllers.Genres;
|
|
|
|
|
|
|
|
|
|
|
|
namespace WatchIt.WebAPI.Controllers;
|
|
|
|
|
|
|
|
|
|
|
|
[ApiController]
|
|
|
|
|
|
[Route("genres")]
|
|
|
|
|
|
public class GenresController(IGenresControllerService genresControllerService) : ControllerBase
|
|
|
|
|
|
{
|
2024-11-08 17:53:23 +01:00
|
|
|
|
#region METHODS
|
|
|
|
|
|
|
|
|
|
|
|
#region Main
|
|
|
|
|
|
|
2024-04-27 22:36:16 +02:00
|
|
|
|
[HttpGet]
|
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<GenreResponse>), StatusCodes.Status200OK)]
|
2024-11-08 17:53:23 +01:00
|
|
|
|
public async Task<ActionResult> GetGenres(GenreQueryParameters query) => await genresControllerService.GetGenres(query);
|
2024-04-27 22:36:16 +02:00
|
|
|
|
|
|
|
|
|
|
[HttpGet("{id}")]
|
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
|
[ProducesResponseType(typeof(GenreResponse), StatusCodes.Status200OK)]
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
2024-11-08 17:53:23 +01:00
|
|
|
|
public async Task<ActionResult> GetGenre([FromRoute]short id) => await genresControllerService.GetGenre(id);
|
2024-04-27 22:36:16 +02:00
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
|
[Authorize]
|
|
|
|
|
|
[ProducesResponseType(typeof(GenreResponse), StatusCodes.Status201Created)]
|
|
|
|
|
|
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]
|
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
|
2024-11-08 17:53:23 +01:00
|
|
|
|
public async Task<ActionResult> PostGenre([FromBody]GenreRequest body) => await genresControllerService.PostGenre(body);
|
2024-04-27 22:36:16 +02:00
|
|
|
|
|
|
|
|
|
|
[HttpPut("{id}")]
|
|
|
|
|
|
[Authorize]
|
|
|
|
|
|
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]
|
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
2024-11-08 17:53:23 +01:00
|
|
|
|
public async Task<ActionResult> PutGenre([FromRoute]short id, [FromBody]GenreRequest body) => await genresControllerService.PutGenre(id, body);
|
2024-04-27 22:36:16 +02:00
|
|
|
|
|
|
|
|
|
|
[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)]
|
2024-11-08 17:53:23 +01:00
|
|
|
|
public async Task<ActionResult> DeleteGenre([FromRoute]short id) => await genresControllerService.DeleteGenre(id);
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Media
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet("{id}/media")]
|
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<MediaResponse>), StatusCodes.Status200OK)]
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
|
|
|
|
|
public async Task<ActionResult> GetGenreMedia([FromRoute]short id, MediaQueryParameters query) => await genresControllerService.GetGenreMedia(id, query);
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
2024-04-27 22:36:16 +02:00
|
|
|
|
}
|