new photos controller created

This commit is contained in:
2024-09-25 22:11:28 +02:00
Unverified
parent bb67186587
commit 9e9e5e1742
36 changed files with 743 additions and 332 deletions

View File

@@ -8,4 +8,5 @@ public class Endpoints
public Media Media { get; set; }
public Movies Movies { get; set; }
public Series Series { get; set; }
public Photos Photos { get; set; }
}

View File

@@ -3,23 +3,19 @@
public class Media
{
public string Base { get; set; }
public string Get { get; set; }
public string GetGenres { get; set; }
public string PostGenre { get; set; }
public string DeleteGenre { get; set; }
public string GetMedia { get; set; }
public string GetMediaGenres { get; set; }
public string PostMediaGenre { get; set; }
public string DeleteMediaGenre { get; set; }
public string GetMediaRating { get; set; }
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; }
public string DeletePoster { get; set; }
public string GetPhoto { get; set; }
public string GetPhotos { get; set; }
public string GetPhotoRandomBackground { get; set; }
public string PostPhoto { get; set; }
public string PutPhoto { get; set; }
public string DeletePhoto { get; set; }
public string GetMediaPoster { get; set; }
public string PutMediaPoster { get; set; }
public string DeleteMediaPoster { get; set; }
public string GetMediaPhotos { get; set; }
public string GetMediaPhotoRandomBackground { get; set; }
public string PostMediaPhoto { get; set; }
}

View File

@@ -0,0 +1,10 @@
namespace WatchIt.Website.Services.Utility.Configuration.Model;
public class Photos
{
public string Base { get; set; }
public string GetPhotoRandomBackground { get; set; }
public string DeletePhoto { get; set; }
public string PutPhotoBackgroundData { get; set; }
public string DeletePhotoBackgroundData { get; set; }
}

View File

@@ -1,5 +1,6 @@
using WatchIt.Common.Model.Genres;
using WatchIt.Common.Model.Media;
using WatchIt.Common.Model.Photos;
namespace WatchIt.Website.Services.WebAPI.Media;
@@ -9,6 +10,7 @@ public interface IMediaWebAPIService
Task GetMediaGenres(long mediaId, Action<IEnumerable<GenreResponse>>? successAction = null, Action? notFoundAction = null);
Task PostMediaGenre(long mediaId, long genreId, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null, Action? notFoundAction = null);
Task DeleteMediaGenre(long mediaId, long genreId, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null, Action? notFoundAction = null);
Task GetMediaRating(long mediaId, Action<MediaRatingResponse>? successAction = null, Action? notFoundAction = null);
Task GetMediaRatingByUser(long mediaId, long userId, Action<short>? successAction = null, Action? notFoundAction = null);
@@ -17,9 +19,11 @@ public interface IMediaWebAPIService
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);
Task GetPoster(long mediaId, Action<MediaPosterResponse>? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? notFoundAction = null);
Task PutPoster(long mediaId, MediaPosterRequest data, Action<MediaPosterResponse>? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null);
Task DeletePoster(long mediaId, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null);
Task GetMediaPoster(long mediaId, Action<MediaPosterResponse>? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? notFoundAction = null);
Task PutMediaPoster(long mediaId, MediaPosterRequest data, Action<MediaPosterResponse>? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null);
Task DeleteMediaPoster(long mediaId, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null);
Task GetMediaPhotos(long mediaId, PhotoQueryParameters? query = null, Action<IEnumerable<PhotoResponse>>? successAction = null, Action? notFoundAction = null);
Task GetMediaPhotoRandomBackground(long mediaId, Action<PhotoResponse>? successAction = null, Action? notFoundAction = null);
Task PostMediaPhoto(long mediaId, MediaPhotoRequest data, Action? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null, Action? notFoundAction = null);
}

View File

