61 lines
2.5 KiB
C#
61 lines
2.5 KiB
C#
|
|
using WatchIt.Common.Model.Genres;
|
|||
|
|
using WatchIt.Common.Model.Media;
|
|||
|
|
using WatchIt.Common.Services.HttpClient;
|
|||
|
|
using WatchIt.Website.Services.Utility.Configuration;
|
|||
|
|
using WatchIt.Website.Services.Utility.Configuration.Model;
|
|||
|
|
using WatchIt.Website.Services.WebAPI.Common;
|
|||
|
|
|
|||
|
|
namespace WatchIt.Website.Services.WebAPI.Media;
|
|||
|
|
|
|||
|
|
public class MediaWebAPIService(IHttpClientService httpClientService, IConfigurationService configurationService) : BaseWebAPIService(configurationService), IMediaWebAPIService
|
|||
|
|
{
|
|||
|
|
#region PUBLIC METHODS
|
|||
|
|
|
|||
|
|
public async Task GetGenres(long mediaId, Action<IEnumerable<GenreResponse>>? successAction = null, Action? notFoundAction = null)
|
|||
|
|
{
|
|||
|
|
string url = GetUrl(EndpointsConfiguration.Media.GetGenres, mediaId);
|
|||
|
|
|
|||
|
|
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
|
|||
|
|
|
|||
|
|
HttpResponse response = await httpClientService.SendRequestAsync(request);
|
|||
|
|
response.RegisterActionFor2XXSuccess(successAction)
|
|||
|
|
.RegisterActionFor404NotFound(notFoundAction)
|
|||
|
|
.ExecuteAction();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public async Task PostGenre(long mediaId, long genreId, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null, Action? notFoundAction = null)
|
|||
|
|
{
|
|||
|
|
string url = GetUrl(EndpointsConfiguration.Media.PostGenre, mediaId, genreId);
|
|||
|
|
|
|||
|
|
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
|
|||
|
|
|
|||
|
|
HttpResponse response = await httpClientService.SendRequestAsync(request);
|
|||
|
|
response.RegisterActionFor2XXSuccess(successAction)
|
|||
|
|
.RegisterActionFor401Unauthorized(unauthorizedAction)
|
|||
|
|
.RegisterActionFor403Forbidden(forbiddenAction)
|
|||
|
|
.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();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
#region PRIVATE METHODS
|
|||
|
|
|
|||
|
|
protected override string GetServiceBase() => EndpointsConfiguration.Media.Base;
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
}
|