media view count incrementation endpoint added, media page loading optimized, media view count incrementation on media page added

This commit is contained in:
2024-09-21 21:11:21 +02:00
Unverified
parent 6e2a38fb7c
commit 40fdc3f345
10 changed files with 112 additions and 44 deletions

View File

@@ -11,6 +11,7 @@ public class Media
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; }

View File

@@ -14,6 +14,8 @@ public interface IMediaWebAPIService
Task GetMediaRatingByUser(long mediaId, long userId, Action<short>? successAction = null, Action? notFoundAction = null);
Task PutMediaRating(long mediaId, MediaRatingRequest body, Action? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? unauthorizedAction = null, Action? notFoundAction = null);
Task DeleteMediaRating(long mediaId, Action? successAction = null, Action? unauthorizedAction = null);
Task PostMediaView(long mediaId, Action? successAction = null, Action? notFoundAction = null);
Task GetPhotoMediaRandomBackground(long mediaId, Action<MediaPhotoResponse>? successAction = null, Action? notFoundAction = null);
Task GetPhotoRandomBackground(Action<MediaPhotoResponse>? successAction = null, Action? notFoundAction = null);

View File

@@ -113,6 +113,22 @@ public class MediaWebAPIService(IHttpClientService httpClientService, IConfigura
}
#endregion
#region View count
public async Task PostMediaView(long mediaId, Action? successAction = null, Action? notFoundAction = null)
{
string url = GetUrl(EndpointsConfiguration.Media.PostMediaView, mediaId);
HttpRequest request = new HttpRequest(HttpMethodType.Post, url);
HttpResponse response = await httpClientService.SendRequestAsync(request);
response.RegisterActionFor2XXSuccess(successAction)
.RegisterActionFor404NotFound(notFoundAction)
.ExecuteAction();
}
#endregion

View File

@@ -9,7 +9,7 @@ using WatchIt.Website.Services.WebAPI.Movies;
namespace WatchIt.Website.Pages;
public partial class MediaDataPage : ComponentBase
public partial class MediaPage : ComponentBase
{
#region SERVICES
@@ -56,49 +56,49 @@ public partial class MediaDataPage : ComponentBase
{
if (firstRender)
{
await MediaWebAPIService.GetMedia(Id, data => _media = data, () => _error = $"Media with id {Id} was not found");
List<Task> step1Tasks = new List<Task>();
List<Task> step2Tasks = new List<Task>();
List<Task> endTasks = new List<Task>();
// STEP 0
step1Tasks.AddRange(
[
MediaWebAPIService.GetMedia(Id, data => _media = data, () => _error = $"Media with id {Id} was not found")
]);
// STEP 1
await Task.WhenAll(step1Tasks);
if (_error is null)
{
Task backgroundTask = MediaWebAPIService.GetPhotoMediaRandomBackground(Id, data => _background = data);
Task posterTask = MediaWebAPIService.GetPoster(Id, data => _poster = data);
Task<User?> userTask = AuthenticationService.GetUserAsync();
Task genresTask = MediaWebAPIService.GetMediaGenres(Id, data => _genres = data);
Task globalRatingTask = MediaWebAPIService.GetMediaRating(Id, data => _globalRating = data);
Task specificMediaTask;
if (_media.Type == MediaType.Movie)
{
specificMediaTask = MoviesWebAPIService.Get(Id, data => _movie = data);
}
else
{
// TODO: download tv series info
specificMediaTask = null;
}
await Task.WhenAll(
step2Tasks.AddRange(
[
userTask,
specificMediaTask,
genresTask,
globalRatingTask,
backgroundTask,
posterTask,
Task.Run(async () => _user = await AuthenticationService.GetUserAsync())
]);
_user = await userTask;
}
if (_user is not null)
{
Task userRatingTask = MediaWebAPIService.GetMediaRatingByUser(Id, _user.Id, data => _userRating = data);
await Task.WhenAll(
endTasks.AddRange(
[
userRatingTask,
MediaWebAPIService.PostMediaView(Id),
MediaWebAPIService.GetPhotoMediaRandomBackground(Id, data => _background = data),
MediaWebAPIService.GetPoster(Id, data => _poster = data),
MediaWebAPIService.GetMediaGenres(Id, data => _genres = data),
MediaWebAPIService.GetMediaRating(Id, data => _globalRating = data),
_media.Type == MediaType.Movie ? MoviesWebAPIService.Get(Id, data => _movie = data) : Task.CompletedTask,
]);
}
// STEP 2
await Task.WhenAll(step2Tasks);
if (_error is null && _user is not null)
{
endTasks.AddRange(
[
MediaWebAPIService.GetMediaRatingByUser(Id, _user.Id, data => _userRating = data)
]);
}
// END
await Task.WhenAll(endTasks);
_loaded = true;
StateHasChanged();
}

View File

@@ -46,6 +46,7 @@
"GetMediaRatingByUser": "/{0}/rating/{1}",
"PutMediaRating": "/{0}/rating",
"DeleteMediaRating": "/{0}/rating",
"PostMediaView": "/{0}/view",
"GetPhotoMediaRandomBackground": "/{0}/photos/random_background",
"GetPoster": "/{0}/poster",