From 26a5e1e5587ae75e619c02305392c173eec5af8e Mon Sep 17 00:00:00 2001 From: Mateusz Skoczek Date: Tue, 5 Nov 2024 20:04:15 +0100 Subject: [PATCH] profile editing finished --- .../AccountProfileBackgroundRequest.cs | 24 ++++ .../AccountsController.cs | 33 +++++ .../AccountsControllerService.cs | 56 ++++++++ .../IAccountsControllerService.cs | 3 + ...ccountProfileBackgroundRequestValidator.cs | 14 ++ .../Accounts/AccountsClientService.cs | 41 ++++++ .../Accounts/IAccountsClientService.cs | 4 + .../Model/Accounts.cs | 3 + WatchIt.Website/WatchIt.Website/App.razor | 2 +- ...rofileBackgroundEditorPanelComponent.razor | 122 +++++++++++++++++- ...ileBackgroundEditorPanelComponent.razor.cs | 121 +++++++++++++++++ ...leBackgroundEditorPanelComponent.razor.css | 23 ++++ .../WatchIt.Website/Pages/UserEditPage.razor | 5 +- .../Pages/UserEditPage.razor.cs | 15 ++- .../WatchIt.Website/Pages/UserPage.razor | 12 +- .../WatchIt.Website/Pages/UserPage.razor.cs | 10 +- .../WatchIt.Website/appsettings.json | 3 + 17 files changed, 475 insertions(+), 16 deletions(-) create mode 100644 WatchIt.Common/WatchIt.Common.Model/Accounts/AccountProfileBackgroundRequest.cs create mode 100644 WatchIt.WebAPI/WatchIt.WebAPI.Validators/Accounts/AccountProfileBackgroundRequestValidator.cs create mode 100644 WatchIt.Website/WatchIt.Website/Components/Pages/UserEditPage/Panels/ProfileBackgroundEditorPanelComponent.razor.css diff --git a/WatchIt.Common/WatchIt.Common.Model/Accounts/AccountProfileBackgroundRequest.cs b/WatchIt.Common/WatchIt.Common.Model/Accounts/AccountProfileBackgroundRequest.cs new file mode 100644 index 0000000..4bcb781 --- /dev/null +++ b/WatchIt.Common/WatchIt.Common.Model/Accounts/AccountProfileBackgroundRequest.cs @@ -0,0 +1,24 @@ +using System.Diagnostics.CodeAnalysis; + +namespace WatchIt.Common.Model.Accounts; + +public class AccountProfileBackgroundRequest +{ + #region PROPERTIES + + public required Guid Id { get; set; } + + #endregion + + + + #region CONSTRUCTORS + + [SetsRequiredMembers] + public AccountProfileBackgroundRequest(Guid id) + { + Id = id; + } + + #endregion +} \ No newline at end of file diff --git a/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/AccountsController.cs b/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/AccountsController.cs index 02fa953..714d4e4 100644 --- a/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/AccountsController.cs +++ b/WatchIt.WebAPI/WatchIt.WebAPI.Controllers/AccountsController.cs @@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Mvc; using WatchIt.Common.Model.Accounts; using WatchIt.Common.Model.Movies; using WatchIt.Common.Model.Persons; +using WatchIt.Common.Model.Photos; using WatchIt.Common.Model.Series; using WatchIt.WebAPI.Services.Controllers.Accounts; @@ -14,6 +15,8 @@ namespace WatchIt.WebAPI.Controllers; [Route("accounts")] public class AccountsController(IAccountsControllerService accountsControllerService) : ControllerBase { + #region Basic + [HttpPost("register")] [AllowAnonymous] [ProducesResponseType(typeof(RegisterResponse), StatusCodes.Status201Created)] @@ -39,6 +42,10 @@ public class AccountsController(IAccountsControllerService accountsControllerSer [ProducesResponseType(typeof(void), StatusCodes.Status204NoContent)] public async Task Logout() => await accountsControllerService.Logout(); + #endregion + + #region Profile picture + [HttpGet("{id}/profile_picture")] [AllowAnonymous] [ProducesResponseType(typeof(AccountProfilePictureResponse), StatusCodes.Status200OK)] @@ -59,6 +66,32 @@ public class AccountsController(IAccountsControllerService accountsControllerSer [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] public async Task DeleteAccountProfilePicture() => await accountsControllerService.DeleteAccountProfilePicture(); + #endregion + + #region Profile background + + [HttpGet("{id}/profile_background")] + [AllowAnonymous] + [ProducesResponseType(typeof(PhotoResponse), StatusCodes.Status200OK)] + [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] + [ProducesResponseType(StatusCodes.Status404NotFound)] + public async Task GetAccountProfileBackground([FromRoute(Name = "id")]long id) => await accountsControllerService.GetAccountProfileBackground(id); + + [HttpPut("profile_background")] + [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] + [ProducesResponseType(typeof(PhotoResponse), StatusCodes.Status200OK)] + [ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)] + [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] + public async Task PutAccountProfileBackground([FromBody]AccountProfileBackgroundRequest body) => await accountsControllerService.PutAccountProfileBackground(body); + + [HttpDelete("profile_background")] + [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] + [ProducesResponseType(typeof(void), StatusCodes.Status204NoContent)] + [ProducesResponseType(typeof(void), StatusCodes.Status401Unauthorized)] + public async Task DeleteAccountProfileBackground() => await accountsControllerService.DeleteAccountProfileBackground(); + + #endregion + [HttpGet("{id}/info")] [AllowAnonymous] [ProducesResponseType(typeof(AccountResponse), StatusCodes.Status200OK)] diff --git a/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Accounts/AccountsControllerService.cs b/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Accounts/AccountsControllerService.cs index da1d7a9..e4a6879 100644 --- a/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Accounts/AccountsControllerService.cs +++ b/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Accounts/AccountsControllerService.cs @@ -8,6 +8,7 @@ using WatchIt.Common.Model.Accounts; using WatchIt.Common.Model.Media; using WatchIt.Common.Model.Movies; using WatchIt.Common.Model.Persons; +using WatchIt.Common.Model.Photos; using WatchIt.Common.Model.Series; using WatchIt.Database; using WatchIt.Database.Model.Account; @@ -32,6 +33,8 @@ public class AccountsControllerService( { #region PUBLIC METHODS + #region Basic + public async Task Register(RegisterRequest data) { string leftSalt = StringExtensions.CreateRandom(20); @@ -125,6 +128,10 @@ public class AccountsControllerService( return RequestResult.NoContent(); } + #endregion + + #region Profile picture + public async Task GetAccountProfilePicture(long id) { Account? account = await database.Accounts.FirstOrDefaultAsync(x => x.Id == id); @@ -185,6 +192,55 @@ public class AccountsControllerService( return RequestResult.NoContent(); } + #endregion + + #region Profile background + + public async Task GetAccountProfileBackground(long id) + { + Account? account = await database.Accounts.FirstOrDefaultAsync(x => x.Id == id); + if (account is null) + { + return RequestResult.BadRequest() + .AddValidationError("id", "Account with this id does not exists"); + } + + if (account.BackgroundPicture is null) + { + return RequestResult.NotFound(); + } + + PhotoResponse response = new PhotoResponse(account.BackgroundPicture); + return RequestResult.Ok(response); + } + + public async Task PutAccountProfileBackground(AccountProfileBackgroundRequest data) + { + Account account = await database.Accounts.FirstAsync(x => x.Id == userService.GetUserId()); + + account.BackgroundPictureId = data.Id; + + await database.SaveChangesAsync(); + + PhotoResponse returnData = new PhotoResponse(account.BackgroundPicture!); + return RequestResult.Ok(returnData); + } + + public async Task DeleteAccountProfileBackground() + { + Account account = await database.Accounts.FirstAsync(x => x.Id == userService.GetUserId()); + + if (account.BackgroundPicture is not null) + { + account.BackgroundPictureId = null; + await database.SaveChangesAsync(); + } + + return RequestResult.NoContent(); + } + + #endregion + public async Task GetAccountInfo(long id) { Account? account = await database.Accounts.FirstOrDefaultAsync(x => x.Id == id); diff --git a/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Accounts/IAccountsControllerService.cs b/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Accounts/IAccountsControllerService.cs index 4fb51a0..5213ab4 100644 --- a/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Accounts/IAccountsControllerService.cs +++ b/WatchIt.WebAPI/WatchIt.WebAPI.Services/WatchIt.WebAPI.Services.Controllers/WatchIt.WebAPI.Services.Controllers.Accounts/IAccountsControllerService.cs @@ -16,6 +16,9 @@ public interface IAccountsControllerService Task GetAccountProfilePicture(long id); Task PutAccountProfilePicture(AccountProfilePictureRequest data); Task DeleteAccountProfilePicture(); + Task GetAccountProfileBackground(long id); + Task PutAccountProfileBackground(AccountProfileBackgroundRequest data); + Task DeleteAccountProfileBackground(); Task GetAccountInfo(long id); Task PutAccountProfileInfo(AccountProfileInfoRequest data); Task GetAccountRatedMovies(long id, MovieRatedQueryParameters query); diff --git a/WatchIt.WebAPI/WatchIt.WebAPI.Validators/Accounts/AccountProfileBackgroundRequestValidator.cs b/WatchIt.WebAPI/WatchIt.WebAPI.Validators/Accounts/AccountProfileBackgroundRequestValidator.cs new file mode 100644 index 0000000..205be53 --- /dev/null +++ b/WatchIt.WebAPI/WatchIt.WebAPI.Validators/Accounts/AccountProfileBackgroundRequestValidator.cs @@ -0,0 +1,14 @@ +using FluentValidation; +using WatchIt.Common.Model.Accounts; +using WatchIt.Database; + +namespace WatchIt.WebAPI.Validators.Accounts; + +public class AccountProfileBackgroundRequestValidator : AbstractValidator +{ + public AccountProfileBackgroundRequestValidator(DatabaseContext database) + { + RuleFor(x => x.Id).MustBeIn(database.MediaPhotoImages.Where(x => x.MediaPhotoImageBackground != null), x => x.Id) + .WithMessage("Image has to be background"); + } +} \ No newline at end of file diff --git a/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.Client/Accounts/AccountsClientService.cs b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.Client/Accounts/AccountsClientService.cs index 4438636..1dab7b6 100644 --- a/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.Client/Accounts/AccountsClientService.cs +++ b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.Client/Accounts/AccountsClientService.cs @@ -1,6 +1,7 @@ using WatchIt.Common.Model.Accounts; using WatchIt.Common.Model.Movies; using WatchIt.Common.Model.Persons; +using WatchIt.Common.Model.Photos; using WatchIt.Common.Model.Series; using WatchIt.Common.Services.HttpClient; using WatchIt.Website.Services.Configuration; @@ -108,6 +109,46 @@ public class AccountsClientService(IHttpClientService httpClientService, IConfig .RegisterActionFor401Unauthorized(unauthorizedAction) .ExecuteAction(); } + + public async Task GetAccountProfileBackground(long id, Action? successAction = null, Action>? badRequestAction = null, Action? notFoundAction = null) + { + string url = GetUrl(EndpointsConfiguration.Accounts.GetAccountProfileBackground, id); + HttpRequest request = new HttpRequest(HttpMethodType.Get, url); + + HttpResponse response = await httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .RegisterActionFor400BadRequest(badRequestAction) + .RegisterActionFor404NotFound(notFoundAction) + .ExecuteAction(); + } + + public async Task PutAccountProfileBackground(AccountProfileBackgroundRequest data, Action? successAction = null, Action>? badRequestAction = null, Action? unauthorizedAction = null) + { + string url = GetUrl(EndpointsConfiguration.Accounts.PutAccountProfileBackground); + + HttpRequest request = new HttpRequest(HttpMethodType.Put, url) + { + Body = data + }; + + HttpResponse response = await httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .RegisterActionFor400BadRequest(badRequestAction) + .RegisterActionFor401Unauthorized(unauthorizedAction) + .ExecuteAction(); + } + + public async Task DeleteAccountProfileBackground(Action? successAction = null, Action? unauthorizedAction = null) + { + string url = GetUrl(EndpointsConfiguration.Accounts.DeleteAccountProfileBackground); + + HttpRequest request = new HttpRequest(HttpMethodType.Delete, url); + + HttpResponse response = await httpClientService.SendRequestAsync(request); + response.RegisterActionFor2XXSuccess(successAction) + .RegisterActionFor401Unauthorized(unauthorizedAction) + .ExecuteAction(); + } public async Task GetAccountInfo(long id, Action? successAction = null, Action? notFoundAction = null) { diff --git a/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.Client/Accounts/IAccountsClientService.cs b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.Client/Accounts/IAccountsClientService.cs index bb45c37..48110fe 100644 --- a/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.Client/Accounts/IAccountsClientService.cs +++ b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.Client/Accounts/IAccountsClientService.cs @@ -1,6 +1,7 @@ using WatchIt.Common.Model.Accounts; using WatchIt.Common.Model.Movies; using WatchIt.Common.Model.Persons; +using WatchIt.Common.Model.Photos; using WatchIt.Common.Model.Series; namespace WatchIt.Website.Services.Client.Accounts; @@ -14,6 +15,9 @@ public interface IAccountsClientService Task GetAccountProfilePicture(long id, Action? successAction = null, Action>? badRequestAction = null, Action? notFoundAction = null); Task PutAccountProfilePicture(AccountProfilePictureRequest data, Action? successAction = null, Action>? badRequestAction = null, Action? unauthorizedAction = null); Task DeleteAccountProfilePicture(Action? successAction = null, Action? unauthorizedAction = null); + Task GetAccountProfileBackground(long id, Action? successAction = null, Action>? badRequestAction = null, Action? notFoundAction = null); + Task PutAccountProfileBackground(AccountProfileBackgroundRequest data, Action? successAction = null, Action>? badRequestAction = null, Action? unauthorizedAction = null); + Task DeleteAccountProfileBackground(Action? successAction = null, Action? unauthorizedAction = null); Task GetAccountInfo(long id, Action? successAction = null, Action? notFoundAction = null); Task PutAccountProfileInfo(AccountProfileInfoRequest data, Action? successAction = null, Action>? badRequestAction = null, Action? unauthorizedAction = null); Task GetAccountRatedMovies(long id, MovieRatedQueryParameters query, Action>? successAction = null, Action? notFoundAction = null); diff --git a/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.Configuration/Model/Accounts.cs b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.Configuration/Model/Accounts.cs index 02ac602..f035f6d 100644 --- a/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.Configuration/Model/Accounts.cs +++ b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.Configuration/Model/Accounts.cs @@ -10,6 +10,9 @@ public class Accounts public string GetAccountProfilePicture { get; set; } public string PutAccountProfilePicture { get; set; } public string DeleteAccountProfilePicture { get; set; } + public string GetAccountProfileBackground { get; set; } + public string PutAccountProfileBackground { get; set; } + public string DeleteAccountProfileBackground { get; set; } public string GetAccountInfo { get; set; } public string PutAccountProfileInfo { get; set; } public string GetAccountRatedMovies { get; set; } diff --git a/WatchIt.Website/WatchIt.Website/App.razor b/WatchIt.Website/WatchIt.Website/App.razor index 66ac768..f460abd 100644 --- a/WatchIt.Website/WatchIt.Website/App.razor +++ b/WatchIt.Website/WatchIt.Website/App.razor @@ -13,7 +13,7 @@ - + diff --git a/WatchIt.Website/WatchIt.Website/Components/Pages/UserEditPage/Panels/ProfileBackgroundEditorPanelComponent.razor b/WatchIt.Website/WatchIt.Website/Components/Pages/UserEditPage/Panels/ProfileBackgroundEditorPanelComponent.razor index 8d8a88c..0a2e598 100644 --- a/WatchIt.Website/WatchIt.Website/Components/Pages/UserEditPage/Panels/ProfileBackgroundEditorPanelComponent.razor +++ b/WatchIt.Website/WatchIt.Website/Components/Pages/UserEditPage/Panels/ProfileBackgroundEditorPanelComponent.razor @@ -1,5 +1,121 @@ +@using Blazorise.Components +@using WatchIt.Common.Model.Photos + + +
-
-

Profile background

-
+ @if (_loaded) + { +
+
+

Profile background

+ @if (_editMode) + { + + } + else + { + + + } +
+ @if (_editMode) + { +
+
+
+
+ + Sorry... @not_found_context was not found + +
+
+ +
+
+
+ @if (_mediaPhotos is null) + { + Select media first + } + else if (!_mediaPhotos.Any()) + { + No backgrounds for this media + } + else + { +
+ @foreach (PhotoResponse photo in _mediaPhotos) + { +
+
+
+
+ +
+
+
+
+
+
+
+ +
+
+
+
+ } +
+ } +
+ } + else + { + if (_selectedPhoto is not null) + { + + } + else + { + You don't have selected background. Click "Edit" to choose one. + } + } +
+ } + else + { + + }
\ No newline at end of file diff --git a/WatchIt.Website/WatchIt.Website/Components/Pages/UserEditPage/Panels/ProfileBackgroundEditorPanelComponent.razor.cs b/WatchIt.Website/WatchIt.Website/Components/Pages/UserEditPage/Panels/ProfileBackgroundEditorPanelComponent.razor.cs index 904e6a4..594ba75 100644 --- a/WatchIt.Website/WatchIt.Website/Components/Pages/UserEditPage/Panels/ProfileBackgroundEditorPanelComponent.razor.cs +++ b/WatchIt.Website/WatchIt.Website/Components/Pages/UserEditPage/Panels/ProfileBackgroundEditorPanelComponent.razor.cs @@ -1,7 +1,128 @@ using Microsoft.AspNetCore.Components; +using WatchIt.Common.Model.Accounts; +using WatchIt.Common.Model.Media; +using WatchIt.Common.Model.Photos; +using WatchIt.Website.Services.Authentication; +using WatchIt.Website.Services.Client.Accounts; +using WatchIt.Website.Services.Client.Media; namespace WatchIt.Website.Components.Pages.UserEditPage.Panels; public partial class ProfileBackgroundEditorPanelComponent : ComponentBase { + #region SERVICES + + [Inject] private IMediaClientService MediaClientService { get; set; } = default!; + [Inject] private IAccountsClientService AccountsClientService { get; set; } = default!; + + #endregion + + + + #region PARAMETERS + + [Parameter] public required long Id { get; set; } + [Parameter] public Action? OnBackgroundChanged { get; set; } + + #endregion + + + + #region FIELDS + + private bool _loaded; + + private bool _editMode; + private long? _selectedMedia; + private IEnumerable? _mediaPhotos; + private bool _backgroundsLoading; + private bool _saveLoading; + + private bool _removeLoading; + + private IEnumerable _mediaList = default!; + + private PhotoResponse? _selectedPhoto; + private MediaResponse? _selectedPhotoMedia; + + #endregion + + + + #region PRIVATE METHODS + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + { + await Task.WhenAll( + [ + MediaClientService.GetAllMedia(successAction: data => _mediaList = data), + AccountsClientService.GetAccountProfileBackground(Id, data => _selectedPhoto = data) + ]); + + if (_selectedPhoto is not null) + { + _selectedPhotoMedia = _mediaList.First(x => x.Id == _selectedPhoto.MediaId); + } + + _loaded = true; + StateHasChanged(); + } + } + + private async Task Save(Guid id) + { + _saveLoading = true; + await AccountsClientService.PutAccountProfileBackground(new AccountProfileBackgroundRequest(id), data => + { + OnBackgroundChanged?.Invoke(data); + _selectedPhoto = data; + _selectedPhotoMedia = _mediaList.First(x => x.Id == _selectedMedia!.Value); + _saveLoading = false; + Cancel(); + }); + } + + private void Cancel() + { + _editMode = false; + _selectedMedia = default; + _saveLoading = false; + _backgroundsLoading = false; + _mediaPhotos = default; + } + + private void Edit() + { + _editMode = true; + } + + private async Task Remove() + { + _removeLoading = true; + await AccountsClientService.DeleteAccountProfileBackground(() => + { + OnBackgroundChanged?.Invoke(null); + _selectedPhoto = null; + _selectedPhotoMedia = null; + _removeLoading = false; + }); + } + + private async Task LoadBackgrounds() + { + _backgroundsLoading = true; + PhotoQueryParameters query = new PhotoQueryParameters + { + IsBackground = true + }; + await MediaClientService.GetMediaPhotos(_selectedMedia!.Value, query, successAction: data => + { + _mediaPhotos = data; + _backgroundsLoading = false; + }); + } + + #endregion } \ No newline at end of file diff --git a/WatchIt.Website/WatchIt.Website/Components/Pages/UserEditPage/Panels/ProfileBackgroundEditorPanelComponent.razor.css b/WatchIt.Website/WatchIt.Website/Components/Pages/UserEditPage/Panels/ProfileBackgroundEditorPanelComponent.razor.css new file mode 100644 index 0000000..910ae4d --- /dev/null +++ b/WatchIt.Website/WatchIt.Website/Components/Pages/UserEditPage/Panels/ProfileBackgroundEditorPanelComponent.razor.css @@ -0,0 +1,23 @@ +/* IDS */ + +#scrollPhotos { + overflow-x: scroll; + + border-color: grey; + border-width: 1px; + border-style: solid; + border-radius: 10px; +} + +#backgroundIndicator { + height: 30px; + width: 30px; +} + + + +/* CLASSES */ + +.photo-container { + width: 350px; +} \ No newline at end of file diff --git a/WatchIt.Website/WatchIt.Website/Pages/UserEditPage.razor b/WatchIt.Website/WatchIt.Website/Pages/UserEditPage.razor index 8031ff4..ae3c2c8 100644 --- a/WatchIt.Website/WatchIt.Website/Pages/UserEditPage.razor +++ b/WatchIt.Website/WatchIt.Website/Pages/UserEditPage.razor @@ -1,7 +1,9 @@ @using System.Text @using WatchIt.Common.Model +@using WatchIt.Common.Model.Photos @using WatchIt.Website.Components.Pages.UserEditPage.Panels + @page "/user/edit" @{ @@ -60,7 +62,8 @@
- +
diff --git a/WatchIt.Website/WatchIt.Website/Pages/UserEditPage.razor.cs b/WatchIt.Website/WatchIt.Website/Pages/UserEditPage.razor.cs index b3ada08..8e4c5ea 100644 --- a/WatchIt.Website/WatchIt.Website/Pages/UserEditPage.razor.cs +++ b/WatchIt.Website/WatchIt.Website/Pages/UserEditPage.razor.cs @@ -1,6 +1,7 @@ using System.Net; using Microsoft.AspNetCore.Components; using WatchIt.Common.Model; +using WatchIt.Common.Model.Photos; using WatchIt.Website.Components.Pages.UserEditPage.Panels; using WatchIt.Website.Layout; using WatchIt.Website.Services.Authentication; @@ -50,11 +51,12 @@ public partial class UserEditPage : ComponentBase if (_user is null) { NavigationManager.NavigateTo($"/auth?redirect_to={WebUtility.UrlEncode("/user/edit")}"); + return; } - else - { - StateHasChanged(); - } + StateHasChanged(); + + await AccountsClientService.GetAccountProfileBackground(_user.Id, data => Layout.BackgroundPhoto = data); + StateHasChanged(); } } @@ -63,6 +65,11 @@ public partial class UserEditPage : ComponentBase _header.ReloadPicture(), Layout.ReloadProfilePicture() ]); + + private void BackgroundChanged(PhotoResponse? background) + { + Layout.BackgroundPhoto = background; + } #endregion } \ No newline at end of file diff --git a/WatchIt.Website/WatchIt.Website/Pages/UserPage.razor b/WatchIt.Website/WatchIt.Website/Pages/UserPage.razor index ff65c65..722e501 100644 --- a/WatchIt.Website/WatchIt.Website/Pages/UserPage.razor +++ b/WatchIt.Website/WatchIt.Website/Pages/UserPage.razor @@ -69,7 +69,7 @@ step1Tasks = new List(); List endTasks = new List(); // INIT Layout.BackgroundPhoto = null; // STEP 0 - endTasks.AddRange( + step1Tasks.AddRange( [ GetUserData() ]); + // STEP 1 + await Task.WhenAll(step1Tasks); + endTasks.AddRange( + [ + AccountsClientService.GetAccountProfileBackground(_accountData.Id, data => Layout.BackgroundPhoto = data) + ]); + // END await Task.WhenAll(endTasks); diff --git a/WatchIt.Website/WatchIt.Website/appsettings.json b/WatchIt.Website/WatchIt.Website/appsettings.json index 2d4a0f1..b6820ca 100644 --- a/WatchIt.Website/WatchIt.Website/appsettings.json +++ b/WatchIt.Website/WatchIt.Website/appsettings.json @@ -24,6 +24,9 @@ "GetAccountProfilePicture": "/{0}/profile_picture", "PutAccountProfilePicture": "/profile_picture", "DeleteAccountProfilePicture": "/profile_picture", + "GetAccountProfileBackground": "/{0}/profile_background", + "PutAccountProfileBackground": "/profile_background", + "DeleteAccountProfileBackground": "/profile_background", "GetAccountInfo": "/{0}/info", "PutAccountProfileInfo": "/profile_info", "GetAccountRatedMovies": "/{0}/movies",