diff --git a/.github/workflows/dev_pr.yml b/.github/workflows/dev_pr.yml index e195c09..99c2f76 100644 --- a/.github/workflows/dev_pr.yml +++ b/.github/workflows/dev_pr.yml @@ -1,7 +1,7 @@ name: "Pull request to 'dev' branch" on: - push: + pull_request: branches: - "dev/**" paths: diff --git a/WatchIt.Common/WatchIt.Common.Model/Media/MediaPhoto.cs b/WatchIt.Common/WatchIt.Common.Model/Media/MediaPhoto.cs deleted file mode 100644 index aa76ffd..0000000 --- a/WatchIt.Common/WatchIt.Common.Model/Media/MediaPhoto.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Text.Json.Serialization; - -namespace WatchIt.Common.Model.Media; - -public class MediaPhoto -{ - [JsonPropertyName("media_id")] - public required long MediaId { get; set; } - - [JsonPropertyName("image")] - public required byte[] Image { get; set; } - - [JsonPropertyName("mime_type")] - public required string MimeType { get; set; } - - [JsonPropertyName("background")] - public MediaPhotoBackground? Background { get; set; } -} \ No newline at end of file diff --git a/WatchIt.Common/WatchIt.Common.Model/Media/MediaPhotoRequest.cs b/WatchIt.Common/WatchIt.Common.Model/Media/MediaPhotoRequest.cs index 956e256..56bbb4c 100644 --- a/WatchIt.Common/WatchIt.Common.Model/Media/MediaPhotoRequest.cs +++ b/WatchIt.Common/WatchIt.Common.Model/Media/MediaPhotoRequest.cs @@ -1,12 +1,13 @@ -using WatchIt.Database.Model.Media; +using WatchIt.Common.Model.Photos; +using WatchIt.Database.Model.Media; namespace WatchIt.Common.Model.Media; -public class MediaPhotoRequest : MediaPhoto +public class MediaPhotoRequest : Photo { - public MediaPhotoImage CreateMediaPhotoImage() => new MediaPhotoImage + public MediaPhotoImage CreateMediaPhotoImage(long mediaId) => new MediaPhotoImage { - MediaId = MediaId, + MediaId = mediaId, Image = Image, MimeType = MimeType }; @@ -18,22 +19,4 @@ public class MediaPhotoRequest : MediaPhoto FirstGradientColor = Background.FirstGradientColor, SecondGradientColor = Background.SecondGradientColor }; - - public void UpdateMediaPhotoImage(MediaPhotoImage item) - { - item.MediaId = MediaId; - item.Image = Image; - item.MimeType = MimeType; - item.UploadDate = DateTime.Now; - } - - public void UpdateMediaPhotoImageBackground(MediaPhotoImageBackground item) - { - if (Background is not null) - { - item.IsUniversalBackground = Background.IsUniversalBackground; - item.FirstGradientColor = Background.FirstGradientColor; - item.SecondGradientColor = Background.SecondGradientColor; - } - } } \ No newline at end of file diff --git a/WatchIt.Common/WatchIt.Common.Model/Media/MediaPoster.cs b/WatchIt.Common/WatchIt.Common.Model/Media/MediaPoster.cs index d4f4aab..17397be 100644 --- a/WatchIt.Common/WatchIt.Common.Model/Media/MediaPoster.cs +++ b/WatchIt.Common/WatchIt.Common.Model/Media/MediaPoster.cs @@ -2,20 +2,8 @@ namespace WatchIt.Common.Model.Media; -public abstract class MediaPoster +public abstract class MediaPoster : Picture { - #region PROPERTIES - - [JsonPropertyName("image")] - public required byte[] Image { get; set; } - - [JsonPropertyName("mime_type")] - public required string MimeType { get; set; } - - #endregion - - - #region PUBLIC METHODS public override string ToString() => $"data:{MimeType};base64,{Convert.ToBase64String(Image)}"; diff --git a/WatchIt.Common/WatchIt.Common.Model/Photos/Photo.cs b/WatchIt.Common/WatchIt.Common.Model/Photos/Photo.cs new file mode 100644 index 0000000..39cabfd --- /dev/null +++ b/WatchIt.Common/WatchIt.Common.Model/Photos/Photo.cs @@ -0,0 +1,13 @@ +using System.Text.Json.Serialization; + +namespace WatchIt.Common.Model.Photos; + +public abstract class Photo : Picture +{ + #region PROPERTIES + + [JsonPropertyName("background")] + public PhotoBackgroundData? Background { get; set; } + + #endregion +} \ No newline at end of file diff --git a/WatchIt.Common/WatchIt.Common.Model/Media/MediaPhotoBackground.cs b/WatchIt.Common/WatchIt.Common.Model/Photos/PhotoBackgroundData.cs similarity index 68% rename from WatchIt.Common/WatchIt.Common.Model/Media/MediaPhotoBackground.cs rename to WatchIt.Common/WatchIt.Common.Model/Photos/PhotoBackgroundData.cs index bb46b23..09c31c3 100644 --- a/WatchIt.Common/WatchIt.Common.Model/Media/MediaPhotoBackground.cs +++ b/WatchIt.Common/WatchIt.Common.Model/Photos/PhotoBackgroundData.cs @@ -1,9 +1,11 @@ -using System.Text.Json.Serialization; +using System.Text.Json.Serialization; -namespace WatchIt.Common.Model.Media; +namespace WatchIt.Common.Model.Photos; -public class MediaPhotoBackground +public class PhotoBackgroundData { + #region PROPERTIES + [JsonPropertyName("is_universal_background")] public required bool IsUniversalBackground { get; set; } @@ -12,4 +14,6 @@ public class MediaPhotoBackground [JsonPropertyName("second_gradient_color")] public required byte[] SecondGradientColor { get; set; } + + #endregion } \ No newline at end of file diff --git a/WatchIt.Common/WatchIt.Common.Model/Photos/PhotoBackgroundDataRequest.cs b/WatchIt.Common/WatchIt.Common.Model/Photos/PhotoBackgroundDataRequest.cs new file mode 100644 index 0000000..1da4817 --- /dev/null +++ b/WatchIt.Common/WatchIt.Common.Model/Photos/PhotoBackgroundDataRequest.cs @@ -0,0 +1,25 @@ +using WatchIt.Database.Model.Media; + +namespace WatchIt.Common.Model.Photos; + +public class PhotoBackgroundDataRequest : PhotoBackgroundData +{ + #region PUBLIC METHODS + + public MediaPhotoImageBackground CreateMediaPhotoImageBackground(Guid photoId) => new MediaPhotoImageBackground + { + Id = photoId, + IsUniversalBackground = IsUniversalBackground, + FirstGradientColor = FirstGradientColor, + SecondGradientColor = SecondGradientColor, + }; + + public void UpdateMediaPhotoImageBackground(MediaPhotoImageBackground image) + { + image.IsUniversalBackground = IsUniversalBackground; + image.FirstGradientColor = FirstGradientColor; + image.SecondGradientColor = SecondGradientColor; + } + + #endregion +} \ No newline at end of file diff --git a/WatchIt.Common/WatchIt.Common.Model/Media/MediaPhotoQueryParameters.cs b/WatchIt.Common/WatchIt.Common.Model/Photos/PhotoQueryParameters.cs similarity index 53% rename from WatchIt.Common/WatchIt.Common.Model/Media/MediaPhotoQueryParameters.cs rename to WatchIt.Common/WatchIt.Common.Model/Photos/PhotoQueryParameters.cs index 83777b0..6e3bc5f 100644 --- a/WatchIt.Common/WatchIt.Common.Model/Media/MediaPhotoQueryParameters.cs +++ b/WatchIt.Common/WatchIt.Common.Model/Photos/PhotoQueryParameters.cs @@ -1,10 +1,10 @@ -using System.Text; using Microsoft.AspNetCore.Mvc; +using WatchIt.Common.Model.Media; using WatchIt.Common.Query; -namespace WatchIt.Common.Model.Media; +namespace WatchIt.Common.Model.Photos; -public class MediaPhotoQueryParameters : QueryParameters +public class PhotoQueryParameters : QueryParameters { #region PROPERTIES @@ -17,19 +17,30 @@ public class MediaPhotoQueryParameters : QueryParameters [FromQuery(Name = "is_universal_background")] public bool? IsUniversalBackground { get; set; } + [FromQuery(Name = "upload_date")] + public DateOnly? UploadDate { get; set; } + + [FromQuery(Name = "upload_date_from")] + public DateOnly? UploadDateFrom { get; set; } + + [FromQuery(Name = "upload_date_to")] + public DateOnly? UploadDateTo { get; set; } + #endregion #region PUBLIC METHODS - public override bool IsMeetingConditions(MediaPhotoResponse item) => + public override bool IsMeetingConditions(PhotoResponse item) => ( TestString(item.MimeType, MimeType) && TestBoolean(item.Background is not null, IsBackground) && TestBoolean(item.Background!.IsUniversalBackground, IsUniversalBackground) + && + TestComparable(item.UploadDate, UploadDate, UploadDateFrom, UploadDateTo) ); #endregion diff --git a/WatchIt.Common/WatchIt.Common.Model/Media/MediaPhotoResponse.cs b/WatchIt.Common/WatchIt.Common.Model/Photos/PhotoResponse.cs similarity index 75% rename from WatchIt.Common/WatchIt.Common.Model/Media/MediaPhotoResponse.cs rename to WatchIt.Common/WatchIt.Common.Model/Photos/PhotoResponse.cs index e2e1ec5..0b3b6d5 100644 --- a/WatchIt.Common/WatchIt.Common.Model/Media/MediaPhotoResponse.cs +++ b/WatchIt.Common/WatchIt.Common.Model/Photos/PhotoResponse.cs @@ -1,16 +1,19 @@ -using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.CodeAnalysis; using System.Text.Json.Serialization; using WatchIt.Database.Model.Media; -namespace WatchIt.Common.Model.Media; +namespace WatchIt.Common.Model.Photos; -public class MediaPhotoResponse : MediaPhoto +public class PhotoResponse : Photo { #region PROPERTIES [JsonPropertyName("id")] public Guid Id { get; set; } + [JsonPropertyName("media_id")] + public required long MediaId { get; set; } + [JsonPropertyName("upload_date")] public DateTime UploadDate { get; set; } @@ -21,10 +24,10 @@ public class MediaPhotoResponse : MediaPhoto #region CONSTRUCTORS [JsonConstructor] - public MediaPhotoResponse() {} + public PhotoResponse() {} [SetsRequiredMembers] - public MediaPhotoResponse(MediaPhotoImage mediaPhotoImage) + public PhotoResponse(MediaPhotoImage mediaPhotoImage) { Id = mediaPhotoImage.Id; MediaId = mediaPhotoImage.MediaId; @@ -34,7 +37,7 @@ public class MediaPhotoResponse : MediaPhoto if (mediaPhotoImage.MediaPhotoImageBackground is not null) { - Background = new MediaPhotoBackground + Background = new PhotoBackgroundData { IsUniversalBackground = mediaPhotoImage.MediaPhotoImageBackground.IsUniversalBackground, FirstGradientColor = mediaPhotoImage.MediaPhotoImageBackground.FirstGradientColor, diff --git a/WatchIt.Common/WatchIt.Common.Model/Picture.cs b/WatchIt.Common/WatchIt.Common.Model/Picture.cs new file mode 100644 index 0000000..a83524d --- /dev/null +++ b/WatchIt.Common/WatchIt.Common.Model/Picture.cs @@ -0,0 +1,16 @@ +using System.Text.Json.Serialization; + +namespace WatchIt.Common.Model; + +public abstract class Picture +{ + #region PROPERTIES + + [JsonPropertyName("image")] + public required byte[] Image { get; set; } + + [JsonPropertyName("mime_type")] + public required string MimeType { get; set; } + + #endregion +} \ No newline at end of file diff --git a/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/MediaController.cs b/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/MediaController.cs index 045308c..e2cbce7 100644 --- a/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/MediaController.cs +++ b/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/MediaController.cs @@ -4,33 +4,53 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using WatchIt.Common.Model.Genres; using WatchIt.Common.Model.Media; +using WatchIt.Common.Model.Photos; using WatchIt.WebAPI.Services.Controllers.Media; namespace WatchIt.WebAPI.Controllers; [ApiController] [Route("media")] -public class MediaController(IMediaControllerService mediaControllerService) +public class MediaController : ControllerBase { - #region MAIN + #region FIELDS - [HttpGet("{id}")] - [AllowAnonymous] - [ProducesResponseType(typeof(MediaResponse), StatusCodes.Status200OK)] - [ProducesResponseType(StatusCodes.Status404NotFound)] - public async Task GetMedia([FromRoute] long id) => await mediaControllerService.GetMedia(id); + private readonly IMediaControllerService _mediaControllerService; #endregion - #region GENRES + #region CONSTRUCTORS + + public MediaController(IMediaControllerService mediaControllerService) + { + _mediaControllerService = mediaControllerService; + } + + #endregion + + + + #region METHODS + + #region Main + + [HttpGet("{id}")] + [AllowAnonymous] + [ProducesResponseType(typeof(MediaResponse), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task GetMedia([FromRoute] long id) => await _mediaControllerService.GetMedia(id); + + #endregion + + #region Genres [HttpGet("{id}/genres")] [AllowAnonymous] [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public async Task GetMediaGenres([FromRoute]long id) => await mediaControllerService.GetMediaGenres(id); + public async Task GetMediaGenres([FromRoute]long id) => await _mediaControllerService.GetMediaGenres(id); [HttpPost("{id}/genres/{genre_id}")] [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] @@ -38,7 +58,7 @@ public class MediaController(IMediaControllerService mediaControllerService) [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] [ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public async Task PostMediaGenre([FromRoute]long id, [FromRoute(Name = "genre_id")]short genreId) => await mediaControllerService.PostMediaGenre(id, genreId); + public async Task PostMediaGenre([FromRoute]long id, [FromRoute(Name = "genre_id")]short genreId) => await _mediaControllerService.PostMediaGenre(id, genreId); [HttpDelete("{id}/genres/{genre_id}")] [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] @@ -46,25 +66,23 @@ public class MediaController(IMediaControllerService mediaControllerService) [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] [ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public async Task DeleteMediaGenre([FromRoute]long id, [FromRoute(Name = "genre_id")]short genreId) => await mediaControllerService.DeleteMediaGenre(id, genreId); + public async Task DeleteMediaGenre([FromRoute]long id, [FromRoute(Name = "genre_id")]short genreId) => await _mediaControllerService.DeleteMediaGenre(id, genreId); #endregion - - - #region RATING + #region Rating [HttpGet("{id}/rating")] [AllowAnonymous] [ProducesResponseType(typeof(MediaRatingResponse), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public async Task GetMediaRating([FromRoute] long id) => await mediaControllerService.GetMediaRating(id); + public async Task GetMediaRating([FromRoute] long id) => await _mediaControllerService.GetMediaRating(id); [HttpGet("{id}/rating/{user_id}")] [AllowAnonymous] [ProducesResponseType(typeof(short), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public async Task GetMediaRatingByUser([FromRoute] long id, [FromRoute(Name = "user_id")]long userId) => await mediaControllerService.GetMediaRatingByUser(id, userId); + public async Task GetMediaRatingByUser([FromRoute] long id, [FromRoute(Name = "user_id")]long userId) => await _mediaControllerService.GetMediaRatingByUser(id, userId); [HttpPut("{id}/rating")] [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] @@ -72,38 +90,34 @@ public class MediaController(IMediaControllerService mediaControllerService) [ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public async Task PutMediaRating([FromRoute] long id, [FromBody] MediaRatingRequest data) => await mediaControllerService.PutMediaRating(id, data); + public async Task PutMediaRating([FromRoute] long id, [FromBody] MediaRatingRequest data) => await _mediaControllerService.PutMediaRating(id, data); [HttpDelete("{id}/rating")] [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] - public async Task DeleteMediaRating([FromRoute] long id) => await mediaControllerService.DeleteMediaRating(id); + public async Task DeleteMediaRating([FromRoute] long id) => await _mediaControllerService.DeleteMediaRating(id); #endregion - - - #region VIEW COUNT + #region View count [HttpPost("{id}/view")] [AllowAnonymous] [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public async Task PostMediaView([FromRoute] long id) => await mediaControllerService.PostMediaView(id); + public async Task PostMediaView([FromRoute] long id) => await _mediaControllerService.PostMediaView(id); #endregion - - - #region POSTER + #region Poster [HttpGet("{id}/poster")] [AllowAnonymous] [ProducesResponseType(typeof(MediaPosterResponse), StatusCodes.Status200OK)] [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public async Task GetMediaPoster([FromRoute] long id) => await mediaControllerService.GetMediaPoster(id); + public async Task GetMediaPoster([FromRoute] long id) => await _mediaControllerService.GetMediaPoster(id); [HttpPut("{id}/poster")] [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] @@ -111,68 +125,41 @@ public class MediaController(IMediaControllerService mediaControllerService) [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] [ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)] - public async Task PutMediaPoster([FromRoute]long id, [FromBody]MediaPosterRequest body) => await mediaControllerService.PutMediaPoster(id, body); + public async Task PutMediaPoster([FromRoute]long id, [FromBody]MediaPosterRequest body) => await _mediaControllerService.PutMediaPoster(id, body); [HttpDelete("{id}/poster")] [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] [ProducesResponseType(typeof(void), StatusCodes.Status204NoContent)] [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] [ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)] - public async Task DeleteMediaPoster([FromRoute]long id) => await mediaControllerService.DeleteMediaPoster(id); + public async Task DeleteMediaPoster([FromRoute]long id) => await _mediaControllerService.DeleteMediaPoster(id); #endregion + #region Photos - - #region PHOTOS + [HttpGet("{id}/photos")] + [AllowAnonymous] + [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task GetMediaPhotos([FromRoute]long id, PhotoQueryParameters query) => await _mediaControllerService.GetMediaPhotos(id, query); [HttpGet("{id}/photos/random_background")] [AllowAnonymous] - [ProducesResponseType(typeof(MediaPhotoResponse), StatusCodes.Status200OK)] + [ProducesResponseType(typeof(PhotoResponse), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public async Task GetMediaPhotoRandomBackground([FromRoute]long id) => await mediaControllerService.GetMediaRandomBackgroundPhoto(id); + public async Task GetMediaPhotoRandomBackground([FromRoute]long id) => await _mediaControllerService.GetMediaPhotoRandomBackground(id); - [HttpGet("photos/{photo_id}")] - [AllowAnonymous] - [ProducesResponseType(typeof(MediaPhotoResponse), StatusCodes.Status200OK)] - [ProducesResponseType(StatusCodes.Status404NotFound)] - public async Task GetPhoto([FromRoute(Name = "photo_id")] Guid photoId) => await mediaControllerService.GetPhoto(photoId); - - [HttpGet("photos")] - [AllowAnonymous] - [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] - public async Task GetPhotos(MediaPhotoQueryParameters query) => await mediaControllerService.GetPhotos(query); - - [HttpGet("photos/random_background")] - [AllowAnonymous] - [ProducesResponseType(typeof(MediaPhotoResponse), StatusCodes.Status200OK)] - [ProducesResponseType(StatusCodes.Status404NotFound)] - public async Task GetPhotoRandomBackground() => await mediaControllerService.GetRandomBackgroundPhoto(); - - [HttpPost("photos")] + [HttpPost("{id}/photos")] [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] - [ProducesResponseType(typeof(MediaPhotoResponse), StatusCodes.Status201Created)] - [ProducesResponseType(StatusCodes.Status400BadRequest)] - [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] - [ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)] - public async Task PostPhoto([FromBody]MediaPhotoRequest body) => await mediaControllerService.PostPhoto(body); - - [HttpPut("photos/{photo_id}")] - [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] - [ProducesResponseType(typeof(void), StatusCodes.Status200OK)] + [ProducesResponseType(typeof(PhotoResponse), StatusCodes.Status201Created)] [ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] [ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)] [ProducesResponseType(StatusCodes.Status404NotFound)] - public async Task PutPhoto([FromRoute(Name = "photo_id")]Guid photoId, [FromBody]MediaPhotoRequest body) => await mediaControllerService.PutPhoto(photoId, body); + public async Task PostPhoto([FromRoute]long id, [FromBody]MediaPhotoRequest body) => await _mediaControllerService.PostMediaPhoto(id, body); - [HttpDelete("photos/{photo_id}")] - [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] - [ProducesResponseType(typeof(void), StatusCodes.Status200OK)] - [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] - [ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)] - [ProducesResponseType(StatusCodes.Status404NotFound)] - public async Task DeletePhoto([FromRoute(Name = "photo_id")]Guid photoId) => await mediaControllerService.DeletePhoto(photoId); + #endregion #endregion } \ No newline at end of file diff --git a/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/PhotosController.cs b/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/PhotosController.cs new file mode 100644 index 0000000..1318c7d --- /dev/null +++ b/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/PhotosController.cs @@ -0,0 +1,74 @@ +using Microsoft.AspNetCore.Authentication.JwtBearer; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using WatchIt.Common.Model.Photos; +using WatchIt.WebAPI.Services.Controllers.Photos; + +namespace WatchIt.WebAPI.Controllers; + +[ApiController] +[Route("photos")] +public class PhotosController : ControllerBase +{ + #region FIELDS + + private readonly IPhotosControllerService _photosControllerService; + + #endregion + + + + #region CONSTRUCTORS + + public PhotosController(IPhotosControllerService photosControllerService) + { + _photosControllerService = photosControllerService; + } + + #endregion + + + + #region METHODS + + #region Main + + [HttpGet("random_background")] + [AllowAnonymous] + [ProducesResponseType(typeof(PhotoResponse), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task GetPhotoRandomBackground() => await _photosControllerService.GetPhotoRandomBackground(); + + [HttpDelete("{id}")] + [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] + [ProducesResponseType(typeof(void), StatusCodes.Status200OK)] + [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] + [ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task DeletePhoto([FromRoute] Guid id) => await _photosControllerService.DeletePhoto(id); + + #endregion + + #region Background data + + [HttpPut("{id}/background_data")] + [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] + [ProducesResponseType(typeof(void), StatusCodes.Status200OK)] + [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] + [ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task PutPhotoBackgroundData([FromRoute]Guid id, [FromBody] PhotoBackgroundDataRequest body) => await _photosControllerService.PutPhotoBackgroundData(id, body); + + [HttpDelete("{id}/background_data")] + [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] + [ProducesResponseType(typeof(void), StatusCodes.Status200OK)] + [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] + [ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task DeletePhotoBackgroundData([FromRoute]Guid id) => await _photosControllerService.DeletePhotoBackgroundData(id); + + #endregion + + #endregion +} \ No newline at end of file diff --git a/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/WatchIt.WebAPI.Controllers.csproj b/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/WatchIt.WebAPI.Controllers.csproj index 1b46756..809068e 100644 --- a/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/WatchIt.WebAPI.Controllers.csproj +++ b/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/WatchIt.WebAPI.Controllers.csproj @@ -17,6 +17,7 @@ + diff --git a/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Media/IMediaControllerService.cs b/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Media/IMediaControllerService.cs index 7e26c60..df8c5c4 100644 --- a/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Media/IMediaControllerService.cs +++ b/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Media/IMediaControllerService.cs @@ -1,4 +1,5 @@ using WatchIt.Common.Model.Media; +using WatchIt.Common.Model.Photos; using WatchIt.WebAPI.Services.Controllers.Common; namespace WatchIt.WebAPI.Services.Controllers.Media; @@ -21,12 +22,8 @@ public interface IMediaControllerService Task GetMediaPoster(long mediaId); Task PutMediaPoster(long mediaId, MediaPosterRequest data); Task DeleteMediaPoster(long mediaId); - - Task GetPhoto(Guid id); - Task GetPhotos(MediaPhotoQueryParameters query); - Task GetRandomBackgroundPhoto(); - Task GetMediaRandomBackgroundPhoto(long id); - Task PostPhoto(MediaPhotoRequest data); - Task PutPhoto(Guid photoId, MediaPhotoRequest data); - Task DeletePhoto(Guid photoId); + + Task GetMediaPhotos(long mediaId, PhotoQueryParameters queryParameters); + Task GetMediaPhotoRandomBackground(long mediaId); + Task PostMediaPhoto(long mediaId, MediaPhotoRequest data); } \ No newline at end of file diff --git a/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Media/MediaControllerService.cs b/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Media/MediaControllerService.cs index d33cea2..50ee996 100644 --- a/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Media/MediaControllerService.cs +++ b/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Media/MediaControllerService.cs @@ -2,6 +2,7 @@ using SimpleToolkit.Extensions; using WatchIt.Common.Model.Genres; using WatchIt.Common.Model.Media; +using WatchIt.Common.Model.Photos; using WatchIt.Database; using WatchIt.Database.Model.Media; using WatchIt.Database.Model.Rating; @@ -294,59 +295,48 @@ public class MediaControllerService(DatabaseContext database, IUserService userS #endregion #region Photos - - public async Task GetPhoto(Guid id) + + public async Task GetMediaPhotos(long mediaId, PhotoQueryParameters queryParameters) { - MediaPhotoImage? item = await database.MediaPhotoImages.FirstOrDefaultAsync(x => x.Id == id); - if (item is null) + Database.Model.Media.Media? media = await database.Media.FirstOrDefaultAsync(x => x.Id == mediaId); + if (media is null) { return RequestResult.NotFound(); } - - MediaPhotoResponse data = new MediaPhotoResponse(item); - return RequestResult.Ok(data); + + IEnumerable imagesRaw = await database.MediaPhotoImages.Where(x => x.MediaId == mediaId).ToListAsync(); + IEnumerable images = imagesRaw.Select(x => new PhotoResponse(x)); + images = queryParameters.PrepareData(images); + return RequestResult.Ok(images); } - public async Task GetPhotos(MediaPhotoQueryParameters query) + public Task GetMediaPhotoRandomBackground(long mediaId) { - IEnumerable data = await database.MediaPhotoImages.Select(x => new MediaPhotoResponse(x)).ToListAsync(); - data = query.PrepareData(data); - return RequestResult.Ok(data); - } - - public Task GetRandomBackgroundPhoto() - { - MediaPhotoImage? image = database.MediaPhotoImages.Where(x => x.MediaPhotoImageBackground != null && x.MediaPhotoImageBackground.IsUniversalBackground).Random(); + MediaPhotoImage? image = database.MediaPhotoImages.Where(x => x.MediaId == mediaId && x.MediaPhotoImageBackground != null).Random(); if (image is null) { return Task.FromResult(RequestResult.NotFound()); } - MediaPhotoResponse data = new MediaPhotoResponse(image); - return Task.FromResult(RequestResult.Ok(data)); - } - - public Task GetMediaRandomBackgroundPhoto(long id) - { - MediaPhotoImage? image = database.MediaPhotoImages.Where(x => x.MediaId == id && x.MediaPhotoImageBackground != null).Random(); - if (image is null) - { - return Task.FromResult(RequestResult.NotFound()); - } - - MediaPhotoResponse data = new MediaPhotoResponse(image); + PhotoResponse data = new PhotoResponse(image); return Task.FromResult(RequestResult.Ok(data)); } - public async Task PostPhoto(MediaPhotoRequest data) + public async Task PostMediaPhoto(long mediaId, MediaPhotoRequest data) { UserValidator validator = userService.GetValidator().MustBeAdmin(); if (!validator.IsValid) { return RequestResult.Forbidden(); } + + Database.Model.Media.Media? media = await database.Media.FirstOrDefaultAsync(x => x.Id == mediaId); + if (media is null) + { + return RequestResult.NotFound(); + } - MediaPhotoImage item = data.CreateMediaPhotoImage(); + MediaPhotoImage item = data.CreateMediaPhotoImage(mediaId); await database.MediaPhotoImages.AddAsync(item); await database.SaveChangesAsync(); @@ -357,69 +347,7 @@ public class MediaControllerService(DatabaseContext database, IUserService userS await database.SaveChangesAsync(); } - return RequestResult.Created($"photos/{item.Id}", new MediaPhotoResponse(item)); - } - - public async Task PutPhoto(Guid photoId, MediaPhotoRequest data) - { - UserValidator validator = userService.GetValidator().MustBeAdmin(); - if (!validator.IsValid) - { - return RequestResult.Forbidden(); - } - - MediaPhotoImage? item = await database.MediaPhotoImages.FirstOrDefaultAsync(x => x.Id == photoId); - if (item is null) - { - return RequestResult.NotFound(); - } - - data.UpdateMediaPhotoImage(item); - if (item.MediaPhotoImageBackground is null && data.Background is not null) - { - MediaPhotoImageBackground background = data.CreateMediaPhotoImageBackground(item.Id)!; - await database.MediaPhotoImageBackgrounds.AddAsync(background); - } - else if (item.MediaPhotoImageBackground is not null && data.Background is null) - { - database.MediaPhotoImageBackgrounds.Attach(item.MediaPhotoImageBackground); - database.MediaPhotoImageBackgrounds.Remove(item.MediaPhotoImageBackground); - } - else if (item.MediaPhotoImageBackground is not null && data.Background is not null) - { - data.UpdateMediaPhotoImageBackground(item.MediaPhotoImageBackground); - } - await database.SaveChangesAsync(); - - return RequestResult.Ok(); - } - - public async Task DeletePhoto(Guid photoId) - { - UserValidator validator = userService.GetValidator().MustBeAdmin(); - if (!validator.IsValid) - { - return RequestResult.Forbidden(); - } - - MediaPhotoImage? item = await database.MediaPhotoImages.FirstOrDefaultAsync(x => x.Id == photoId); - if (item is null) - { - return RequestResult.NotFound(); - } - - if (item.MediaPhotoImageBackground is not null) - { - database.MediaPhotoImageBackgrounds.Attach(item.MediaPhotoImageBackground); - database.MediaPhotoImageBackgrounds.Remove(item.MediaPhotoImageBackground); - await database.SaveChangesAsync(); - } - - database.MediaPhotoImages.Attach(item); - database.MediaPhotoImages.Remove(item); - await database.SaveChangesAsync(); - - return RequestResult.Ok(); + return RequestResult.Created($"photos/{item.Id}", new PhotoResponse(item)); } #endregion diff --git a/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Photos/IPhotosControllerService.cs b/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Photos/IPhotosControllerService.cs new file mode 100644 index 0000000..8b17b02 --- /dev/null +++ b/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Photos/IPhotosControllerService.cs @@ -0,0 +1,13 @@ +using WatchIt.Common.Model.Photos; +using WatchIt.WebAPI.Services.Controllers.Common; + +namespace WatchIt.WebAPI.Services.Controllers.Photos; + +public interface IPhotosControllerService +{ + Task GetPhotoRandomBackground(); + Task DeletePhoto(Guid photoId); + + Task PutPhotoBackgroundData(Guid id, PhotoBackgroundDataRequest data); + Task DeletePhotoBackgroundData(Guid id); +} \ No newline at end of file diff --git a/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Photos/PhotosControllerService.cs b/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Photos/PhotosControllerService.cs new file mode 100644 index 0000000..68b0627 --- /dev/null +++ b/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Photos/PhotosControllerService.cs @@ -0,0 +1,140 @@ +using Microsoft.AspNetCore.Identity; +using Microsoft.EntityFrameworkCore; +using SimpleToolkit.Extensions; +using WatchIt.Common.Model.Photos; +using WatchIt.Database; +using WatchIt.Database.Model.Media; +using WatchIt.WebAPI.Services.Controllers.Common; +using WatchIt.WebAPI.Services.Utility.User; + +namespace WatchIt.WebAPI.Services.Controllers.Photos; + +public class PhotosControllerService : IPhotosControllerService +{ + #region FIELDS + + private readonly DatabaseContext _database; + private readonly IUserService _userService; + + #endregion + + + + #region CONTRUCTORS + + public PhotosControllerService(DatabaseContext database, IUserService userService) + { + _database = database; + _userService = userService; + } + + #endregion + + + + #region PUBLIC METHODS + + #region Main + + public Task GetPhotoRandomBackground() + { + MediaPhotoImage? image = _database.MediaPhotoImages.Where(x => x.MediaPhotoImageBackground != null && x.MediaPhotoImageBackground.IsUniversalBackground).Random(); + if (image is null) + { + return Task.FromResult(RequestResult.NotFound()); + } + + PhotoResponse data = new PhotoResponse(image); + return Task.FromResult(RequestResult.Ok(data)); + } + + public async Task DeletePhoto(Guid photoId) + { + UserValidator validator = _userService.GetValidator().MustBeAdmin(); + if (!validator.IsValid) + { + return RequestResult.Forbidden(); + } + + MediaPhotoImage? item = await _database.MediaPhotoImages.FirstOrDefaultAsync(x => x.Id == photoId); + if (item is null) + { + return RequestResult.NotFound(); + } + + if (item.MediaPhotoImageBackground is not null) + { + _database.MediaPhotoImageBackgrounds.Attach(item.MediaPhotoImageBackground); + _database.MediaPhotoImageBackgrounds.Remove(item.MediaPhotoImageBackground); + await _database.SaveChangesAsync(); + } + + _database.MediaPhotoImages.Attach(item); + _database.MediaPhotoImages.Remove(item); + await _database.SaveChangesAsync(); + + return RequestResult.Ok(); + } + + #endregion + + #region Background data + + public async Task PutPhotoBackgroundData(Guid id, PhotoBackgroundDataRequest data) + { + UserValidator validator = _userService.GetValidator().MustBeAdmin(); + if (!validator.IsValid) + { + return RequestResult.Forbidden(); + } + + MediaPhotoImage? image = await _database.MediaPhotoImages.FirstOrDefaultAsync(x => x.Id == id); + if (image is null) + { + return RequestResult.NotFound(); + } + + MediaPhotoImageBackground? imageBackground = image.MediaPhotoImageBackground; + if (imageBackground is null) + { + imageBackground = data.CreateMediaPhotoImageBackground(id); + await _database.MediaPhotoImageBackgrounds.AddAsync(imageBackground); + } + else + { + data.UpdateMediaPhotoImageBackground(imageBackground); + } + await _database.SaveChangesAsync(); + + return RequestResult.Ok(); + } + + public async Task DeletePhotoBackgroundData(Guid id) + { + UserValidator validator = _userService.GetValidator().MustBeAdmin(); + if (!validator.IsValid) + { + return RequestResult.Forbidden(); + } + + MediaPhotoImage? image = await _database.MediaPhotoImages.FirstOrDefaultAsync(x => x.Id == id); + if (image is null) + { + return RequestResult.NotFound(); + } + + MediaPhotoImageBackground? imageBackground = image.MediaPhotoImageBackground; + if (imageBackground is not null) + { + _database.MediaPhotoImageBackgrounds.Attach(imageBackground); + _database.MediaPhotoImageBackgrounds.Remove(imageBackground); + await _database.SaveChangesAsync(); + } + + return RequestResult.Ok(); + } + + #endregion + + #endregion +} \ No newline at end of file diff --git a/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Photos/WatchIt.WebAPI.Services.Controllers.Photos.csproj b/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Photos/WatchIt.WebAPI.Services.Controllers.Photos.csproj new file mode 100644 index 0000000..f5730de --- /dev/null +++ b/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Photos/WatchIt.WebAPI.Services.Controllers.Photos.csproj @@ -0,0 +1,20 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + + + + diff --git a/WatchIt.WebAPI/WatchIt.WebAPI.Validators/Media/MediaPhotoRequestValidator.cs b/WatchIt.WebAPI/WatchIt.WebAPI.Validators/Media/MediaPhotoRequestValidator.cs index 6b0d92d..4561c75 100644 --- a/WatchIt.WebAPI/WatchIt.WebAPI.Validators/Media/MediaPhotoRequestValidator.cs +++ b/WatchIt.WebAPI/WatchIt.WebAPI.Validators/Media/MediaPhotoRequestValidator.cs @@ -2,20 +2,19 @@ using Microsoft.EntityFrameworkCore.Scaffolding.Metadata; using WatchIt.Common.Model.Media; using WatchIt.Database; +using WatchIt.WebAPI.Validators.Photos; namespace WatchIt.WebAPI.Validators.Media; public class MediaPhotoRequestValidator : AbstractValidator { - public MediaPhotoRequestValidator(DatabaseContext database) + public MediaPhotoRequestValidator() { - RuleFor(x => x.MediaId).MustBeIn(database.Media, x => x.Id).WithMessage("Media does not exists"); RuleFor(x => x.Image).NotEmpty(); RuleFor(x => x.MimeType).Matches(@"\w+/.+").WithMessage("Incorrect mimetype"); When(x => x.Background is not null, () => { - RuleFor(x => x.Background!.FirstGradientColor).Must(x => x.Length == 3).WithMessage("First gradient color has to be 3 byte long"); - RuleFor(x => x.Background!.SecondGradientColor).Must(x => x.Length == 3).WithMessage("Second gradient color has to be 3 byte long"); + RuleFor(x => x.Background!).SetValidator(new PhotoBackgroundDataValidator()); }); } } \ No newline at end of file diff --git a/WatchIt.WebAPI/WatchIt.WebAPI.Validators/Photos/PhotoBackgroundDataRequestValidator.cs b/WatchIt.WebAPI/WatchIt.WebAPI.Validators/Photos/PhotoBackgroundDataRequestValidator.cs new file mode 100644 index 0000000..bbf414e --- /dev/null +++ b/WatchIt.WebAPI/WatchIt.WebAPI.Validators/Photos/PhotoBackgroundDataRequestValidator.cs @@ -0,0 +1,12 @@ +using FluentValidation; +using WatchIt.Common.Model.Photos; + +namespace WatchIt.WebAPI.Validators.Photos; + +public class PhotoBackgroundDataRequestValidator : AbstractValidator +{ + public PhotoBackgroundDataRequestValidator() + { + RuleFor(x => x).SetValidator(new PhotoBackgroundDataValidator()); + } +} \ No newline at end of file diff --git a/WatchIt.WebAPI/WatchIt.WebAPI.Validators/Photos/PhotoBackgroundDataValidator.cs b/WatchIt.WebAPI/WatchIt.WebAPI.Validators/Photos/PhotoBackgroundDataValidator.cs new file mode 100644 index 0000000..58f0d8a --- /dev/null +++ b/WatchIt.WebAPI/WatchIt.WebAPI.Validators/Photos/PhotoBackgroundDataValidator.cs @@ -0,0 +1,13 @@ +using FluentValidation; +using WatchIt.Common.Model.Photos; + +namespace WatchIt.WebAPI.Validators.Photos; + +public class PhotoBackgroundDataValidator : AbstractValidator +{ + public PhotoBackgroundDataValidator() + { + RuleFor(x => x.FirstGradientColor).Must(x => x.Length == 3).WithMessage("First gradient color has to be 3 byte long"); + RuleFor(x => x.SecondGradientColor).Must(x => x.Length == 3).WithMessage("Second gradient color has to be 3 byte long"); + } +} \ No newline at end of file diff --git a/WatchIt.WebAPI/WatchIt.WebAPI/Program.cs b/WatchIt.WebAPI/WatchIt.WebAPI/Program.cs index d52813c..7bd902b 100644 --- a/WatchIt.WebAPI/WatchIt.WebAPI/Program.cs +++ b/WatchIt.WebAPI/WatchIt.WebAPI/Program.cs @@ -13,6 +13,7 @@ using WatchIt.WebAPI.Services.Controllers.Accounts; using WatchIt.WebAPI.Services.Controllers.Genres; using WatchIt.WebAPI.Services.Controllers.Media; using WatchIt.WebAPI.Services.Controllers.Movies; +using WatchIt.WebAPI.Services.Controllers.Photos; using WatchIt.WebAPI.Services.Controllers.Series; using WatchIt.WebAPI.Services.Utility.Configuration; using WatchIt.WebAPI.Services.Utility.Tokens; @@ -156,6 +157,7 @@ public static class Program builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); + builder.Services.AddTransient(); return builder; } diff --git a/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.Utility/WatchIt.Website.Services.Utility.Configuration/Model/Endpoints.cs b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.Utility/WatchIt.Website.Services.Utility.Configuration/Model/Endpoints.cs index a71bdbf..765dd46 100644 --- a/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.Utility/WatchIt.Website.Services.Utility.Configuration/Model/Endpoints.cs +++ b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.Utility/WatchIt.Website.Services.Utility.Configuration/Model/Endpoints.cs @@ -8,4 +8,5 @@ public class Endpoints public Media Media { get; set; } public Movies Movies { get; set; } public Series Series { get; set; } + public Photos Photos { get; set; } } \ No newline at end of file diff --git a/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.Utility/WatchIt.Website.Services.Utility.Configuration/Model/Media.cs b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.Utility/WatchIt.Website.Services.Utility.Configuration/Model/Media.cs index fb215e2..3774ebd 100644 --- a/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.Utility/WatchIt.Website.Services.Utility.Configuration/Model/Media.cs +++ b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.Utility/WatchIt.Website.Services.Utility.Configuration/Model/Media.cs @@ -3,23 +3,19 @@ public class Media { public string Base { get; set; } - public string Get { get; set; } - public string GetGenres { get; set; } - public string PostGenre { get; set; } - public string DeleteGenre { get; set; } + public string GetMedia { get; set; } + public string GetMediaGenres { get; set; } + public string PostMediaGenre { get; set; } + public string DeleteMediaGenre { get; set; } public string GetMediaRating { get; set; } public string GetMediaRatingByUser { get; set; } public string PutMediaRating { get; set; } public string DeleteMediaRating { get; set; } public string PostMediaView { get; set; } - public string GetPhotoMediaRandomBackground { get; set; } - public string GetPoster { get; set; } - public string PutPoster { get; set; } - public string DeletePoster { get; set; } - public string GetPhoto { get; set; } - public string GetPhotos { get; set; } - public string GetPhotoRandomBackground { get; set; } - public string PostPhoto { get; set; } - public string PutPhoto { get; set; } - public string DeletePhoto { get; set; } + public string GetMediaPoster { get; set; } + public string PutMediaPoster { get; set; } + public string DeleteMediaPoster { get; set; } + public string GetMediaPhotos { get; set; } + public string GetMediaPhotoRandomBackground { get; set; } + public string PostMediaPhoto { get; set; } } \ No newline at end of file diff --git a/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.Utility/WatchIt.Website.Services.Utility.Configuration/Model/Photos.cs b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.Utility/WatchIt.Website.Services.Utility.Configuration/Model/Photos.cs new file mode 100644 index 0000000..46384b4 --- /dev/null +++ b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.Utility/WatchIt.Website.Services.Utility.Configuration/Model/Photos.cs @@ -0,0 +1,10 @@ +namespace WatchIt.Website.Services.Utility.Configuration.Model; + +public class Photos +{ + public string Base { get; set; } + public string GetPhotoRandomBackground { get; set; } + public string DeletePhoto { get; set; } + public string PutPhotoBackgroundData { get; set; } + public string DeletePhotoBackgroundData { get; set; } +} \ No newline at end of file diff --git a/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Media/IMediaWebAPIService.cs b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Media/IMediaWebAPIService.cs index 923607d..4eae4f4 100644 --- a/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Media/IMediaWebAPIService.cs +++ b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Media/IMediaWebAPIService.cs @@ -1,5 +1,6 @@ using WatchIt.Common.Model.Genres; using WatchIt.Common.Model.Media; +using WatchIt.Common.Model.Photos; namespace WatchIt.Website.Services.WebAPI.Media; @@ -9,6 +10,7 @@ public interface IMediaWebAPIService Task GetMediaGenres(long mediaId, Action>? successAction = null, Action? notFoundAction = null); Task PostMediaGenre(long mediaId, long genreId, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null, Action? notFoundAction = null); + Task DeleteMediaGenre(long mediaId, long genreId, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null, Action? notFoundAction = null); Task GetMediaRating(long mediaId, Action? successAction = null, Action? notFoundAction = null); Task GetMediaRatingByUser(long mediaId, long userId, Action? successAction = null, Action? notFoundAction = null); @@ -17,9 +19,11 @@ public interface IMediaWebAPIService Task PostMediaView(long mediaId, Action? successAction = null, Action? notFoundAction = null); - Task GetPhotoMediaRandomBackground(long mediaId, Action? successAction = null, Action? notFoundAction = null); - Task GetPhotoRandomBackground(Action? successAction = null, Action? notFoundAction = null); - Task GetPoster(long mediaId, Action? successAction = null, Action>? badRequestAction = null, Action? notFoundAction = null); - Task PutPoster(long mediaId, MediaPosterRequest data, Action? successAction = null, Action>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null); - Task DeletePoster(long mediaId, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null); + Task GetMediaPoster(long mediaId, Action? successAction = null, Action>? badRequestAction = null, Action? notFoundAction = null); + Task PutMediaPoster(long mediaId, MediaPosterRequest data, Action? successAction = null, Action>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null); + Task DeleteMediaPoster(long mediaId, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null); + + Task GetMediaPhotos(long mediaId, PhotoQueryParameters? query = null, Action>? successAction = null, Action? notFoundAction = null); + Task GetMediaPhotoRandomBackground(long mediaId, Action? successAction = null, Action? notFoundAction = null); + Task PostMediaPhoto(long mediaId, MediaPhotoRequest data, Action? successAction = null, Action>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null, Action? notFoundAction = null); } \ No newline at end of file diff --git a/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Media/MediaWebAPIService.cs b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Media/MediaWebAPIService.cs index b8780fd..d6cf3aa 100644 --- a/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Media/MediaWebAPIService.cs +++ b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Media/MediaWebAPIService.cs @@ -1,5 +1,6 @@ using WatchIt.Common.Model.Genres; using WatchIt.Common.Model.Media; +using WatchIt.Common.Model.Photos; using WatchIt.Common.Services.HttpClient; using WatchIt.Website.Services.Utility.Configuration; using WatchIt.Website.Services.Utility.Configuration.Model; @@ -7,19 +8,38 @@ using WatchIt.Website.Services.WebAPI.Common; namespace WatchIt.Website.Services.WebAPI.Media; -public class MediaWebAPIService(IHttpClientService httpClientService, IConfigurationService configurationService) : BaseWebAPIService(configurationService), IMediaWebAPIService +public class MediaWebAPIService : BaseWebAPIService, IMediaWebAPIService { + #region FIELDS + + private readonly IHttpClientService _httpClientService; + + #endregion + + + + #region CONSTRUCTORS + + public MediaWebAPIService(IHttpClientService httpClientService, IConfigurationService configurationService) : base(configurationService) + { + _httpClientService = httpClientService; + } + + #endregion + + + #region PUBLIC METHODS #region Main public async Task GetMedia(long mediaId, Action? successAction = null, Action? notFoundAction = null) { - string url = GetUrl(EndpointsConfiguration.Media.Get, mediaId); + string url = GetUrl(EndpointsConfiguration.Media.GetMedia, mediaId); HttpRequest request = new HttpRequest(HttpMethodType.Get, url); - HttpResponse response = await httpClientService.SendRequestAsync(request); + HttpResponse response = await _httpClientService.SendRequestAsync(request); response.RegisterActionFor2XXSuccess(successAction) .RegisterActionFor404NotFound(notFoundAction) .ExecuteAction(); @@ -31,11 +51,11 @@ public class MediaWebAPIService(IHttpClientService httpClientService, IConfigura public async Task GetMediaGenres(long mediaId, Action>? successAction = null, Action? notFoundAction = null) { - string url = GetUrl(EndpointsConfiguration.Media.GetGenres, mediaId); + string url = GetUrl(EndpointsConfiguration.Media.GetMediaGenres, mediaId); HttpRequest request = new HttpRequest(HttpMethodType.Get, url); - HttpResponse response = await httpClientService.SendRequestAsync(request); + HttpResponse response = await _httpClientService.SendRequestAsync(request); response.RegisterActionFor2XXSuccess(successAction) .RegisterActionFor404NotFound(notFoundAction) .ExecuteAction(); @@ -43,11 +63,25 @@ public class MediaWebAPIService(IHttpClientService httpClientService, IConfigura public async Task PostMediaGenre(long mediaId, long genreId, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null, Action? notFoundAction = null) { - string url = GetUrl(EndpointsConfiguration.Media.PostGenre, mediaId, genreId); + string url = GetUrl(EndpointsConfiguration.Media.PostMediaGenre, mediaId, genreId); - HttpRequest request = new HttpRequest(HttpMethodType.Get, url); + HttpRequest request = new HttpRequest(HttpMethodType.Post, url); - HttpResponse response = await httpClientService.SendRequestAsync(request); + HttpResponse response = await _httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .RegisterActionFor401Unauthorized(unauthorizedAction) + .RegisterActionFor403Forbidden(forbiddenAction) + .RegisterActionFor404NotFound(notFoundAction) + .ExecuteAction(); + } + + public async Task DeleteMediaGenre(long mediaId, long genreId, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null, Action? notFoundAction = null) + { + string url = GetUrl(EndpointsConfiguration.Media.DeleteMediaGenre, mediaId, genreId); + + HttpRequest request = new HttpRequest(HttpMethodType.Delete, url); + + HttpResponse response = await _httpClientService.SendRequestAsync(request); response.RegisterActionFor2XXSuccess(successAction) .RegisterActionFor401Unauthorized(unauthorizedAction) .RegisterActionFor403Forbidden(forbiddenAction) @@ -65,7 +99,7 @@ public class MediaWebAPIService(IHttpClientService httpClientService, IConfigura HttpRequest request = new HttpRequest(HttpMethodType.Get, url); - HttpResponse response = await httpClientService.SendRequestAsync(request); + HttpResponse response = await _httpClientService.SendRequestAsync(request); response.RegisterActionFor2XXSuccess(successAction) .RegisterActionFor404NotFound(notFoundAction) .ExecuteAction(); @@ -77,7 +111,7 @@ public class MediaWebAPIService(IHttpClientService httpClientService, IConfigura HttpRequest request = new HttpRequest(HttpMethodType.Get, url); - HttpResponse response = await httpClientService.SendRequestAsync(request); + HttpResponse response = await _httpClientService.SendRequestAsync(request); response.RegisterActionFor2XXSuccess(successAction) .RegisterActionFor404NotFound(notFoundAction) .ExecuteAction(); @@ -92,7 +126,7 @@ public class MediaWebAPIService(IHttpClientService httpClientService, IConfigura Body = body }; - HttpResponse response = await httpClientService.SendRequestAsync(request); + HttpResponse response = await _httpClientService.SendRequestAsync(request); response.RegisterActionFor2XXSuccess(successAction) .RegisterActionFor400BadRequest(badRequestAction) .RegisterActionFor401Unauthorized(unauthorizedAction) @@ -106,7 +140,7 @@ public class MediaWebAPIService(IHttpClientService httpClientService, IConfigura HttpRequest request = new HttpRequest(HttpMethodType.Delete, url); - HttpResponse response = await httpClientService.SendRequestAsync(request); + HttpResponse response = await _httpClientService.SendRequestAsync(request); response.RegisterActionFor2XXSuccess(successAction) .RegisterActionFor401Unauthorized(unauthorizedAction) .ExecuteAction(); @@ -122,7 +156,7 @@ public class MediaWebAPIService(IHttpClientService httpClientService, IConfigura HttpRequest request = new HttpRequest(HttpMethodType.Post, url); - HttpResponse response = await httpClientService.SendRequestAsync(request); + HttpResponse response = await _httpClientService.SendRequestAsync(request); response.RegisterActionFor2XXSuccess(successAction) .RegisterActionFor404NotFound(notFoundAction) .ExecuteAction(); @@ -130,55 +164,31 @@ public class MediaWebAPIService(IHttpClientService httpClientService, IConfigura #endregion + #region Poster - - public async Task GetPhotoMediaRandomBackground(long mediaId, Action? successAction = null, Action? notFoundAction = null) + public async Task GetMediaPoster(long mediaId, Action? successAction = null, Action>? badRequestAction = null, Action? notFoundAction = null) { - string url = GetUrl(EndpointsConfiguration.Media.GetPhotoMediaRandomBackground, mediaId); + string url = GetUrl(EndpointsConfiguration.Media.GetMediaPoster, mediaId); HttpRequest request = new HttpRequest(HttpMethodType.Get, url); - HttpResponse response = await httpClientService.SendRequestAsync(request); - response.RegisterActionFor2XXSuccess(successAction) - .RegisterActionFor404NotFound(notFoundAction) - .ExecuteAction(); - } - - public async Task GetPhotoRandomBackground(Action? successAction = null, Action? notFoundAction = null) - { - string url = GetUrl(EndpointsConfiguration.Media.GetPhotoRandomBackground); - - HttpRequest request = new HttpRequest(HttpMethodType.Get, url); - - HttpResponse response = await httpClientService.SendRequestAsync(request); - response.RegisterActionFor2XXSuccess(successAction) - .RegisterActionFor404NotFound(notFoundAction) - .ExecuteAction(); - } - - public async Task GetPoster(long mediaId, Action? successAction = null, Action>? badRequestAction = null, Action? notFoundAction = null) - { - string url = GetUrl(EndpointsConfiguration.Media.GetPoster, mediaId); - - HttpRequest request = new HttpRequest(HttpMethodType.Get, url); - - HttpResponse response = await httpClientService.SendRequestAsync(request); + HttpResponse response = await _httpClientService.SendRequestAsync(request); response.RegisterActionFor2XXSuccess(successAction) .RegisterActionFor400BadRequest(badRequestAction) .RegisterActionFor404NotFound(notFoundAction) .ExecuteAction(); } - public async Task PutPoster(long mediaId, MediaPosterRequest data, Action? successAction = null, Action>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null) + public async Task PutMediaPoster(long mediaId, MediaPosterRequest data, Action? successAction = null, Action>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null) { - string url = GetUrl(EndpointsConfiguration.Media.PutPoster, mediaId); + string url = GetUrl(EndpointsConfiguration.Media.PutMediaPoster, mediaId); HttpRequest request = new HttpRequest(HttpMethodType.Put, url) { Body = data }; - HttpResponse response = await httpClientService.SendRequestAsync(request); + HttpResponse response = await _httpClientService.SendRequestAsync(request); response.RegisterActionFor2XXSuccess(successAction) .RegisterActionFor400BadRequest(badRequestAction) .RegisterActionFor401Unauthorized(unauthorizedAction) @@ -186,18 +196,63 @@ public class MediaWebAPIService(IHttpClientService httpClientService, IConfigura .ExecuteAction(); } - public async Task DeletePoster(long mediaId, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null) + public async Task DeleteMediaPoster(long mediaId, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null) { - string url = GetUrl(EndpointsConfiguration.Media.DeletePoster, mediaId); + string url = GetUrl(EndpointsConfiguration.Media.DeleteMediaPoster, mediaId); HttpRequest request = new HttpRequest(HttpMethodType.Delete, url); - HttpResponse response = await httpClientService.SendRequestAsync(request); + HttpResponse response = await _httpClientService.SendRequestAsync(request); response.RegisterActionFor2XXSuccess(successAction) .RegisterActionFor401Unauthorized(unauthorizedAction) .RegisterActionFor403Forbidden(forbiddenAction) .ExecuteAction(); } + + #endregion + + #region Photos + + public async Task GetMediaPhotos(long mediaId, PhotoQueryParameters? query = null, Action>? successAction = null, Action? notFoundAction = null) + { + string url = GetUrl(EndpointsConfiguration.Media.GetMediaPhotos, mediaId); + + HttpRequest request = new HttpRequest(HttpMethodType.Get, url); + + HttpResponse response = await _httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .RegisterActionFor404NotFound(notFoundAction) + .ExecuteAction(); + } + + public async Task GetMediaPhotoRandomBackground(long mediaId, Action? successAction = null, Action? notFoundAction = null) + { + string url = GetUrl(EndpointsConfiguration.Media.GetMediaPhotoRandomBackground, mediaId); + + HttpRequest request = new HttpRequest(HttpMethodType.Get, url); + + HttpResponse response = await _httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .RegisterActionFor404NotFound(notFoundAction) + .ExecuteAction(); + } + + public async Task PostMediaPhoto(long mediaId, MediaPhotoRequest data, Action? successAction = null, Action>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null, Action? notFoundAction = null) + { + string url = GetUrl(EndpointsConfiguration.Media.PostMediaPhoto, mediaId); + + HttpRequest request = new HttpRequest(HttpMethodType.Post, url); + + HttpResponse response = await _httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .RegisterActionFor400BadRequest(badRequestAction) + .RegisterActionFor401Unauthorized(unauthorizedAction) + .RegisterActionFor403Forbidden(forbiddenAction) + .RegisterActionFor404NotFound(notFoundAction) + .ExecuteAction(); + } + + #endregion #endregion diff --git a/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Photos/IPhotosWebAPIService.cs b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Photos/IPhotosWebAPIService.cs new file mode 100644 index 0000000..efc83d9 --- /dev/null +++ b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Photos/IPhotosWebAPIService.cs @@ -0,0 +1,11 @@ +using WatchIt.Common.Model.Photos; + +namespace WatchIt.Website.Services.WebAPI.Photos; + +public interface IPhotosWebAPIService +{ + Task GetPhotoRandomBackground(Action? successAction = null, Action? notFoundAction = null); + Task DeletePhoto(Guid id, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null, Action? notFoundAction = null); + Task PutPhotoBackgroundData(Guid id, PhotoBackgroundDataRequest data, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null, Action? notFoundAction = null); + Task DeletePhotoBackgroundData(Guid id, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null, Action? notFoundAction = null); +} \ No newline at end of file diff --git a/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Photos/PhotosWebAPIService.cs b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Photos/PhotosWebAPIService.cs new file mode 100644 index 0000000..2c149c5 --- /dev/null +++ b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Photos/PhotosWebAPIService.cs @@ -0,0 +1,105 @@ +using WatchIt.Common.Model.Photos; +using WatchIt.Common.Services.HttpClient; +using WatchIt.Website.Services.Utility.Configuration; +using WatchIt.Website.Services.WebAPI.Common; + +namespace WatchIt.Website.Services.WebAPI.Photos; + +public class PhotosWebAPIService : BaseWebAPIService, IPhotosWebAPIService +{ + #region FIELDS + + private readonly IHttpClientService _httpClientService; + + #endregion + + + + #region CONSTRUCTORS + + public PhotosWebAPIService(IHttpClientService httpClientService, IConfigurationService configurationService) : base(configurationService) + { + _httpClientService = httpClientService; + } + + #endregion + + + + #region PUBLIC METHODS + + #region Main + + public async Task GetPhotoRandomBackground(Action? successAction = null, Action? notFoundAction = null) + { + string url = GetUrl(EndpointsConfiguration.Photos.GetPhotoRandomBackground); + + HttpRequest request = new HttpRequest(HttpMethodType.Get, url); + + HttpResponse response = await _httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .RegisterActionFor404NotFound(notFoundAction) + .ExecuteAction(); + } + + public async Task DeletePhoto(Guid id, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null, Action? notFoundAction = null) + { + string url = GetUrl(EndpointsConfiguration.Photos.DeletePhoto, id); + + HttpRequest request = new HttpRequest(HttpMethodType.Delete, url); + + HttpResponse response = await _httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .RegisterActionFor401Unauthorized(unauthorizedAction) + .RegisterActionFor403Forbidden(forbiddenAction) + .RegisterActionFor404NotFound(notFoundAction) + .ExecuteAction(); + } + + #endregion + + #region Background data + + public async Task PutPhotoBackgroundData(Guid id, PhotoBackgroundDataRequest data, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null, Action? notFoundAction = null) + { + string url = GetUrl(EndpointsConfiguration.Photos.PutPhotoBackgroundData, id); + + HttpRequest request = new HttpRequest(HttpMethodType.Put, url) + { + Body = data + }; + + HttpResponse response = await _httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .RegisterActionFor401Unauthorized(unauthorizedAction) + .RegisterActionFor403Forbidden(forbiddenAction) + .RegisterActionFor404NotFound(notFoundAction) + .ExecuteAction(); + } + + public async Task DeletePhotoBackgroundData(Guid id, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null, Action? notFoundAction = null) + { + string url = GetUrl(EndpointsConfiguration.Photos.DeletePhotoBackgroundData, id); + + HttpRequest request = new HttpRequest(HttpMethodType.Delete, url); + + HttpResponse response = await _httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .RegisterActionFor401Unauthorized(unauthorizedAction) + .RegisterActionFor403Forbidden(forbiddenAction) + .RegisterActionFor404NotFound(notFoundAction) + .ExecuteAction(); + } + + #endregion + + #endregion + + + + #region PRIVATE METHODS + + protected override string GetServiceBase() => EndpointsConfiguration.Photos.Base; + + #endregion +} \ No newline at end of file diff --git a/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Photos/WatchIt.Website.Services.WebAPI.Photos.csproj b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Photos/WatchIt.Website.Services.WebAPI.Photos.csproj new file mode 100644 index 0000000..79bbe83 --- /dev/null +++ b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Photos/WatchIt.Website.Services.WebAPI.Photos.csproj @@ -0,0 +1,15 @@ + + + + net8.0 + enable + enable + + + + + + + + + diff --git a/WatchIt.Website/WatchIt.Website/Layout/MainLayout.razor b/WatchIt.Website/WatchIt.Website/Layout/MainLayout.razor index 0b21658..338cb2f 100644 --- a/WatchIt.Website/WatchIt.Website/Layout/MainLayout.razor +++ b/WatchIt.Website/WatchIt.Website/Layout/MainLayout.razor @@ -1,4 +1,6 @@ -@inherits LayoutComponentBase +@using WatchIt.Common.Model.Photos +@using WatchIt.Website.Services.WebAPI.Photos +@inherits LayoutComponentBase @if (_loaded) { @@ -87,6 +89,7 @@ [Inject] public IAuthenticationService AuthenticationService { get; set; } = default!; [Inject] public IAccountsWebAPIService AccountsWebAPIService { get; set; } = default!; [Inject] public IMediaWebAPIService MediaWebAPIService { get; set; } = default!; + [Inject] public IPhotosWebAPIService PhotosWebAPIService { get; set; } = default!; #endregion @@ -134,7 +137,7 @@ private async Task GetBackground() { - Action backgroundSuccess = (data) => + Action backgroundSuccess = (data) => { string imageBase64 = Convert.ToBase64String(data.Image); string firstColor = BitConverter.ToString(data.Background.FirstGradientColor) @@ -146,7 +149,7 @@ _firstGradientColor = $"#{firstColor}"; _secondGradientColor = $"#{secondColor}"; }; - await MediaWebAPIService.GetPhotoRandomBackground(backgroundSuccess); + await PhotosWebAPIService.GetPhotoRandomBackground(backgroundSuccess); } private async Task GetAuthenticatedUser() diff --git a/WatchIt.Website/WatchIt.Website/Pages/AuthPage.razor.cs b/WatchIt.Website/WatchIt.Website/Pages/AuthPage.razor.cs index f45313f..d2b5b85 100644 --- a/WatchIt.Website/WatchIt.Website/Pages/AuthPage.razor.cs +++ b/WatchIt.Website/WatchIt.Website/Pages/AuthPage.razor.cs @@ -1,10 +1,12 @@ using Microsoft.AspNetCore.Components; using WatchIt.Common.Model.Accounts; using WatchIt.Common.Model.Media; +using WatchIt.Common.Model.Photos; using WatchIt.Website.Services.Utility.Authentication; using WatchIt.Website.Services.Utility.Tokens; using WatchIt.Website.Services.WebAPI.Accounts; using WatchIt.Website.Services.WebAPI.Media; +using WatchIt.Website.Services.WebAPI.Photos; namespace WatchIt.Website.Pages; @@ -17,6 +19,7 @@ public partial class AuthPage [Inject] public ITokensService TokensService { get; set; } = default!; [Inject] public IMediaWebAPIService MediaWebAPIService { get; set; } = default!; [Inject] public IAccountsWebAPIService AccountsWebAPIService { get; set; } = default!; + [Inject] public IPhotosWebAPIService PhotosWebAPIService { get; set; } = default!; [Inject] public NavigationManager NavigationManager { get; set; } = default!; #endregion @@ -75,7 +78,7 @@ public partial class AuthPage NavigationManager.NavigateTo("/"); } - Action backgroundSuccess = (data) => + Action backgroundSuccess = (data) => { string imageBase64 = Convert.ToBase64String(data.Image); string firstColor = BitConverter.ToString(data.Background.FirstGradientColor) @@ -87,7 +90,7 @@ public partial class AuthPage _firstGradientColor = $"#{firstColor}"; _secondGradientColor = $"#{secondColor}"; }; - await MediaWebAPIService.GetPhotoRandomBackground(backgroundSuccess); + await PhotosWebAPIService.GetPhotoRandomBackground(backgroundSuccess); _loaded = true; StateHasChanged(); diff --git a/WatchIt.Website/WatchIt.Website/Pages/HomePage.razor.cs b/WatchIt.Website/WatchIt.Website/Pages/HomePage.razor.cs index 170b8a6..706a9c6 100644 --- a/WatchIt.Website/WatchIt.Website/Pages/HomePage.razor.cs +++ b/WatchIt.Website/WatchIt.Website/Pages/HomePage.razor.cs @@ -53,8 +53,8 @@ public partial class HomePage await Task.WhenAll(step1Tasks); endTasks.AddRange( [ - Parallel.ForEachAsync(_topMovies, async (x, _) => await MediaWebAPIService.GetPoster(x.Key.Id, y => _topMovies[x.Key] = y)), - Parallel.ForEachAsync(_topSeries, async (x, _) => await MediaWebAPIService.GetPoster(x.Key.Id, y => _topSeries[x.Key] = y)) + Parallel.ForEachAsync(_topMovies, async (x, _) => await MediaWebAPIService.GetMediaPoster(x.Key.Id, y => _topMovies[x.Key] = y)), + Parallel.ForEachAsync(_topSeries, async (x, _) => await MediaWebAPIService.GetMediaPoster(x.Key.Id, y => _topSeries[x.Key] = y)) ]); // END diff --git a/WatchIt.Website/WatchIt.Website/Pages/MediaEditPage.razor.cs b/WatchIt.Website/WatchIt.Website/Pages/MediaEditPage.razor.cs index 6d98912..feb4653 100644 --- a/WatchIt.Website/WatchIt.Website/Pages/MediaEditPage.razor.cs +++ b/WatchIt.Website/WatchIt.Website/Pages/MediaEditPage.razor.cs @@ -3,10 +3,12 @@ using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Components.Forms; using WatchIt.Common.Model.Media; using WatchIt.Common.Model.Movies; +using WatchIt.Common.Model.Photos; using WatchIt.Common.Model.Series; using WatchIt.Website.Services.Utility.Authentication; using WatchIt.Website.Services.WebAPI.Media; using WatchIt.Website.Services.WebAPI.Movies; +using WatchIt.Website.Services.WebAPI.Photos; using WatchIt.Website.Services.WebAPI.Series; namespace WatchIt.Website.Pages; @@ -41,7 +43,7 @@ public partial class MediaEditPage : ComponentBase private User? _user; - private MediaPhotoResponse? _background; + private PhotoResponse? _background; private MediaResponse? _media; private MovieRequest? _movieRequest; @@ -94,8 +96,8 @@ public partial class MediaEditPage : ComponentBase { endTasks.AddRange( [ - MediaWebAPIService.GetPhotoMediaRandomBackground(Id.Value, data => _background = data), - MediaWebAPIService.GetPoster(Id.Value, data => + MediaWebAPIService.GetMediaPhotoRandomBackground(Id.Value, data => _background = data), + MediaWebAPIService.GetMediaPoster(Id.Value, data => { _mediaPosterSaved = data; _mediaPosterRequest = new MediaPosterRequest(data); @@ -179,7 +181,7 @@ public partial class MediaEditPage : ComponentBase } _mediaPosterSaving = true; - await MediaWebAPIService.PutPoster(Id.Value, _mediaPosterRequest, Success); + await MediaWebAPIService.PutMediaPoster(Id.Value, _mediaPosterRequest, Success); } private void CancelPoster() @@ -199,7 +201,7 @@ public partial class MediaEditPage : ComponentBase } _mediaPosterDeleting = true; - await MediaWebAPIService.DeletePoster(Id.Value, Success); + await MediaWebAPIService.DeleteMediaPoster(Id.Value, Success); } #endregion diff --git a/WatchIt.Website/WatchIt.Website/Pages/MediaPage.razor.cs b/WatchIt.Website/WatchIt.Website/Pages/MediaPage.razor.cs index cf834a2..0df1dc3 100644 --- a/WatchIt.Website/WatchIt.Website/Pages/MediaPage.razor.cs +++ b/WatchIt.Website/WatchIt.Website/Pages/MediaPage.razor.cs @@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Components; using WatchIt.Common.Model.Genres; using WatchIt.Common.Model.Media; using WatchIt.Common.Model.Movies; +using WatchIt.Common.Model.Photos; using WatchIt.Common.Model.Series; using WatchIt.Website.Services.Utility.Authentication; using WatchIt.Website.Services.WebAPI.Media; @@ -42,7 +43,7 @@ public partial class MediaPage : ComponentBase private User? _user; - private MediaPhotoResponse? _background; + private PhotoResponse? _background; private MediaPosterResponse? _poster; private IEnumerable _genres; private MediaRatingResponse _globalRating; @@ -83,8 +84,8 @@ public partial class MediaPage : ComponentBase endTasks.AddRange( [ MediaWebAPIService.PostMediaView(Id), - MediaWebAPIService.GetPhotoMediaRandomBackground(Id, data => _background = data), - MediaWebAPIService.GetPoster(Id, data => _poster = data), + MediaWebAPIService.GetMediaPhotoRandomBackground(Id, data => _background = data), + MediaWebAPIService.GetMediaPoster(Id, data => _poster = data), MediaWebAPIService.GetMediaGenres(Id, data => _genres = data), MediaWebAPIService.GetMediaRating(Id, data => _globalRating = data), _media.Type == MediaType.Movie ? MoviesWebAPIService.GetMovie(Id, data => _movie = data) : SeriesWebAPIService.GetSeries(Id, data => _series = data), diff --git a/WatchIt.Website/WatchIt.Website/Program.cs b/WatchIt.Website/WatchIt.Website/Program.cs index 133fc07..ee79676 100644 --- a/WatchIt.Website/WatchIt.Website/Program.cs +++ b/WatchIt.Website/WatchIt.Website/Program.cs @@ -8,6 +8,7 @@ using WatchIt.Website.Services.Utility.Tokens; using WatchIt.Website.Services.WebAPI.Accounts; using WatchIt.Website.Services.WebAPI.Media; using WatchIt.Website.Services.WebAPI.Movies; +using WatchIt.Website.Services.WebAPI.Photos; using WatchIt.Website.Services.WebAPI.Series; namespace WatchIt.Website; @@ -64,6 +65,7 @@ public static class Program builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); + builder.Services.AddSingleton(); return builder; } diff --git a/WatchIt.Website/WatchIt.Website/WatchIt.Website.csproj b/WatchIt.Website/WatchIt.Website/WatchIt.Website.csproj index 7dbaed0..0722800 100644 --- a/WatchIt.Website/WatchIt.Website/WatchIt.Website.csproj +++ b/WatchIt.Website/WatchIt.Website/WatchIt.Website.csproj @@ -22,6 +22,7 @@ + diff --git a/WatchIt.Website/WatchIt.Website/appsettings.json b/WatchIt.Website/WatchIt.Website/appsettings.json index 1cc3e65..02e7c38 100644 --- a/WatchIt.Website/WatchIt.Website/appsettings.json +++ b/WatchIt.Website/WatchIt.Website/appsettings.json @@ -30,26 +30,21 @@ }, "Media": { "Base": "/media", - "Get": "/{0}", - "GetGenres": "/{0}/genres", - "PostGenre": "/{0}/genres/{1}", - "DeleteGenre": "/{0}/genres/{1}", + "GetMedia": "/{0}", + "GetMediaGenres": "/{0}/genres", + "PostMediaGenre": "/{0}/genres/{1}", + "DeleteMediaGenre": "/{0}/genres/{1}", "GetMediaRating": "/{0}/rating", "GetMediaRatingByUser": "/{0}/rating/{1}", "PutMediaRating": "/{0}/rating", "DeleteMediaRating": "/{0}/rating", "PostMediaView": "/{0}/view", - - "GetPhotoMediaRandomBackground": "/{0}/photos/random_background", - "GetPoster": "/{0}/poster", - "PutPoster": "/{0}/poster", - "DeletePoster": "/{0}/poster", - "GetPhoto": "/photos/{0}", - "GetPhotos": "/photos", - "GetPhotoRandomBackground": "/photos/random_background", - "PostPhoto": "/photos", - "PutPhoto": "/photos/{0}", - "DeletePhoto": "/photos/{0}" + "GetMediaPoster": "/{0}/poster", + "PutMediaPoster": "/{0}/poster", + "DeleteMediaPoster": "/{0}/poster", + "GetMediaPhotos": "/{0}/photos", + "GetMediaPhotoRandomBackground": "/{0}/photos/random_background", + "PostMediaPhoto": "/{0}/photos" }, "Movies": { "Base": "/movies", @@ -68,6 +63,13 @@ "PutSeries": "/{0}", "DeleteSeries": "/{0}", "GetSeriesViewRank": "/view" + }, + "Photos": { + "Base": "/photos", + "GetPhotoRandomBackground": "/random_background", + "DeletePhoto": "/{0}", + "PutPhotoBackgroundData": "/{0}/background_data", + "DeletePhotoBackgroundData": "/{0}/background_data" } } } diff --git a/WatchIt.sln b/WatchIt.sln index d94dd47..07a0606 100644 --- a/WatchIt.sln +++ b/WatchIt.sln @@ -84,6 +84,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WatchIt.WebAPI.Services.Con EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WatchIt.Website.Services.WebAPI.Series", "WatchIt.Website\WatchIt.Website.Services\WatchIt.Website.Services.WebAPI\WatchIt.Website.Services.WebAPI.Series\WatchIt.Website.Services.WebAPI.Series.csproj", "{783C743A-85BF-4382-BFE5-7A90E3F3B8B6}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WatchIt.WebAPI.Services.Controllers.Photos", "WatchIt.WebAPI\WatchIt.WebAPI.Services\WatchIt.WebAPI.Services.Controllers\WatchIt.WebAPI.Services.Controllers.Photos\WatchIt.WebAPI.Services.Controllers.Photos.csproj", "{ABDF8471-2FAB-4930-B016-7DD3E48AE6B8}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WatchIt.Website.Services.WebAPI.Photos", "WatchIt.Website\WatchIt.Website.Services\WatchIt.Website.Services.WebAPI\WatchIt.Website.Services.WebAPI.Photos\WatchIt.Website.Services.WebAPI.Photos.csproj", "{960A833F-C195-4D1D-AD4F-D00B57067181}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -128,6 +132,8 @@ Global {8720AECA-7084-429A-BA15-49B6622C1A32} = {130BC8F5-82CE-4EDF-AECB-21594DD41849} {F8FCEF7B-72EA-48BC-AC68-E11244B067DD} = {CEC468DB-CC49-47D3-9E3E-1CC9530C3CE7} {783C743A-85BF-4382-BFE5-7A90E3F3B8B6} = {46E3711F-18BD-4004-AF53-EA4D8643D92F} + {ABDF8471-2FAB-4930-B016-7DD3E48AE6B8} = {CEC468DB-CC49-47D3-9E3E-1CC9530C3CE7} + {960A833F-C195-4D1D-AD4F-D00B57067181} = {46E3711F-18BD-4004-AF53-EA4D8643D92F} EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {23383776-1F27-4B5D-8C7C-57BFF75FA473}.Debug|Any CPU.ActiveCfg = Debug|Any CPU @@ -250,5 +256,13 @@ Global {783C743A-85BF-4382-BFE5-7A90E3F3B8B6}.Debug|Any CPU.Build.0 = Debug|Any CPU {783C743A-85BF-4382-BFE5-7A90E3F3B8B6}.Release|Any CPU.ActiveCfg = Release|Any CPU {783C743A-85BF-4382-BFE5-7A90E3F3B8B6}.Release|Any CPU.Build.0 = Release|Any CPU + {ABDF8471-2FAB-4930-B016-7DD3E48AE6B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ABDF8471-2FAB-4930-B016-7DD3E48AE6B8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ABDF8471-2FAB-4930-B016-7DD3E48AE6B8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {ABDF8471-2FAB-4930-B016-7DD3E48AE6B8}.Release|Any CPU.Build.0 = Release|Any CPU + {960A833F-C195-4D1D-AD4F-D00B57067181}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {960A833F-C195-4D1D-AD4F-D00B57067181}.Debug|Any CPU.Build.0 = Debug|Any CPU + {960A833F-C195-4D1D-AD4F-D00B57067181}.Release|Any CPU.ActiveCfg = Release|Any CPU + {960A833F-C195-4D1D-AD4F-D00B57067181}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal