diff --git a/WatchIt.Common/WatchIt.Common.Model/Media/MediaPhotoRequest.cs b/WatchIt.Common/WatchIt.Common.Model/Media/MediaPhotoRequest.cs index 56bbb4c..5481b2a 100644 --- a/WatchIt.Common/WatchIt.Common.Model/Media/MediaPhotoRequest.cs +++ b/WatchIt.Common/WatchIt.Common.Model/Media/MediaPhotoRequest.cs @@ -1,10 +1,28 @@ -using WatchIt.Common.Model.Photos; +using System.Diagnostics.CodeAnalysis; +using WatchIt.Common.Model.Photos; using WatchIt.Database.Model.Media; namespace WatchIt.Common.Model.Media; public class MediaPhotoRequest : Photo { + #region CONSTRUCTORS + + public MediaPhotoRequest() {} + + [SetsRequiredMembers] + public MediaPhotoRequest(PhotoResponse response) + { + Image = response.Image; + MimeType = response.MimeType; + } + + #endregion + + + + #region PUBLIC METHODS + public MediaPhotoImage CreateMediaPhotoImage(long mediaId) => new MediaPhotoImage { MediaId = mediaId, @@ -19,4 +37,6 @@ public class MediaPhotoRequest : Photo FirstGradientColor = Background.FirstGradientColor, SecondGradientColor = Background.SecondGradientColor }; + + #endregion } \ 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 17397be..d87668b 100644 --- a/WatchIt.Common/WatchIt.Common.Model/Media/MediaPoster.cs +++ b/WatchIt.Common/WatchIt.Common.Model/Media/MediaPoster.cs @@ -4,9 +4,4 @@ namespace WatchIt.Common.Model.Media; public abstract class MediaPoster : Picture { - #region PUBLIC METHODS - - public override string ToString() => $"data:{MimeType};base64,{Convert.ToBase64String(Image)}"; - - #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 index 1da4817..917548b 100644 --- a/WatchIt.Common/WatchIt.Common.Model/Photos/PhotoBackgroundDataRequest.cs +++ b/WatchIt.Common/WatchIt.Common.Model/Photos/PhotoBackgroundDataRequest.cs @@ -1,9 +1,26 @@ +using System.Diagnostics.CodeAnalysis; using WatchIt.Database.Model.Media; namespace WatchIt.Common.Model.Photos; public class PhotoBackgroundDataRequest : PhotoBackgroundData { + #region CONSTRUCTORS + + public PhotoBackgroundDataRequest() {} + + [SetsRequiredMembers] + public PhotoBackgroundDataRequest(PhotoBackgroundData photoBackgroundData) + { + IsUniversalBackground = photoBackgroundData.IsUniversalBackground; + FirstGradientColor = photoBackgroundData.FirstGradientColor; + SecondGradientColor = photoBackgroundData.SecondGradientColor; + } + + #endregion + + + #region PUBLIC METHODS public MediaPhotoImageBackground CreateMediaPhotoImageBackground(Guid photoId) => new MediaPhotoImageBackground diff --git a/WatchIt.Common/WatchIt.Common.Model/Photos/PhotoQueryParameters.cs b/WatchIt.Common/WatchIt.Common.Model/Photos/PhotoQueryParameters.cs index 6e3bc5f..99145b5 100644 --- a/WatchIt.Common/WatchIt.Common.Model/Photos/PhotoQueryParameters.cs +++ b/WatchIt.Common/WatchIt.Common.Model/Photos/PhotoQueryParameters.cs @@ -38,7 +38,7 @@ public class PhotoQueryParameters : QueryParameters && TestBoolean(item.Background is not null, IsBackground) && - TestBoolean(item.Background!.IsUniversalBackground, IsUniversalBackground) + TestBoolean(item.Background is not null && item.Background.IsUniversalBackground, IsUniversalBackground) && TestComparable(item.UploadDate, UploadDate, UploadDateFrom, UploadDateTo) ); diff --git a/WatchIt.Common/WatchIt.Common.Model/Picture.cs b/WatchIt.Common/WatchIt.Common.Model/Picture.cs index a83524d..ab0e8ee 100644 --- a/WatchIt.Common/WatchIt.Common.Model/Picture.cs +++ b/WatchIt.Common/WatchIt.Common.Model/Picture.cs @@ -13,4 +13,12 @@ public abstract class Picture public required string MimeType { get; set; } #endregion + + + + #region PUBLIC METHODS + + public override string ToString() => $"data:{MimeType};base64,{Convert.ToBase64String(Image)}"; + + #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 index 1318c7d..1b9316a 100644 --- a/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/PhotosController.cs +++ b/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/PhotosController.cs @@ -55,6 +55,7 @@ public class PhotosController : ControllerBase [HttpPut("{id}/background_data")] [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] [ProducesResponseType(typeof(void), StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status400BadRequest)] [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] [ProducesResponseType(typeof(void), StatusCodes.Status403Forbidden)] [ProducesResponseType(StatusCodes.Status404NotFound)] 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 d6cf3aa..47bec77 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 @@ -241,7 +241,10 @@ public class MediaWebAPIService : BaseWebAPIService, IMediaWebAPIService { string url = GetUrl(EndpointsConfiguration.Media.PostMediaPhoto, mediaId); - HttpRequest request = new HttpRequest(HttpMethodType.Post, url); + HttpRequest request = new HttpRequest(HttpMethodType.Post, url) + { + Body = data + }; HttpResponse response = await _httpClientService.SendRequestAsync(request); response.RegisterActionFor2XXSuccess(successAction) 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 index efc83d9..560574b 100644 --- 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 @@ -5,7 +5,7 @@ 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); + 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>? badRequestAction = 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 index 2c149c5..3ca5a1d 100644 --- 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 @@ -42,7 +42,7 @@ public class PhotosWebAPIService : BaseWebAPIService, IPhotosWebAPIService .ExecuteAction(); } - public async Task DeletePhoto(Guid id, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null, Action? notFoundAction = null) + 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); @@ -60,7 +60,7 @@ public class PhotosWebAPIService : BaseWebAPIService, IPhotosWebAPIService #region Background data - public async Task PutPhotoBackgroundData(Guid id, PhotoBackgroundDataRequest data, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null, Action? notFoundAction = null) + public async Task PutPhotoBackgroundData(Guid id, PhotoBackgroundDataRequest data, Action? successAction = null, Action>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null, Action? notFoundAction = null) { string url = GetUrl(EndpointsConfiguration.Photos.PutPhotoBackgroundData, id); @@ -71,13 +71,14 @@ public class PhotosWebAPIService : BaseWebAPIService, IPhotosWebAPIService HttpResponse response = await _httpClientService.SendRequestAsync(request); response.RegisterActionFor2XXSuccess(successAction) + .RegisterActionFor400BadRequest(badRequestAction) .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) + 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); diff --git a/WatchIt.Website/WatchIt.Website/App.razor b/WatchIt.Website/WatchIt.Website/App.razor index 0e62374..b7ea5bd 100644 --- a/WatchIt.Website/WatchIt.Website/App.razor +++ b/WatchIt.Website/WatchIt.Website/App.razor @@ -9,8 +9,8 @@ - - + + diff --git a/WatchIt.Website/WatchIt.Website/Pages/MediaEditPage.razor b/WatchIt.Website/WatchIt.Website/Pages/MediaEditPage.razor index 5f4e437..616d826 100644 --- a/WatchIt.Website/WatchIt.Website/Pages/MediaEditPage.razor +++ b/WatchIt.Website/WatchIt.Website/Pages/MediaEditPage.razor @@ -1,4 +1,6 @@ -@using WatchIt.Common.Model.Movies +@using Microsoft.IdentityModel.Tokens +@using WatchIt.Common.Model.Movies +@using WatchIt.Common.Model.Photos @using WatchIt.Common.Model.Series @page "/media/{id:long}/edit" @@ -197,6 +199,166 @@ +
+
+
+
+
+
+
+

Photos

+
+
+
+ @if (!_photoEditMode) + { + + } + else + { +
+ @if (!string.IsNullOrWhiteSpace(_photoEditError)) + { +
+ @_photoEditError +
+ } + + +
+ } +
+
+
+
+ @if (!_photoEditMode) + { + if (!_photos.IsNullOrEmpty()) + { +
+ @foreach (PhotoResponse photo in _photos) + { +
+
+
+ photo +
+
+
+ @if (photo.Background is not null) + { +
+
+
+ background_icon +
+
+
+ } +
+
+ Upload: @(photo.UploadDate.ToString()) +
+
+
+ +
+
+ +
+
+
+ } +
+ } + else + { +
+ Photo list is empty +
+ } + } + else + { +
+
+
+
+
+
+ edit_photo +
+
+ @if (_photoEditId is null) + { +
+
+ +
+
+ } +
+
+
+
+
+
+
+ + +
+
+
+
+ + +
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+
+ } +
+
+
+
+
+
} else { @@ -220,7 +382,7 @@ {