Refactoring, database structure changed
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
@using Blazorise.Extensions
|
||||
@using WatchIt.DTO.Models.Controllers.Genres.Genre
|
||||
@using WatchIt.DTO.Models.Controllers.Media.Medium.Response
|
||||
@inherits Component
|
||||
|
||||
|
||||
|
||||
<div class="panel h-100">
|
||||
<div class="container-grid">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<div class="d-flex flex-wrap metadata-pill-container">
|
||||
<div class="metadata-pill">
|
||||
<strong>@(Data is MediumMovieResponse ? "Movie" : "TV Series")</strong>
|
||||
</div>
|
||||
@if (Data.ReleaseDate is not null)
|
||||
{
|
||||
<div class="metadata-pill">
|
||||
<strong>Release date:</strong> @Data.ReleaseDate.ToString()
|
||||
</div>
|
||||
}
|
||||
@if (Data.Duration is not null)
|
||||
{
|
||||
<div class="metadata-pill">
|
||||
<strong>Length:</strong> @TimeSpan.FromMinutes(Data.Duration.Value).ToString(@"hh\:mm")
|
||||
</div>
|
||||
}
|
||||
@if (Data is MediumMovieResponse movieData)
|
||||
{
|
||||
if (movieData.Budget is not null)
|
||||
{
|
||||
<div class="metadata-pill">
|
||||
<strong>Budget:</strong> @(Math.Round(movieData.Budget.Value))$
|
||||
</div>
|
||||
}
|
||||
}
|
||||
@if (Data is MediumSeriesResponse seriesData)
|
||||
{
|
||||
if (seriesData.HasEnded)
|
||||
{
|
||||
<div class="metadata-pill">
|
||||
Ended
|
||||
</div>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mt-4">
|
||||
<div class="col">
|
||||
<h4><strong>Genres:</strong></h4>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<div class="d-flex flex-wrap gap-3">
|
||||
@if (Data.Genres.IsNullOrEmpty())
|
||||
{
|
||||
<div>
|
||||
No genres assigned.
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (GenreResponse genre in Data.Genres)
|
||||
{
|
||||
<a class="text-decoration-none text-light" href="/genre/@genre.Id">
|
||||
<div class="metadata-pill">
|
||||
@genre.Name
|
||||
</div>
|
||||
</a>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,13 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using WatchIt.DTO.Models.Controllers.Media.Medium.Response;
|
||||
|
||||
namespace WatchIt.Website.Components.Panels.Pages.MediumPage;
|
||||
|
||||
public partial class MetadataPanel : Component
|
||||
{
|
||||
#region PARAMETERS
|
||||
|
||||
[Parameter] public required BaseMediumResponse Data { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
@using WatchIt.Website.Components.Subcomponents.Common
|
||||
@using Blazorise
|
||||
@inherits Component
|
||||
|
||||
|
||||
|
||||
<div class="panel panel-background-gold h-100 text-dark">
|
||||
<div class="container-grid">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<TitledDisplayRating Rating="@(_globalRating)" Title="Global rating:"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<hr class="rating-separator"/>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<h4 class="text-dark">
|
||||
<strong>Your rating:</strong>
|
||||
</h4>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<Authorization>
|
||||
<Authorized>
|
||||
<Rating SelectedValue="@(_userRating)" SelectedValueChanged="@(UserRatingChanged)" Color="Color.Dark" MaxValue="10" TextSize="@(TextSize.Large)"/>
|
||||
</Authorized>
|
||||
<NotAuthorized>
|
||||
<p class="text-dark">You must be logged in to add a rating</p>
|
||||
</NotAuthorized>
|
||||
<Loading>
|
||||
<LoadingInline Content="Loading..."/>
|
||||
</Loading>
|
||||
</Authorization>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,106 @@
|
||||
using System.Net;
|
||||
using System.Runtime.InteropServices;
|
||||
using Blazorise.Snackbar;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Refit;
|
||||
using WatchIt.DTO.Models.Controllers.Media.Medium.Response;
|
||||
using WatchIt.DTO.Models.Generics.Rating;
|
||||
using WatchIt.Website.Clients;
|
||||
using WatchIt.Website.Components.Layout;
|
||||
using WatchIt.Website.Services.Authentication;
|
||||
|
||||
namespace WatchIt.Website.Components.Panels.Pages.MediumPage;
|
||||
|
||||
public partial class RatingPanel : Component
|
||||
{
|
||||
#region SERVICES
|
||||
|
||||
[Inject] protected IAuthenticationService AuthenticationService { get; set; } = null!;
|
||||
[Inject] protected IMediaClient MediaClient { get; set; } = null!;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PARAMETERS
|
||||
|
||||
[Parameter] public required BaseMediumResponse Data { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region FIELDS
|
||||
|
||||
private RatingOverallResponse _globalRating;
|
||||
private int _userRating = 0;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region PRIVATE METHODS
|
||||
|
||||
protected override async Task OnFirstRenderAsync()
|
||||
{
|
||||
await base.OnFirstRenderAsync();
|
||||
|
||||
_globalRating = Data.Rating;
|
||||
|
||||
if (Base.AuthorizedAccount is not null)
|
||||
{
|
||||
IApiResponse<RatingUserResponse> response = await MediaClient.GetMediumUserRating(Data.Id, Base.AuthorizedAccount.Id);
|
||||
if (response.IsSuccessful || response.StatusCode == HttpStatusCode.NotFound)
|
||||
{
|
||||
_userRating = Convert.ToInt32(response.Content?.Rating ?? 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
await Base.SnackbarStack.PushAsync("An error occured. User rating could not be obtained.", SnackbarColor.Danger);
|
||||
}
|
||||
}
|
||||
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private async Task UserRatingChanged(int value)
|
||||
{
|
||||
if (value == _userRating)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string accessToken = await AuthenticationService.GetRawAccessTokenAsync() ?? string.Empty;
|
||||
|
||||
IApiResponse response;
|
||||
if (value == 0)
|
||||
{
|
||||
response = await MediaClient.DeleteMediumRating(accessToken, Data.Id);
|
||||
}
|
||||
else
|
||||
{
|
||||
response = await MediaClient.PutMediumRating(accessToken, Data.Id, new RatingRequest { Rating = Convert.ToByte(value) });
|
||||
}
|
||||
|
||||
if (response.IsSuccessful)
|
||||
{
|
||||
_userRating = value;
|
||||
|
||||
IApiResponse<RatingOverallResponse> globalRatingResponse = await MediaClient.GetMediumRating(Data.Id);
|
||||
if (globalRatingResponse.IsSuccessful)
|
||||
{
|
||||
_globalRating = globalRatingResponse.Content;
|
||||
}
|
||||
else
|
||||
{
|
||||
await Base.SnackbarStack.PushAsync("An error occured. Global rating could not be updated.", SnackbarColor.Danger);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
await Base.SnackbarStack.PushAsync("An error occured. User rating could not be changed.", SnackbarColor.Danger);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
.rating-separator {
|
||||
border-color: black;
|
||||
border-width: 1px;
|
||||
|
||||
margin: 10px 0;
|
||||
}
|
||||
Reference in New Issue
Block a user