following added

This commit is contained in:
2024-11-10 14:33:41 +01:00
Unverified
parent 046dc26915
commit 0bf572d844
24 changed files with 2015 additions and 90 deletions

View File

@@ -13,6 +13,36 @@ public class AccountsClientService(IHttpClientService httpClientService, IConfig
{
#region PUBLIC METHODS
#region Main
public async Task GetAccounts(AccountQueryParameters? query = null, Action<IEnumerable<AccountResponse>>? successAction = null)
{
string url = GetUrl(EndpointsConfiguration.Accounts.GetAccounts);
HttpRequest request = new HttpRequest(HttpMethodType.Get, url)
{
Query = query
};
HttpResponse response = await httpClientService.SendRequestAsync(request);
response.RegisterActionFor2XXSuccess(successAction)
.ExecuteAction();
}
public async Task GetAccount(long id, Action<AccountResponse>? successAction = null, Action? notFoundAction = null)
{
string url = GetUrl(EndpointsConfiguration.Accounts.GetAccount, id);
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
HttpResponse response = await httpClientService.SendRequestAsync(request);
response.RegisterActionFor2XXSuccess(successAction)
.RegisterActionFor404NotFound(notFoundAction)
.ExecuteAction();
}
#endregion
#region Authentication
public async Task Register(RegisterRequest data, Action<RegisterResponse>? createdAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null)
{
string url = GetUrl(EndpointsConfiguration.Accounts.Register);
@@ -69,7 +99,11 @@ public class AccountsClientService(IHttpClientService httpClientService, IConfig
response.RegisterActionFor2XXSuccess(successAction)
.ExecuteAction();
}
#endregion
#region Profile picture
public async Task GetAccountProfilePicture(long id, Action<AccountProfilePictureResponse>? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? notFoundAction = null)
{
string url = GetUrl(EndpointsConfiguration.Accounts.GetAccountProfilePicture, id);
@@ -109,7 +143,11 @@ public class AccountsClientService(IHttpClientService httpClientService, IConfig
.RegisterActionFor401Unauthorized(unauthorizedAction)
.ExecuteAction();
}
#endregion
#region Profile background
public async Task GetAccountProfileBackground(long id, Action<PhotoResponse>? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? notFoundAction = null)
{
string url = GetUrl(EndpointsConfiguration.Accounts.GetAccountProfileBackground, id);
@@ -150,29 +188,9 @@ public class AccountsClientService(IHttpClientService httpClientService, IConfig
.ExecuteAction();
}
public async Task GetAccounts(AccountQueryParameters query, Action<IEnumerable<AccountResponse>>? successAction = null)
{
string url = GetUrl(EndpointsConfiguration.Accounts.GetAccounts);
HttpRequest request = new HttpRequest(HttpMethodType.Get, url)
{
Query = query
};
HttpResponse response = await httpClientService.SendRequestAsync(request);
response.RegisterActionFor2XXSuccess(successAction)
.ExecuteAction();
}
#endregion
public async Task GetAccount(long id, Action<AccountResponse>? successAction = null, Action? notFoundAction = null)
{
string url = GetUrl(EndpointsConfiguration.Accounts.GetAccount, id);
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
HttpResponse response = await httpClientService.SendRequestAsync(request);
response.RegisterActionFor2XXSuccess(successAction)
.RegisterActionFor404NotFound(notFoundAction)
.ExecuteAction();
}
#region Account management
public async Task PutAccountProfileInfo(AccountProfileInfoRequest data, Action? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? unauthorizedAction = null)
{
@@ -234,6 +252,10 @@ public class AccountsClientService(IHttpClientService httpClientService, IConfig
.ExecuteAction();
}
#endregion
#region Media
public async Task GetAccountRatedMovies(long id, MovieRatedQueryParameters query, Action<IEnumerable<MovieRatedResponse>>? successAction = null, Action? notFoundAction = null)
{
string url = GetUrl(EndpointsConfiguration.Accounts.GetAccountRatedMovies, id);
@@ -275,6 +297,63 @@ public class AccountsClientService(IHttpClientService httpClientService, IConfig
.RegisterActionFor404NotFound(notFoundAction)
.ExecuteAction();
}
#endregion
#region Follows
public async Task GetAccountFollows(long id, AccountQueryParameters? query = null, Action<IEnumerable<AccountResponse>>? successAction = null, Action? notFoundAction = null)
{
string url = GetUrl(EndpointsConfiguration.Accounts.GetAccountFollows, id);
HttpRequest request = new HttpRequest(HttpMethodType.Get, url)
{
Query = query
};
HttpResponse response = await httpClientService.SendRequestAsync(request);
response.RegisterActionFor2XXSuccess(successAction)
.RegisterActionFor404NotFound(notFoundAction)
.ExecuteAction();
}
public async Task GetAccountFollowers(long id, AccountQueryParameters? query = null, Action<IEnumerable<AccountResponse>>? successAction = null, Action? notFoundAction = null)
{
string url = GetUrl(EndpointsConfiguration.Accounts.GetAccountFollowers, id);
HttpRequest request = new HttpRequest(HttpMethodType.Get, url)
{
Query = query
};
HttpResponse response = await httpClientService.SendRequestAsync(request);
response.RegisterActionFor2XXSuccess(successAction)
.RegisterActionFor404NotFound(notFoundAction)
.ExecuteAction();
}
public async Task PostAccountFollow(long userId, Action? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? unauthorizedAction = null)
{
string url = GetUrl(EndpointsConfiguration.Accounts.PostAccountFollow, userId);
HttpRequest request = new HttpRequest(HttpMethodType.Post, url);
HttpResponse response = await httpClientService.SendRequestAsync(request);
response.RegisterActionFor2XXSuccess(successAction)
.RegisterActionFor400BadRequest(badRequestAction)
.RegisterActionFor401Unauthorized(unauthorizedAction)
.ExecuteAction();
}
public async Task DeleteAccountFollow(long userId, Action? successAction = null, Action? unauthorizedAction = null)
{
string url = GetUrl(EndpointsConfiguration.Accounts.DeleteAccountFollow, userId);
HttpRequest request = new HttpRequest(HttpMethodType.Delete, url);
HttpResponse response = await httpClientService.SendRequestAsync(request);
response.RegisterActionFor2XXSuccess(successAction)
.RegisterActionFor401Unauthorized(unauthorizedAction)
.ExecuteAction();
}
#endregion
#endregion

View File

@@ -18,13 +18,17 @@ public interface IAccountsClientService
Task GetAccountProfileBackground(long id, Action<PhotoResponse>? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? notFoundAction = null);
Task PutAccountProfileBackground(AccountProfileBackgroundRequest data, Action<PhotoResponse>? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? unauthorizedAction = null);
Task DeleteAccountProfileBackground(Action? successAction = null, Action? unauthorizedAction = null);
Task GetAccounts(AccountQueryParameters query, Action<IEnumerable<AccountResponse>>? successAction = null);
Task GetAccounts(AccountQueryParameters? query = null, Action<IEnumerable<AccountResponse>>? successAction = null);
Task GetAccount(long id, Action<AccountResponse>? successAction = null, Action? notFoundAction = null);
Task PutAccountProfileInfo(AccountProfileInfoRequest data, Action? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? unauthorizedAction = null);
Task PatchAccountUsername(AccountUsernameRequest data, Action? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? unauthorizedAction = null);
Task PatchAccountEmail(AccountEmailRequest data, Action? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? unauthorizedAction = null);
Task PatchAccountPassword(AccountPasswordRequest data, Action? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? unauthorizedAction = null);
Task GetAccountRatedMovies(long id, MovieRatedQueryParameters query, Action<IEnumerable<MovieRatedResponse>>? successAction = null, Action? notFoundAction = null);
Task GetAccountRatedSeries(long id, SeriesRatedQueryParameters query, Action<IEnumerable<SeriesRatedResponse>>? successAction = null, Action? notFoundAction = null);
Task GetAccountRatedPersons(long id, PersonRatedQueryParameters query, Action<IEnumerable<PersonRatedResponse>>? successAction = null, Action? notFoundAction = null);
Task GetAccountRatedMovies(long id, MovieRatedQueryParameters? query = null, Action<IEnumerable<MovieRatedResponse>>? successAction = null, Action? notFoundAction = null);
Task GetAccountRatedSeries(long id, SeriesRatedQueryParameters? query = null, Action<IEnumerable<SeriesRatedResponse>>? successAction = null, Action? notFoundAction = null);
Task GetAccountRatedPersons(long id, PersonRatedQueryParameters? query = null, Action<IEnumerable<PersonRatedResponse>>? successAction = null, Action? notFoundAction = null);
Task GetAccountFollows(long id, AccountQueryParameters? query = null, Action<IEnumerable<AccountResponse>>? successAction = null, Action? notFoundAction = null);
Task GetAccountFollowers(long id, AccountQueryParameters? query = null, Action<IEnumerable<AccountResponse>>? successAction = null, Action? notFoundAction = null);
Task PostAccountFollow(long userId, Action? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? unauthorizedAction = null);
Task DeleteAccountFollow(long userId, Action? successAction = null, Action? unauthorizedAction = null);
}

View File

@@ -22,4 +22,8 @@ public class Accounts
public string GetAccountRatedMovies { get; set; }
public string GetAccountRatedSeries { get; set; }
public string GetAccountRatedPersons { get; set; }
public string GetAccountFollows { get; set; }
public string GetAccountFollowers { get; set; }
public string PostAccountFollow { get; set; }
public string DeleteAccountFollow { get; set; }
}

View File

@@ -9,7 +9,7 @@
<link rel="icon" type="image/png" href="favicon.png"/>
<!-- CSS -->
<link rel="stylesheet" href="css/general.css?version=0.3.0.5"/>
<link rel="stylesheet" href="css/general.css?version=0.5.0.0"/>
<link rel="stylesheet" href="css/panel.css?version=0.3.0.5"/>
<link rel="stylesheet" href="css/main_button.css?version=0.3.0.0"/>
<link rel="stylesheet" href="css/gaps.css?version=0.3.0.1"/>

View File

@@ -1,7 +1,7 @@
<a class="text-decoration-none text-reset" href="/user/@(Item.Id)">
<div class="d-flex align-items-center gap-4">
<AccountPictureComponent Id="@(Item.Id)"
Size="90"/>
Size="@(PictureSize)"/>
<h4 class="fw-bold">@(Item.Username)</h4>
</div>
</a>

View File

@@ -1,13 +1,14 @@
using Microsoft.AspNetCore.Components;
using WatchIt.Common.Model.Accounts;
namespace WatchIt.Website.Components.Pages.SearchPage.Subcomponents;
namespace WatchIt.Website.Components.Common.Subcomponents;
public partial class UserSearchResultItemComponent : ComponentBase
public partial class UserListItemComponent : ComponentBase
{
#region PROPERTIES
[Parameter] public required AccountResponse Item { get; set; }
[Parameter] public int PictureSize { get; set; } = 90;
#endregion
}

View File

@@ -1,5 +1,4 @@
@using Blazorise.Extensions
@using WatchIt.Website.Components.Pages.SearchPage.Subcomponents
@@ -29,7 +28,7 @@
@{
int iCopy = i;
}
<UserSearchResultItemComponent Item="@(_items[iCopy])"/>
<UserListItemComponent Item="@(_items[iCopy])"/>
</div>
</div>
}

View File

@@ -0,0 +1,29 @@
<div class="vstack gap-default">
<div class="panel panel-section-header">
<h3 class="fw-bold m-0">@(Title)</h3>
</div>
@if (!_loaded)
{
<div class="panel">
<LoadingComponent Color="LoadingComponent.LoadingComponentColors.Light"/>
</div>
}
else if (!_items.Any())
{
<div class="panel">
<div class="d-flex justify-content-center">
No items
</div>
</div>
}
else
{
foreach (AccountResponse item in _items)
{
<div class="panel">
<UserListItemComponent Item="item"
PictureSize="50"/>
</div>
}
}
</div>

View File

@@ -0,0 +1,41 @@
using Microsoft.AspNetCore.Components;
using WatchIt.Common.Model.Accounts;
namespace WatchIt.Website.Components.Pages.UserPage.Panels;
public partial class FollowListPanelComponent : ComponentBase
{
#region PARAMETERS
[Parameter] public required string Title { get; set; }
[Parameter] public required Func<Action<IEnumerable<AccountResponse>>, Task> DownloadItemsMethod { get; set; }
#endregion
#region FIELDS
private bool _loaded;
private List<AccountResponse> _items = [];
#endregion
#region PRIVATE METHODS
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await DownloadItemsMethod.Invoke(data => _items.AddRange(data));
_loaded = true;
StateHasChanged();
}
}
#endregion
}

View File

@@ -1,29 +1,49 @@
<div id="base" class="vstack">
<AccountPictureComponent Class="shadow position-absolute z-1 start-50 translate-middle" Id="@(AccountProfileInfoData.Id)" Size="240"/>
<AccountPictureComponent Class="shadow position-absolute z-1 start-50 translate-middle" Id="@(Data.Id)" Size="240"/>
<div class="panel z-0">
<div class="vstack gap-3">
<div id="space" class="container-grid"></div>
<div class="d-flex justify-content-center">
<h3 class="fw-bold m-0">@(AccountProfileInfoData.Username)</h3>
<h3 class="fw-bold m-0">@(Data.Username)</h3>
</div>
@if (!string.IsNullOrWhiteSpace(AccountProfileInfoData.Description))
@if (!string.IsNullOrWhiteSpace(Data.Description))
{
<span class="text-center w-100 mb-2">
@(AccountProfileInfoData.Description)
@(Data.Description)
</span>
}
<div class="d-flex flex-wrap justify-content-center metadata-pill-container">
<div class="metadata-pill"><strong>Email:</strong> @(AccountProfileInfoData.Email)</div>
@if (!string.IsNullOrWhiteSpace(AccountProfileInfoData.Gender?.Name))
<div class="metadata-pill"><strong>Email:</strong> @(Data.Email)</div>
@if (!string.IsNullOrWhiteSpace(Data.Gender?.Name))
{
<div class="metadata-pill"><strong>Gender:</strong> @(AccountProfileInfoData.Gender?.Name)</div>
<div class="metadata-pill"><strong>Gender:</strong> @(Data.Gender?.Name)</div>
}
<div class="metadata-pill"><strong>Account created:</strong> @(AccountProfileInfoData.CreationDate.ToShortDateString())</div>
<div class="metadata-pill"><strong>Last active:</strong> @(AccountProfileInfoData.LastActive.ToShortDateString())</div>
@if (AccountProfileInfoData.IsAdmin)
<div class="metadata-pill"><strong>Joined:</strong> @(Data.CreationDate.ToShortDateString())</div>
<div class="metadata-pill"><strong>Last active:</strong> @(Data.LastActive.ToShortDateString())</div>
@if (Data.IsAdmin)
{
<div class="metadata-pill"><strong>Admin</strong></div>
}
@if (LoggedUserData is not null && Data.Id != LoggedUserData.Id)
{
<div role="button" class="metadata-pill @(!_followLoading ? "metadata-pill-hoverable" : string.Empty)" @onclick="@(Follow)">
@if (_followLoading)
{
<div class="spinner-border spinner-border-sm"></div>
}
else
{
if (Followers.Any(x => x.Id == LoggedUserData.Id))
{
<span><i class="fa fa-eye-slash" aria-hidden="true"></i> Unfollow</span>
}
else
{
<span><i class="fa fa-eye" aria-hidden="true"></i> Follow</span>
}
}
</div>
}
</div>
</div>
</div>

View File

@@ -9,7 +9,6 @@ public partial class UserPageHeaderPanelComponent : ComponentBase
{
#region SERVICES
[Inject] private IAuthenticationService AuthenticationService { get; set; } = default!;
[Inject] private IAccountsClientService AccountsClientService { get; set; } = default!;
#endregion
@@ -18,38 +17,45 @@ public partial class UserPageHeaderPanelComponent : ComponentBase
#region PARAMETERS
[Parameter] public required AccountResponse AccountProfileInfoData { get; set; }
[Parameter] public required AccountResponse Data { get; set; }
[Parameter] public required List<AccountResponse> Followers { get; set; }
[Parameter] public AccountResponse? LoggedUserData { get; set; }
[Parameter] public Action<bool>? FollowingChanged { get; set; }
#endregion
#region FIELDS
private bool _followLoading;
private AccountProfilePictureResponse? _accountProfilePicture;
#endregion
#region PRIVATE METHODS
protected override async Task OnAfterRenderAsync(bool firstRender)
private async Task Follow()
{
if (firstRender)
_followLoading = true;
if (Followers.Any(x => x.Id == LoggedUserData!.Id))
{
List<Task> endTasks = new List<Task>();
// STEP 0
endTasks.AddRange(
[
AccountsClientService.GetAccountProfilePicture(AccountProfileInfoData.Id, data => _accountProfilePicture = data),
]);
// END
await Task.WhenAll(endTasks);
StateHasChanged();
await AccountsClientService.DeleteAccountFollow(Data.Id, () =>
{
Followers.RemoveAll(x => x.Id == LoggedUserData!.Id);
FollowingChanged?.Invoke(false);
_followLoading = false;
});
}
else
{
await AccountsClientService.PostAccountFollow(Data.Id, () =>
{
Followers.Add(LoggedUserData);
FollowingChanged?.Invoke(true);
_followLoading = false;
});
}
}

View File

@@ -48,10 +48,12 @@
{
<div class="row mt-header">
<div class="col">
<UserPageHeaderPanelComponent AccountProfileInfoData="@(_accountData)"/>
<UserPageHeaderPanelComponent Data="@(_accountData)"
Followers="@(_followers)"
LoggedUserData="@(_loggedUserData)"/>
</div>
</div>
<div class="row mt-over-panel-menu">
<div class="row mt-default">
<div class="col">
<Tabs Pills
RenderMode="TabsRenderMode.LazyLoad"
@@ -62,6 +64,8 @@
<Tab Name="movies">Movies</Tab>
<Tab Name="series">TV Series</Tab>
<Tab Name="people">People</Tab>
<Tab Name="follows">Follows</Tab>
<Tab Name="followers">Followers</Tab>
</Items>
<Content>
<TabPanel Name="summary">
@@ -160,22 +164,34 @@
PictureDownloadingTask="@((id, action) => PersonsClientService.GetPersonPhoto(id, action))"
ItemDownloadingTask="@((query, action) => AccountsClientService.GetAccountRatedPersons(_accountData.Id, query, action))"
SortingOptions="@(new Dictionary<string, string>
{
{ "user_rating.average", "Average user rating" },
{ "user_rating.count", "Number of user ratings" },
{ "user_rating_last_date", "User rating date" },
{ "rating.average", "Average rating" },
{ "rating.count", "Number of ratings" },
{ "name", "Name" },
{ "birth_date", "Birth date" },
{ "death_date", "Death date" },
})"
{
{ "user_rating.average", "Average user rating" },
{ "user_rating.count", "Number of user ratings" },
{ "user_rating_last_date", "User rating date" },
{ "rating.average", "Average rating" },
{ "rating.count", "Number of ratings" },
{ "name", "Name" },
{ "birth_date", "Birth date" },
{ "death_date", "Death date" },
})"
PosterPlaceholder="/assets/person_poster.png"
GetGlobalRatingMethod="@((id, action) => PersonsClientService.GetPersonGlobalRating(id, action))">
<PersonsRatedFilterFormComponent/>
</ListComponent>
</div>
</TabPanel>
<TabPanel Name="follows">
<div class="mt-default">
<FollowListPanelComponent Title="Follows"
DownloadItemsMethod="action => AccountsClientService.GetAccountFollows(_accountData.Id, successAction: action)"/>
</div>
</TabPanel>
<TabPanel Name="followers">
<div class="mt-default">
<FollowListPanelComponent Title="Followers"
DownloadItemsMethod="action => AccountsClientService.GetAccountFollowers(_accountData.Id, successAction: action)"/>
</div>
</TabPanel>
</Content>
</Tabs>
</div>

View File

@@ -38,7 +38,11 @@ public partial class UserPage : ComponentBase
private bool _loaded;
private bool _redirection;
private bool _owner;
private User? _user;
private AccountResponse? _loggedUserData;
private AccountResponse? _accountData;
private List<AccountResponse> _followers;
#endregion
@@ -66,8 +70,13 @@ public partial class UserPage : ComponentBase
await Task.WhenAll(step1Tasks);
endTasks.AddRange(
[
AccountsClientService.GetAccountProfileBackground(_accountData.Id, data => Layout.BackgroundPhoto = data)
AccountsClientService.GetAccountProfileBackground(_accountData.Id, data => Layout.BackgroundPhoto = data),
AccountsClientService.GetAccountFollowers(_accountData.Id, successAction: data => _followers = data.ToList())
]);
if (_user is not null)
{
endTasks.Add(AccountsClientService.GetAccount(_user.Id, data => _loggedUserData = data));
}
// END
await Task.WhenAll(endTasks);
@@ -79,20 +88,20 @@ public partial class UserPage : ComponentBase
private async Task GetUserData()
{
User? user = await AuthenticationService.GetUserAsync();
_user = await AuthenticationService.GetUserAsync();
if (!Id.HasValue)
{
if (user is null)
if (_user is null)
{
NavigationManager.NavigateTo($"/auth?redirect_to={WebUtility.UrlEncode("/user")}");
_redirection = true;
return;
}
Id = user.Id;
Id = _user.Id;
}
await AccountsClientService.GetAccount(Id.Value, data => _accountData = data);
_owner = Id.Value == user?.Id;
_owner = Id.Value == _user?.Id;
}

View File

@@ -35,7 +35,11 @@
"PatchAccountPassword": "/password",
"GetAccountRatedMovies": "/{0}/movies",
"GetAccountRatedSeries": "/{0}/series",
"GetAccountRatedPersons": "/{0}/persons"
"GetAccountRatedPersons": "/{0}/persons",
"GetAccountFollows": "/{0}/follows",
"GetAccountFollowers": "/{0}/followers",
"PostAccountFollow": "/follows/{0}",
"DeleteAccountFollow": "/follows/{0}"
},
"Genders": {
"Base": "/genders",

View File

@@ -66,6 +66,11 @@ body, html {
gap: 1rem;
}
.metadata-pill-hoverable:hover {
background-color: gray;
color: black;
}