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")]
|
2024-09-21 22:04:35 +02:00
|
|
|
|
public class MoviesController : ControllerBase
|
2024-04-27 22:36:16 +02:00
|
|
|
|
{
|
2024-09-21 22:04:35 +02:00
|
|
|
|
#region SERVICES
|
|
|
|
|
|
|
|
|
|
|
|
private readonly IMoviesControllerService _moviesControllerService;
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region CONSTRUCTORS
|
|
|
|
|
|
|
|
|
|
|
|
public MoviesController(IMoviesControllerService moviesControllerService)
|
|
|
|
|
|
{
|
|
|
|
|
|
_moviesControllerService = moviesControllerService;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region METHODS
|
|
|
|
|
|
|
|
|
|
|
|
#region Main
|
|
|
|
|
|
|
2024-04-27 22:36:16 +02:00
|
|
|
|
[HttpGet]
|
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<MovieResponse>), StatusCodes.Status200OK)]
|
2024-09-21 22:04:35 +02:00
|
|
|
|
public async Task<ActionResult> GetAllMovies(MovieQueryParameters query) => await _moviesControllerService.GetAllMovies(query);
|
2024-04-27 22:36:16 +02:00
|
|
|
|
|
|
|
|
|
|
[HttpGet("{id}")]
|
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
|
[ProducesResponseType(typeof(MovieResponse), StatusCodes.Status200OK)]
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
2024-09-21 22:04:35 +02:00
|
|
|
|
public async Task<ActionResult> GetMovie([FromRoute] long id) => await _moviesControllerService.GetMovie(id);
|
2024-04-27 22:36:16 +02:00
|
|
|
|
|
|
|
|
|
|
[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)]
|
2024-09-21 22:04:35 +02:00
|
|
|
|
public async Task<ActionResult> PostMovie([FromBody] MovieRequest body) => await _moviesControllerService.PostMovie(body);
|
2024-04-27 22:36:16 +02:00
|
|
|
|
|
|
|
|
|
|
[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)]
|
2024-09-21 22:04:35 +02:00
|
|
|
|
public async Task<ActionResult> PutMovie([FromRoute] long id, [FromBody]MovieRequest body) => await _moviesControllerService.PutMovie(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-09-21 22:04:35 +02:00
|
|
|
|
public async Task<ActionResult> DeleteMovie([FromRoute] long id) => await _moviesControllerService.DeleteMovie(id);
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region View count
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet("view")]
|
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<MovieResponse>), StatusCodes.Status200OK)]
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
|
|
|
|
public async Task<ActionResult> GetMoviesViewRank([FromQuery] int first = 5, [FromQuery] int days = 7) => await _moviesControllerService.GetMoviesViewRank(first, days);
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
2024-04-27 22:36:16 +02:00
|
|
|
|
}
|