diff --git a/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Movies/IMoviesWebAPIService.cs b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Movies/IMoviesWebAPIService.cs index 1a856c7..1bbe0e7 100644 --- a/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Movies/IMoviesWebAPIService.cs +++ b/WatchIt.Website/WatchIt.Website.Services/WatchIt.Website.Services.WebAPI/WatchIt.Website.Services.WebAPI.Movies/IMoviesWebAPIService.cs @@ -9,4 +9,6 @@ public interface IMoviesWebAPIService Task GetMovie(long id, Action? successAction = null, Action? notFoundAction = null); Task PutMovie(long id, MovieRequest data, Action? successAction = null, Action>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null); Task DeleteMovie(long id, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null); + + Task GetMoviesViewRank(int? first = null, int? days = null, Action>? successAction = null, Action>? badRequestAction = null); } \ No newline at end of file diff --git a/WatchIt.Website/WatchIt.Website/App.razor b/WatchIt.Website/WatchIt.Website/App.razor index 51bd262..0e62374 100644 --- a/WatchIt.Website/WatchIt.Website/App.razor +++ b/WatchIt.Website/WatchIt.Website/App.razor @@ -10,7 +10,7 @@ - + diff --git a/WatchIt.Website/WatchIt.Website/Pages/HomePage.razor b/WatchIt.Website/WatchIt.Website/Pages/HomePage.razor index ee87f9b..2d99b94 100644 --- a/WatchIt.Website/WatchIt.Website/Pages/HomePage.razor +++ b/WatchIt.Website/WatchIt.Website/Pages/HomePage.razor @@ -1,54 +1,97 @@ @page "/" +@using WatchIt.Common.Model.Movies WatchIt
-
-
-

Hello, world!

-

Welcome to your new app.

-

Hello, world!

-

Welcome to your new app.

-

Hello, world!

-

Welcome to your new app.

-

Hello, world!

-

Welcome to your new app.

-

Hello, world!

-

Welcome to your new app.

-

Hello, world!

-

Welcome to your new app.

-

Hello, world!

-

Welcome to your new app.

-

Hello, world!

-

Welcome to your new app.

-

Hello, world!

-

Welcome to your new app.

-

Hello, world!

-

Welcome to your new app.

-

Hello, world!

-

Welcome to your new app.

-

Hello, world!

-

Welcome to your new app.

-

Hello, world!

-

Welcome to your new app.

-

Hello, world!

-

Welcome to your new app.

-

Hello, world!

-

Welcome to your new app.

-

Hello, world!

-

Welcome to your new app.

-

Hello, world!

-

Welcome to your new app.

-

Hello, world!

-

Welcome to your new app.

-

Hello, world!

-

Welcome to your new app.

-

Hello, world!

-

Welcome to your new app.

-

Hello, world!

-

Welcome to your new app.

-

Hello, world!

-

Welcome to your new app.

-
-
+ @if (_loaded) + { + if (string.IsNullOrWhiteSpace(_error)) + { +
+
+
+
+
+
+

Top 5 movies this week by popularity

+
+
+ +
+
+
+
+
+
+
+
+
+
+

Top 5 TV series this week by popularity

+
+
+ +
+
+
+
+ } + else + { + + } + } + else + { + + }
\ No newline at end of file diff --git a/WatchIt.Website/WatchIt.Website/Pages/HomePage.razor.cs b/WatchIt.Website/WatchIt.Website/Pages/HomePage.razor.cs index 3383e8e..170b8a6 100644 --- a/WatchIt.Website/WatchIt.Website/Pages/HomePage.razor.cs +++ b/WatchIt.Website/WatchIt.Website/Pages/HomePage.razor.cs @@ -1,6 +1,69 @@ -namespace WatchIt.Website.Pages; +using Microsoft.AspNetCore.Components; +using WatchIt.Common.Model.Media; +using WatchIt.Common.Model.Movies; +using WatchIt.Common.Model.Series; +using WatchIt.Website.Services.WebAPI.Media; +using WatchIt.Website.Services.WebAPI.Movies; +using WatchIt.Website.Services.WebAPI.Series; + +namespace WatchIt.Website.Pages; public partial class HomePage { + #region SERVICES + + [Inject] public NavigationManager NavigationManager { get; set; } = default!; + [Inject] public IMediaWebAPIService MediaWebAPIService { get; set; } = default!; + [Inject] public IMoviesWebAPIService MoviesWebAPIService { get; set; } = default!; + [Inject] public ISeriesWebAPIService SeriesWebAPIService { get; set; } = default!; + #endregion + + + + #region FIELDS + + private bool _loaded; + private string? _error; + + private IDictionary _topMovies = new Dictionary(); + private IDictionary _topSeries = new Dictionary(); + + #endregion + + + + #region PRIVATE METHODS + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + { + List step1Tasks = new List(); + List endTasks = new List(); + + // STEP 0 + step1Tasks.AddRange( + [ + MoviesWebAPIService.GetMoviesViewRank(successAction: data => _topMovies = data.ToDictionary(x => x, _ => default(MediaPosterResponse?))), + SeriesWebAPIService.GetSeriesViewRank(successAction: data => _topSeries = data.ToDictionary(x => x, _ => default(MediaPosterResponse?))), + ]); + + // STEP 1 + 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)) + ]); + + // END + await Task.WhenAll(endTasks); + + _loaded = true; + StateHasChanged(); + } + } + + #endregion } \ No newline at end of file diff --git a/WatchIt.Website/WatchIt.Website/Pages/HomePage.razor.css b/WatchIt.Website/WatchIt.Website/Pages/HomePage.razor.css new file mode 100644 index 0000000..2b6a9bf --- /dev/null +++ b/WatchIt.Website/WatchIt.Website/Pages/HomePage.razor.css @@ -0,0 +1,16 @@ +/* CLASSES */ + +.poster-aspect-ratio { + aspect-ratio: 3/5; +} + +.border-2 { + border-width: 2px; +} + +.place-circle { + width: 30px; + height: 30px; + vertical-align: middle; + line-height: 25px; +} \ No newline at end of file