@@ -1,5 +1,6 @@
using WatchIt.Common.Model.Genres;
using WatchIt.Common.Model.Media;
using WatchIt.Common.Model.Photos;
using WatchIt.Common.Services.HttpClient;
using WatchIt.Website.Services.Utility.Configuration;
using WatchIt.Website.Services.Utility.Configuration.Model;
@@ -7,19 +8,38 @@ using WatchIt.Website.Services.WebAPI.Common;
namespace WatchIt.Website.Services.WebAPI.Media;
public class MediaWebAPIService(IHttpClientService httpClientService, IConfigurationService configurationService) : BaseWebAPIService(configurationService), IMediaWebAPIService
public class MediaWebAPIService : BaseWebAPIService, IMediaWebAPIService
{
#region FIELDS
private readonly IHttpClientService _httpClientService;
#endregion
#region CONSTRUCTORS
public MediaWebAPIService(IHttpClientService httpClientService, IConfigurationService configurationService) : base(configurationService)
{
_httpClientService = httpClientService;
}
#endregion
#region PUBLIC METHODS
#region Main
public async Task GetMedia(long mediaId, Action<MediaResponse>? successAction = null, Action? notFoundAction = null)
{
string url = GetUrl(EndpointsConfiguration.Media.Get, mediaId);
string url = GetUrl(EndpointsConfiguration.Media.GetMedia, mediaId);
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
HttpResponse response = await httpClientService.SendRequestAsync(request);
HttpResponse response = await _httpClientService.SendRequestAsync(request);
response.RegisterActionFor2XXSuccess(successAction)
.RegisterActionFor404NotFound(notFoundAction)
.ExecuteAction();
@@ -31,11 +51,11 @@ public class MediaWebAPIService(IHttpClientService httpClientService, IConfigura
public async Task GetMediaGenres(long mediaId, Action<IEnumerable<GenreResponse>>? successAction = null, Action? notFoundAction = null)
{
string url = GetUrl(EndpointsConfiguration.Media.GetGenres, mediaId);
string url = GetUrl(EndpointsConfiguration.Media.GetMediaGenres, mediaId);
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
HttpResponse response = await httpClientService.SendRequestAsync(request);
HttpResponse response = await _httpClientService.SendRequestAsync(request);
response.RegisterActionFor2XXSuccess(successAction)
.RegisterActionFor404NotFound(notFoundAction)
.ExecuteAction();
@@ -43,11 +63,25 @@ public class MediaWebAPIService(IHttpClientService httpClientService, IConfigura
public async Task PostMediaGenre(long mediaId, long genreId, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null, Action? notFoundAction = null)
{
string url = GetUrl(EndpointsConfiguration.Media.PostGenre, mediaId, genreId);
string url = GetUrl(EndpointsConfiguration.Media.PostMediaGenre, mediaId, genreId);
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
HttpRequest request = new HttpRequest(HttpMethodType.Post, url);
HttpResponse response = await httpClientService.SendRequestAsync(request);
HttpResponse response = await _httpClientService.SendRequestAsync(request);
response.RegisterActionFor2XXSuccess(successAction)
.RegisterActionFor401Unauthorized(unauthorizedAction)
.RegisterActionFor403Forbidden(forbiddenAction)
.RegisterActionFor404NotFound(notFoundAction)
.ExecuteAction();
}
public async Task DeleteMediaGenre(long mediaId, long genreId, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null, Action? notFoundAction = null)
{
string url = GetUrl(EndpointsConfiguration.Media.DeleteMediaGenre, mediaId, genreId);
HttpRequest request = new HttpRequest(HttpMethodType.Delete, url);
HttpResponse response = await _httpClientService.SendRequestAsync(request);
response.RegisterActionFor2XXSuccess(successAction)
.RegisterActionFor401Unauthorized(unauthorizedAction)
.RegisterActionFor403Forbidden(forbiddenAction)
@@ -65,7 +99,7 @@ public class MediaWebAPIService(IHttpClientService httpClientService, IConfigura
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
HttpResponse response = await httpClientService.SendRequestAsync(request);
HttpResponse response = await _httpClientService.SendRequestAsync(request);
response.RegisterActionFor2XXSuccess(successAction)
.RegisterActionFor404NotFound(notFoundAction)
.ExecuteAction();
@@ -77,7 +111,7 @@ public class MediaWebAPIService(IHttpClientService httpClientService, IConfigura
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
HttpResponse response = await httpClientService.SendRequestAsync(request);
HttpResponse response = await _httpClientService.SendRequestAsync(request);
response.RegisterActionFor2XXSuccess(successAction)
.RegisterActionFor404NotFound(notFoundAction)
.ExecuteAction();
@@ -92,7 +126,7 @@ public class MediaWebAPIService(IHttpClientService httpClientService, IConfigura
Body = body
};
HttpResponse response = await httpClientService.SendRequestAsync(request);
HttpResponse response = await _httpClientService.SendRequestAsync(request);
response.RegisterActionFor2XXSuccess(successAction)
.RegisterActionFor400BadRequest(badRequestAction)
.RegisterActionFor401Unauthorized(unauthorizedAction)
@@ -106,7 +140,7 @@ public class MediaWebAPIService(IHttpClientService httpClientService, IConfigura
HttpRequest request = new HttpRequest(HttpMethodType.Delete, url);
HttpResponse response = await httpClientService.SendRequestAsync(request);
HttpResponse response = await _httpClientService.SendRequestAsync(request);
response.RegisterActionFor2XXSuccess(successAction)
.RegisterActionFor401Unauthorized(unauthorizedAction)
.ExecuteAction();
@@ -122,7 +156,7 @@ public class MediaWebAPIService(IHttpClientService httpClientService, IConfigura
HttpRequest request = new HttpRequest(HttpMethodType.Post, url);
HttpResponse response = await httpClientService.SendRequestAsync(request);
HttpResponse response = await _httpClientService.SendRequestAsync(request);
response.RegisterActionFor2XXSuccess(successAction)
.RegisterActionFor404NotFound(notFoundAction)
.ExecuteAction();
@@ -130,55 +164,31 @@ public class MediaWebAPIService(IHttpClientService httpClientService, IConfigura
#endregion
#region Poster
public async Task GetPhotoMediaRandomBackground(long mediaId, Action<MediaPhotoResponse>? successAction = null, Action? notFoundAction = null)
public async Task GetMediaPoster(long mediaId, Action<MediaPosterResponse>? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? notFoundAction = null)
{
string url = GetUrl(EndpointsConfiguration.Media.GetPhotoMediaRandomBackground, mediaId);
string url = GetUrl(EndpointsConfiguration.Media.GetMediaPoster, mediaId);
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
HttpResponse response = await httpClientService.SendRequestAsync(request);
response.RegisterActionFor2XXSuccess(successAction)
.RegisterActionFor404NotFound(notFoundAction)
.ExecuteAction();
}
public async Task GetPhotoRandomBackground(Action<MediaPhotoResponse>? successAction = null, Action? notFoundAction = null)
{
string url = GetUrl(EndpointsConfiguration.Media.GetPhotoRandomBackground);
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
HttpResponse response = await httpClientService.SendRequestAsync(request);
response.RegisterActionFor2XXSuccess(successAction)
.RegisterActionFor404NotFound(notFoundAction)
.ExecuteAction();
}
public async Task GetPoster(long mediaId, Action<MediaPosterResponse>? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? notFoundAction = null)
{
string url = GetUrl(EndpointsConfiguration.Media.GetPoster, mediaId);
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
HttpResponse response = await httpClientService.SendRequestAsync(request);
HttpResponse response = await _httpClientService.SendRequestAsync(request);
response.RegisterActionFor2XXSuccess(successAction)
.RegisterActionFor400BadRequest(badRequestAction)
.RegisterActionFor404NotFound(notFoundAction)
.ExecuteAction();
}
public async Task PutPoster(long mediaId, MediaPosterRequest data, Action<MediaPosterResponse>? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null)
public async Task PutMediaPoster(long mediaId, MediaPosterRequest data, Action<MediaPosterResponse>? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null)
{
string url = GetUrl(EndpointsConfiguration.Media.PutPoster, mediaId);
string url = GetUrl(EndpointsConfiguration.Media.PutMediaPoster, mediaId);
HttpRequest request = new HttpRequest(HttpMethodType.Put, url)
{
Body = data
};
HttpResponse response = await httpClientService.SendRequestAsync(request);
HttpResponse response = await _httpClientService.SendRequestAsync(request);
response.RegisterActionFor2XXSuccess(successAction)
.RegisterActionFor400BadRequest(badRequestAction)
.RegisterActionFor401Unauthorized(unauthorizedAction)
@@ -186,18 +196,63 @@ public class MediaWebAPIService(IHttpClientService httpClientService, IConfigura
.ExecuteAction();
}
public async Task DeletePoster(long mediaId, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null)
public async Task DeleteMediaPoster(long mediaId, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null)
{
string url = GetUrl(EndpointsConfiguration.Media.DeletePoster, mediaId);
string url = GetUrl(EndpointsConfiguration.Media.DeleteMediaPoster, mediaId);
HttpRequest request = new HttpRequest(HttpMethodType.Delete, url);
HttpResponse response = await httpClientService.SendRequestAsync(request);
HttpResponse response = await _httpClientService.SendRequestAsync(request);
response.RegisterActionFor2XXSuccess(successAction)
.RegisterActionFor401Unauthorized(unauthorizedAction)
.RegisterActionFor403Forbidden(forbiddenAction)
.ExecuteAction();
}
#endregion
#region Photos
public async Task GetMediaPhotos(long mediaId, PhotoQueryParameters? query = null, Action<IEnumerable<PhotoResponse>>? successAction = null, Action? notFoundAction = null)
{
string url = GetUrl(EndpointsConfiguration.Media.GetMediaPhotos, mediaId);
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
HttpResponse response = await _httpClientService.SendRequestAsync(request);
response.RegisterActionFor2XXSuccess(successAction)
.RegisterActionFor404NotFound(notFoundAction)
.ExecuteAction();
}
public async Task GetMediaPhotoRandomBackground(long mediaId, Action<PhotoResponse>? successAction = null, Action? notFoundAction = null)
{
string url = GetUrl(EndpointsConfiguration.Media.GetMediaPhotoRandomBackground, mediaId);
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
HttpResponse response = await _httpClientService.SendRequestAsync(request);
response.RegisterActionFor2XXSuccess(successAction)
.RegisterActionFor404NotFound(notFoundAction)
.ExecuteAction();
}
public async Task PostMediaPhoto(long mediaId, MediaPhotoRequest data, Action? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null, Action? notFoundAction = null)
{
string url = GetUrl(EndpointsConfiguration.Media.PostMediaPhoto, mediaId);
HttpRequest request = new HttpRequest(HttpMethodType.Post, url);
HttpResponse response = await _httpClientService.SendRequestAsync(request);
response.RegisterActionFor2XXSuccess(successAction)
.RegisterActionFor400BadRequest(badRequestAction)
.RegisterActionFor401Unauthorized(unauthorizedAction)
.RegisterActionFor403Forbidden(forbiddenAction)
.RegisterActionFor404NotFound(notFoundAction)
.ExecuteAction();
}
#endregion
#endregion

View File

@@ -0,0 +1,11 @@
using WatchIt.Common.Model.Photos;
namespace WatchIt.Website.Services.WebAPI.Photos;
public interface IPhotosWebAPIService
{
Task GetPhotoRandomBackground(Action<PhotoResponse>? successAction = null, Action? notFoundAction = null);
Task DeletePhoto(Guid id, Action<PhotoResponse>? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null, Action? notFoundAction = null);
Task PutPhotoBackgroundData(Guid id, PhotoBackgroundDataRequest data, Action<PhotoResponse>? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null, Action? notFoundAction = null);
Task DeletePhotoBackgroundData(Guid id, Action<PhotoResponse>? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null, Action? notFoundAction = null);
}

View File

@@ -0,0 +1,105 @@
using WatchIt.Common.Model.Photos;
using WatchIt.Common.Services.HttpClient;
using WatchIt.Website.Services.Utility.Configuration;
using WatchIt.Website.Services.WebAPI.Common;
namespace WatchIt.Website.Services.WebAPI.Photos;
public class PhotosWebAPIService : BaseWebAPIService, IPhotosWebAPIService
{
#region FIELDS
private readonly IHttpClientService _httpClientService;
#endregion
#region CONSTRUCTORS
public PhotosWebAPIService(IHttpClientService httpClientService, IConfigurationService configurationService) : base(configurationService)
{
_httpClientService = httpClientService;
}
#endregion
#region PUBLIC METHODS
#region Main
public async Task GetPhotoRandomBackground(Action<PhotoResponse>? successAction = null, Action? notFoundAction = null)
{
string url = GetUrl(EndpointsConfiguration.Photos.GetPhotoRandomBackground);
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
HttpResponse response = await _httpClientService.SendRequestAsync(request);
response.RegisterActionFor2XXSuccess(successAction)
.RegisterActionFor404NotFound(notFoundAction)
.ExecuteAction();
}
public async Task DeletePhoto(Guid id, Action<PhotoResponse>? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null, Action? notFoundAction = null)
{
string url = GetUrl(EndpointsConfiguration.Photos.DeletePhoto, id);
HttpRequest request = new HttpRequest(HttpMethodType.Delete, url);
HttpResponse response = await _httpClientService.SendRequestAsync(request);
response.RegisterActionFor2XXSuccess(successAction)
.RegisterActionFor401Unauthorized(unauthorizedAction)
.RegisterActionFor403Forbidden(forbiddenAction)
.RegisterActionFor404NotFound(notFoundAction)
.ExecuteAction();
}
#endregion
#region Background data
public async Task PutPhotoBackgroundData(Guid id, PhotoBackgroundDataRequest data, Action<PhotoResponse>? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null, Action? notFoundAction = null)
{
string url = GetUrl(EndpointsConfiguration.Photos.PutPhotoBackgroundData, id);
HttpRequest request = new HttpRequest(HttpMethodType.Put, url)
{
Body = data
};
HttpResponse response = await _httpClientService.SendRequestAsync(request);
response.RegisterActionFor2XXSuccess(successAction)
.RegisterActionFor401Unauthorized(unauthorizedAction)
.RegisterActionFor403Forbidden(forbiddenAction)
.RegisterActionFor404NotFound(notFoundAction)
.ExecuteAction();
}
public async Task DeletePhotoBackgroundData(Guid id, Action<PhotoResponse>? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null, Action? notFoundAction = null)
{
string url = GetUrl(EndpointsConfiguration.Photos.DeletePhotoBackgroundData, id);
HttpRequest request = new HttpRequest(HttpMethodType.Delete, url);
HttpResponse response = await _httpClientService.SendRequestAsync(request);
response.RegisterActionFor2XXSuccess(successAction)
.RegisterActionFor401Unauthorized(unauthorizedAction)
.RegisterActionFor403Forbidden(forbiddenAction)
.RegisterActionFor404NotFound(notFoundAction)
.ExecuteAction();
}
#endregion
#endregion
#region PRIVATE METHODS
protected override string GetServiceBase() => EndpointsConfiguration.Photos.Base;
#endregion
}

View File

@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\WatchIt.Common\WatchIt.Common.Services\WatchIt.Common.Services.HttpClient\WatchIt.Common.Services.HttpClient.csproj" />
<ProjectReference Include="..\..\WatchIt.Website.Services.Utility\WatchIt.Website.Services.Utility.Configuration\WatchIt.Website.Services.Utility.Configuration.csproj" />
<ProjectReference Include="..\WatchIt.Website.Services.WebAPI.Common\WatchIt.Website.Services.WebAPI.Common.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,4 +1,6 @@
@inherits LayoutComponentBase
@using WatchIt.Common.Model.Photos
@using WatchIt.Website.Services.WebAPI.Photos
@inherits LayoutComponentBase
@if (_loaded)
{
@@ -87,6 +89,7 @@
[Inject] public IAuthenticationService AuthenticationService { get; set; } = default!;
[Inject] public IAccountsWebAPIService AccountsWebAPIService { get; set; } = default!;
[Inject] public IMediaWebAPIService MediaWebAPIService { get; set; } = default!;
[Inject] public IPhotosWebAPIService PhotosWebAPIService { get; set; } = default!;
#endregion
@@ -134,7 +137,7 @@
private async Task GetBackground()
{
Action<MediaPhotoResponse> backgroundSuccess = (data) =>
Action<PhotoResponse> backgroundSuccess = (data) =>
{
string imageBase64 = Convert.ToBase64String(data.Image);
string firstColor = BitConverter.ToString(data.Background.FirstGradientColor)
@@ -146,7 +149,7 @@
_firstGradientColor = $"#{firstColor}";
_secondGradientColor = $"#{secondColor}";
};
await MediaWebAPIService.GetPhotoRandomBackground(backgroundSuccess);
await PhotosWebAPIService.GetPhotoRandomBackground(backgroundSuccess);
}
private async Task GetAuthenticatedUser()

View File

@@ -1,10 +1,12 @@
using Microsoft.AspNetCore.Components;
using WatchIt.Common.Model.Accounts;
using WatchIt.Common.Model.Media;
using WatchIt.Common.Model.Photos;
using WatchIt.Website.Services.Utility.Authentication;
using WatchIt.Website.Services.Utility.Tokens;
using WatchIt.Website.Services.WebAPI.Accounts;
using WatchIt.Website.Services.WebAPI.Media;
using WatchIt.Website.Services.WebAPI.Photos;
namespace WatchIt.Website.Pages;
@@ -17,6 +19,7 @@ public partial class AuthPage
[Inject] public ITokensService TokensService { get; set; } = default!;
[Inject] public IMediaWebAPIService MediaWebAPIService { get; set; } = default!;
[Inject] public IAccountsWebAPIService AccountsWebAPIService { get; set; } = default!;
[Inject] public IPhotosWebAPIService PhotosWebAPIService { get; set; } = default!;
[Inject] public NavigationManager NavigationManager { get; set; } = default!;
#endregion
@@ -75,7 +78,7 @@ public partial class AuthPage
NavigationManager.NavigateTo("/");
}
Action<MediaPhotoResponse> backgroundSuccess = (data) =>
Action<PhotoResponse> backgroundSuccess = (data) =>
{
string imageBase64 = Convert.ToBase64String(data.Image);
string firstColor = BitConverter.ToString(data.Background.FirstGradientColor)
@@ -87,7 +90,7 @@ public partial class AuthPage
_firstGradientColor = $"#{firstColor}";
_secondGradientColor = $"#{secondColor}";
};
await MediaWebAPIService.GetPhotoRandomBackground(backgroundSuccess);
await PhotosWebAPIService.GetPhotoRandomBackground(backgroundSuccess);
_loaded = true;
StateHasChanged();

View File

@@ -53,8 +53,8 @@ public partial class HomePage
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))
Parallel.ForEachAsync(_topMovies, async (x, _) => await MediaWebAPIService.GetMediaPoster(x.Key.Id, y => _topMovies[x.Key] = y)),
Parallel.ForEachAsync(_topSeries, async (x, _) => await MediaWebAPIService.GetMediaPoster(x.Key.Id, y => _topSeries[x.Key] = y))
]);
// END

View File

@@ -3,10 +3,12 @@ using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Forms;
using WatchIt.Common.Model.Media;
using WatchIt.Common.Model.Movies;
using WatchIt.Common.Model.Photos;
using WatchIt.Common.Model.Series;
using WatchIt.Website.Services.Utility.Authentication;
using WatchIt.Website.Services.WebAPI.Media;
using WatchIt.Website.Services.WebAPI.Movies;
using WatchIt.Website.Services.WebAPI.Photos;
using WatchIt.Website.Services.WebAPI.Series;
namespace WatchIt.Website.Pages;
@@ -41,7 +43,7 @@ public partial class MediaEditPage : ComponentBase
private User? _user;
private MediaPhotoResponse? _background;
private PhotoResponse? _background;
private MediaResponse? _media;
private MovieRequest? _movieRequest;
@@ -94,8 +96,8 @@ public partial class MediaEditPage : ComponentBase
{
endTasks.AddRange(
[
MediaWebAPIService.GetPhotoMediaRandomBackground(Id.Value, data => _background = data),
MediaWebAPIService.GetPoster(Id.Value, data =>
MediaWebAPIService.GetMediaPhotoRandomBackground(Id.Value, data => _background = data),
MediaWebAPIService.GetMediaPoster(Id.Value, data =>
{
_mediaPosterSaved = data;
_mediaPosterRequest = new MediaPosterRequest(data);
@@ -179,7 +181,7 @@ public partial class MediaEditPage : ComponentBase
}
_mediaPosterSaving = true;
await MediaWebAPIService.PutPoster(Id.Value, _mediaPosterRequest, Success);
await MediaWebAPIService.PutMediaPoster(Id.Value, _mediaPosterRequest, Success);
}
private void CancelPoster()
@@ -199,7 +201,7 @@ public partial class MediaEditPage : ComponentBase
}
_mediaPosterDeleting = true;
await MediaWebAPIService.DeletePoster(Id.Value, Success);
await MediaWebAPIService.DeleteMediaPoster(Id.Value, Success);
}
#endregion

View File

@@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Components;
using WatchIt.Common.Model.Genres;
using WatchIt.Common.Model.Media;
using WatchIt.Common.Model.Movies;
using WatchIt.Common.Model.Photos;
using WatchIt.Common.Model.Series;
using WatchIt.Website.Services.Utility.Authentication;
using WatchIt.Website.Services.WebAPI.Media;
@@ -42,7 +43,7 @@ public partial class MediaPage : ComponentBase
private User? _user;
private MediaPhotoResponse? _background;
private PhotoResponse? _background;
private MediaPosterResponse? _poster;
private IEnumerable<GenreResponse> _genres;
private MediaRatingResponse _globalRating;
@@ -83,8 +84,8 @@ public partial class MediaPage : ComponentBase
endTasks.AddRange(
[
MediaWebAPIService.PostMediaView(Id),
MediaWebAPIService.GetPhotoMediaRandomBackground(Id, data => _background = data),
MediaWebAPIService.GetPoster(Id, data => _poster = data),
MediaWebAPIService.GetMediaPhotoRandomBackground(Id, data => _background = data),
MediaWebAPIService.GetMediaPoster(Id, data => _poster = data),
MediaWebAPIService.GetMediaGenres(Id, data => _genres = data),
MediaWebAPIService.GetMediaRating(Id, data => _globalRating = data),
_media.Type == MediaType.Movie ? MoviesWebAPIService.GetMovie(Id, data => _movie = data) : SeriesWebAPIService.GetSeries(Id, data => _series = data),

View File

@@ -8,6 +8,7 @@ using WatchIt.Website.Services.Utility.Tokens;
using WatchIt.Website.Services.WebAPI.Accounts;
using WatchIt.Website.Services.WebAPI.Media;
using WatchIt.Website.Services.WebAPI.Movies;
using WatchIt.Website.Services.WebAPI.Photos;
using WatchIt.Website.Services.WebAPI.Series;
namespace WatchIt.Website;
@@ -64,6 +65,7 @@ public static class Program
builder.Services.AddSingleton<IMediaWebAPIService, MediaWebAPIService>();
builder.Services.AddSingleton<IMoviesWebAPIService, MoviesWebAPIService>();
builder.Services.AddSingleton<ISeriesWebAPIService, SeriesWebAPIService>();
builder.Services.AddSingleton<IPhotosWebAPIService, PhotosWebAPIService>();
return builder;
}

View File

@@ -22,6 +22,7 @@
<ProjectReference Include="..\WatchIt.Website.Services\WatchIt.Website.Services.WebAPI\WatchIt.Website.Services.WebAPI.Accounts\WatchIt.Website.Services.WebAPI.Accounts.csproj" />
<ProjectReference Include="..\WatchIt.Website.Services\WatchIt.Website.Services.WebAPI\WatchIt.Website.Services.WebAPI.Media\WatchIt.Website.Services.WebAPI.Media.csproj" />
<ProjectReference Include="..\WatchIt.Website.Services\WatchIt.Website.Services.WebAPI\WatchIt.Website.Services.WebAPI.Movies\WatchIt.Website.Services.WebAPI.Movies.csproj" />
<ProjectReference Include="..\WatchIt.Website.Services\WatchIt.Website.Services.WebAPI\WatchIt.Website.Services.WebAPI.Photos\WatchIt.Website.Services.WebAPI.Photos.csproj" />
<ProjectReference Include="..\WatchIt.Website.Services\WatchIt.Website.Services.WebAPI\WatchIt.Website.Services.WebAPI.Series\WatchIt.Website.Services.WebAPI.Series.csproj" />
</ItemGroup>

View File

@@ -30,26 +30,21 @@
},
"Media": {
"Base": "/media",
"Get": "/{0}",
"GetGenres": "/{0}/genres",
"PostGenre": "/{0}/genres/{1}",
"DeleteGenre": "/{0}/genres/{1}",
"GetMedia": "/{0}",
"GetMediaGenres": "/{0}/genres",
"PostMediaGenre": "/{0}/genres/{1}",
"DeleteMediaGenre": "/{0}/genres/{1}",
"GetMediaRating": "/{0}/rating",
"GetMediaRatingByUser": "/{0}/rating/{1}",
"PutMediaRating": "/{0}/rating",
"DeleteMediaRating": "/{0}/rating",
"PostMediaView": "/{0}/view",
"GetPhotoMediaRandomBackground": "/{0}/photos/random_background",
"GetPoster": "/{0}/poster",
"PutPoster": "/{0}/poster",
"DeletePoster": "/{0}/poster",
"GetPhoto": "/photos/{0}",
"GetPhotos": "/photos",
"GetPhotoRandomBackground": "/photos/random_background",
"PostPhoto": "/photos",
"PutPhoto": "/photos/{0}",
"DeletePhoto": "/photos/{0}"
"GetMediaPoster": "/{0}/poster",
"PutMediaPoster": "/{0}/poster",
"DeleteMediaPoster": "/{0}/poster",
"GetMediaPhotos": "/{0}/photos",
"GetMediaPhotoRandomBackground": "/{0}/photos/random_background",
"PostMediaPhoto": "/{0}/photos"
},
"Movies": {
"Base": "/movies",
@@ -68,6 +63,13 @@
"PutSeries": "/{0}",
"DeleteSeries": "/{0}",
"GetSeriesViewRank": "/view"
},
"Photos": {
"Base": "/photos",
"GetPhotoRandomBackground": "/random_background",
"DeletePhoto": "/{0}",
"PutPhotoBackgroundData": "/{0}/background_data",
"DeletePhotoBackgroundData": "/{0}/background_data"
}
}
}