2024-07-30 16:19:51 +02:00
|
|
|
|
using System.Net;
|
|
|
|
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2024-04-27 22:36:16 +02:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
using WatchIt.Common.Model.Genres;
|
|
|
|
|
|
using WatchIt.Common.Model.Movies;
|
|
|
|
|
|
using WatchIt.WebAPI.Services.Controllers.Movies;
|
|
|
|
|
|
|
|
|
|
|
|
namespace WatchIt.WebAPI.Controllers;
|
|
|
|
|
|
|
|
|
|
|
|
[ApiController]
|
|
|
|
|
|
[Route("movies")]
|
|
|
|
|
|
public class MoviesController(IMoviesControllerService moviesControllerService) : ControllerBase
|
|
|
|
|
|
{
|
|
|
|
|
|
[HttpGet]
|
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<MovieResponse>), StatusCodes.Status200OK)]
|
|
|
|
|
|
public async Task<ActionResult> GetAll(MovieQueryParameters query) => await moviesControllerService.GetAll(query);
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet("{id}")]
|
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
|
[ProducesResponseType(typeof(MovieResponse), StatusCodes.Status200OK)]
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
|
|
|
|
|
public async Task<ActionResult> Get([FromRoute]long id) => await moviesControllerService.Get(id);
|
|
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
2024-07-30 16:19:51 +02:00
|
|
|
|
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
2024-04-27 22:36:16 +02:00
|
|
|
|
[ProducesResponseType(typeof(MovieResponse), StatusCodes.Status201Created)]
|
|
|
|
|
|
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]
|
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
|
|
|
|
|
|
public async Task<ActionResult> Post([FromBody]MovieRequest body) => await moviesControllerService.Post(body);
|
|
|
|
|
|
|
|
|
|
|
|
[HttpPut("{id}")]
|
2024-07-30 16:19:51 +02:00
|
|
|
|
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status204NoContent)]
|
2024-04-27 22:36:16 +02:00
|
|
|
|
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]
|
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
|
|
|
|
|
|
public async Task<ActionResult> Put([FromRoute]long id, [FromBody]MovieRequest body) => await moviesControllerService.Put(id, body);
|
2024-07-03 22:18:32 +02:00
|
|
|
|
|
2024-04-27 22:36:16 +02:00
|
|
|
|
[HttpDelete("{id}")]
|
2024-07-30 16:19:51 +02:00
|
|
|
|
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status204NoContent)]
|
2024-04-27 22:36:16 +02:00
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]
|
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
|
2024-07-03 22:18:32 +02:00
|
|
|
|
public async Task<ActionResult> Delete([FromRoute] long id) => await moviesControllerService.Delete(id);
|
2024-04-27 22:36:16 +02:00
|
|
|
|
}
|