2024-09-11 15:59:13 +02:00
|
|
|
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2024-07-03 22:18:32 +02:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
using WatchIt.Common.Model.Genres;
|
|
|
|
|
|
using WatchIt.Common.Model.Media;
|
2024-09-25 22:11:28 +02:00
|
|
|
|
using WatchIt.Common.Model.Photos;
|
2024-09-28 02:36:53 +02:00
|
|
|
|
using WatchIt.Common.Model.Rating;
|
2024-10-06 14:51:58 +02:00
|
|
|
|
using WatchIt.Common.Model.Roles;
|
2024-07-03 22:18:32 +02:00
|
|
|
|
using WatchIt.WebAPI.Services.Controllers.Media;
|
|
|
|
|
|
|
|
|
|
|
|
namespace WatchIt.WebAPI.Controllers;
|
|
|
|
|
|
|
|
|
|
|
|
[ApiController]
|
|
|
|
|
|
[Route("media")]
|
2024-09-25 22:11:28 +02:00
|
|
|
|
public class MediaController : ControllerBase
|
2024-07-03 22:18:32 +02:00
|
|
|
|
{
|
2024-09-25 22:11:28 +02:00
|
|
|
|
#region FIELDS
|
|
|
|
|
|
|
|
|
|
|
|
private readonly IMediaControllerService _mediaControllerService;
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region CONSTRUCTORS
|
|
|
|
|
|
|
|
|
|
|
|
public MediaController(IMediaControllerService mediaControllerService)
|
|
|
|
|
|
{
|
|
|
|
|
|
_mediaControllerService = mediaControllerService;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region METHODS
|
|
|
|
|
|
|
|
|
|
|
|
#region Main
|
2024-09-20 23:37:55 +02:00
|
|
|
|
|
2024-10-08 02:14:16 +02:00
|
|
|
|
[HttpGet]
|
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<MediaResponse>), StatusCodes.Status200OK)]
|
|
|
|
|
|
public async Task<ActionResult> GetAllMedia(MediaQueryParameters query) => await _mediaControllerService.GetAllMedia(query);
|
|
|
|
|
|
|
2024-09-19 13:36:01 +02:00
|
|
|
|
[HttpGet("{id}")]
|
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
|
[ProducesResponseType(typeof(MediaResponse), StatusCodes.Status200OK)]
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
2024-09-25 22:11:28 +02:00
|
|
|
|
public async Task<ActionResult> GetMedia([FromRoute] long id) => await _mediaControllerService.GetMedia(id);
|
2024-09-19 13:36:01 +02:00
|
|
|
|
|
2024-09-20 23:37:55 +02:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
2024-09-25 22:11:28 +02:00
|
|
|
|
#region Genres
|
2024-09-20 23:37:55 +02:00
|
|
|
|
|
2024-07-03 22:18:32 +02:00
|
|
|
|
[HttpGet("{id}/genres")]
|
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<GenreResponse>), StatusCodes.Status200OK)]
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
2024-09-25 22:11:28 +02:00
|
|
|
|
public async Task<ActionResult> GetMediaGenres([FromRoute]long id) => await _mediaControllerService.GetMediaGenres(id);
|
2024-07-03 22:18:32 +02:00
|
|
|
|
|
|
|
|
|
|
[HttpPost("{id}/genres/{genre_id}")]
|
2024-09-11 15:59:13 +02:00
|
|
|
|
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
2024-07-03 22:18:32 +02:00
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status200OK)]
|
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]
|
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
2024-09-25 22:11:28 +02:00
|
|
|
|
public async Task<ActionResult> PostMediaGenre([FromRoute]long id, [FromRoute(Name = "genre_id")]short genreId) => await _mediaControllerService.PostMediaGenre(id, genreId);
|
2024-07-03 22:18:32 +02:00
|
|
|
|
|
|
|
|
|
|
[HttpDelete("{id}/genres/{genre_id}")]
|
2024-09-11 15:59:13 +02:00
|
|
|
|
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
2024-07-03 22:18:32 +02:00
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status200OK)]
|
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]
|
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
2024-09-25 22:11:28 +02:00
|
|
|
|
public async Task<ActionResult> DeleteMediaGenre([FromRoute]long id, [FromRoute(Name = "genre_id")]short genreId) => await _mediaControllerService.DeleteMediaGenre(id, genreId);
|
2024-07-03 22:18:32 +02:00
|
|
|
|
|
2024-09-20 23:37:55 +02:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
2024-09-25 22:11:28 +02:00
|
|
|
|
#region Rating
|
2024-09-20 23:37:55 +02:00
|
|
|
|
|
|
|
|
|
|
[HttpGet("{id}/rating")]
|
2024-07-03 22:18:32 +02:00
|
|
|
|
[AllowAnonymous]
|
2024-09-28 02:36:53 +02:00
|
|
|
|
[ProducesResponseType(typeof(RatingResponse), StatusCodes.Status200OK)]
|
2024-07-03 22:18:32 +02:00
|
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
2024-09-25 22:11:28 +02:00
|
|
|
|
public async Task<ActionResult> GetMediaRating([FromRoute] long id) => await _mediaControllerService.GetMediaRating(id);
|
2024-09-20 23:37:55 +02:00
|
|
|
|
|
|
|
|
|
|
[HttpGet("{id}/rating/{user_id}")]
|
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
|
[ProducesResponseType(typeof(short), StatusCodes.Status200OK)]
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
2024-09-25 22:11:28 +02:00
|
|
|
|
public async Task<ActionResult> GetMediaRatingByUser([FromRoute] long id, [FromRoute(Name = "user_id")]long userId) => await _mediaControllerService.GetMediaRatingByUser(id, userId);
|
2024-09-20 23:37:55 +02:00
|
|
|
|
|
|
|
|
|
|
[HttpPut("{id}/rating")]
|
|
|
|
|
|
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
2024-09-28 02:36:53 +02:00
|
|
|
|
public async Task<ActionResult> PutMediaRating([FromRoute] long id, [FromBody] RatingRequest data) => await _mediaControllerService.PutMediaRating(id, data);
|
2024-09-20 23:37:55 +02:00
|
|
|
|
|
|
|
|
|
|
[HttpDelete("{id}/rating")]
|
|
|
|
|
|
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]
|
2024-09-25 22:11:28 +02:00
|
|
|
|
public async Task<ActionResult> DeleteMediaRating([FromRoute] long id) => await _mediaControllerService.DeleteMediaRating(id);
|
2024-09-20 23:37:55 +02:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
2024-09-21 21:11:21 +02:00
|
|
|
|
|
2024-09-25 22:11:28 +02:00
|
|
|
|
#region View count
|
2024-09-21 21:11:21 +02:00
|
|
|
|
|
|
|
|
|
|
[HttpPost("{id}/view")]
|
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
2024-09-25 22:11:28 +02:00
|
|
|
|
public async Task<ActionResult> PostMediaView([FromRoute] long id) => await _mediaControllerService.PostMediaView(id);
|
2024-09-21 21:11:21 +02:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
2024-09-20 23:37:55 +02:00
|
|
|
|
|
2024-09-25 22:11:28 +02:00
|
|
|
|
#region Poster
|
2024-09-20 23:37:55 +02:00
|
|
|
|
|
2024-09-11 15:59:13 +02:00
|
|
|
|
[HttpGet("{id}/poster")]
|
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
|
[ProducesResponseType(typeof(MediaPosterResponse), StatusCodes.Status200OK)]
|
|
|
|
|
|
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
2024-09-25 22:11:28 +02:00
|
|
|
|
public async Task<ActionResult> GetMediaPoster([FromRoute] long id) => await _mediaControllerService.GetMediaPoster(id);
|
2024-09-11 15:59:13 +02:00
|
|
|
|
|
|
|
|
|
|
[HttpPut("{id}/poster")]
|
|
|
|
|
|
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
2024-09-22 23:11:21 +02:00
|
|
|
|
[ProducesResponseType(typeof(MediaPosterResponse), StatusCodes.Status200OK)]
|
2024-09-11 15:59:13 +02:00
|
|
|
|
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]
|
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
|
2024-09-25 22:11:28 +02:00
|
|
|
|
public async Task<ActionResult> PutMediaPoster([FromRoute]long id, [FromBody]MediaPosterRequest body) => await _mediaControllerService.PutMediaPoster(id, body);
|
2024-09-11 15:59:13 +02:00
|
|
|
|
|
|
|
|
|
|
[HttpDelete("{id}/poster")]
|
|
|
|
|
|
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status204NoContent)]
|
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]
|
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
|
2024-09-25 22:11:28 +02:00
|
|
|
|
public async Task<ActionResult> DeleteMediaPoster([FromRoute]long id) => await _mediaControllerService.DeleteMediaPoster(id);
|
2024-09-20 23:37:55 +02:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2024-09-25 22:11:28 +02:00
|
|
|
|
#region Photos
|
2024-09-20 23:37:55 +02:00
|
|
|
|
|
2024-09-25 22:11:28 +02:00
|
|
|
|
[HttpGet("{id}/photos")]
|
2024-09-20 23:37:55 +02:00
|
|
|
|
[AllowAnonymous]
|
2024-09-25 22:11:28 +02:00
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<PhotoResponse>), StatusCodes.Status200OK)]
|
2024-09-20 23:37:55 +02:00
|
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
2024-09-25 22:11:28 +02:00
|
|
|
|
public async Task<ActionResult> GetMediaPhotos([FromRoute]long id, PhotoQueryParameters query) => await _mediaControllerService.GetMediaPhotos(id, query);
|
2024-07-03 22:18:32 +02:00
|
|
|
|
|
2024-09-25 22:11:28 +02:00
|
|
|
|
[HttpGet("{id}/photos/random_background")]
|
2024-07-03 22:18:32 +02:00
|
|
|
|
[AllowAnonymous]
|
2024-09-25 22:11:28 +02:00
|
|
|
|
[ProducesResponseType(typeof(PhotoResponse), StatusCodes.Status200OK)]
|
2024-07-03 22:18:32 +02:00
|
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
2024-09-25 22:11:28 +02:00
|
|
|
|
public async Task<ActionResult> GetMediaPhotoRandomBackground([FromRoute]long id) => await _mediaControllerService.GetMediaPhotoRandomBackground(id);
|
2024-07-03 22:18:32 +02:00
|
|
|
|
|
2024-09-25 22:11:28 +02:00
|
|
|
|
[HttpPost("{id}/photos")]
|
2024-09-11 15:59:13 +02:00
|
|
|
|
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
2024-09-25 22:11:28 +02:00
|
|
|
|
[ProducesResponseType(typeof(PhotoResponse), StatusCodes.Status201Created)]
|
2024-07-03 22:18:32 +02:00
|
|
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]
|
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
2024-09-25 22:11:28 +02:00
|
|
|
|
public async Task<ActionResult> PostPhoto([FromRoute]long id, [FromBody]MediaPhotoRequest body) => await _mediaControllerService.PostMediaPhoto(id, body);
|
2024-07-03 22:18:32 +02:00
|
|
|
|
|
2024-10-06 14:51:58 +02:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Roles
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet("{id}/roles/actor")]
|
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<ActorRoleResponse>), StatusCodes.Status200OK)]
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
|
|
|
|
|
public async Task<ActionResult> GetMediaAllActorRoles([FromRoute]long id, ActorRoleMediaQueryParameters query) => await _mediaControllerService.GetMediaAllActorRoles(id, query);
|
|
|
|
|
|
|
|
|
|
|
|
[HttpPost("{id}/roles/actor")]
|
|
|
|
|
|
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
|
|
|
|
|
[ProducesResponseType(typeof(ActorRoleResponse), StatusCodes.Status201Created)]
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]
|
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
2024-10-08 19:56:14 +02:00
|
|
|
|
public async Task<ActionResult> PostMediaActorRole([FromRoute]long id, [FromBody]ActorRoleMediaRequest body) => await _mediaControllerService.PostMediaActorRole(id, body);
|
2024-10-06 14:51:58 +02:00
|
|
|
|
|
|
|
|
|
|
[HttpGet("{id}/roles/creator")]
|
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<CreatorRoleResponse>), StatusCodes.Status200OK)]
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
|
|
|
|
|
public async Task<ActionResult> GetMediaAllCreatorRoles([FromRoute]long id, CreatorRoleMediaQueryParameters query) => await _mediaControllerService.GetMediaAllCreatorRoles(id, query);
|
|
|
|
|
|
|
|
|
|
|
|
[HttpPost("{id}/roles/creator")]
|
|
|
|
|
|
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
|
|
|
|
|
|
[ProducesResponseType(typeof(CreatorRoleResponse), StatusCodes.Status201Created)]
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)]
|
|
|
|
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)]
|
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
2024-10-08 19:56:14 +02:00
|
|
|
|
public async Task<ActionResult> PostMediaCreatorRole([FromRoute]long id, [FromBody]CreatorRoleMediaRequest body) => await _mediaControllerService.PostMediaCreatorRole(id, body);
|
2024-10-06 14:51:58 +02:00
|
|
|
|
|
2024-09-25 22:11:28 +02:00
|
|
|
|
#endregion
|
2024-09-20 23:37:55 +02:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
2024-07-03 22:18:32 +02:00
|
|
|
|
}
|