116 lines
4.1 KiB
C#
116 lines
4.1 KiB
C#
using WatchIt.Common.Model.Genders;
|
|
using WatchIt.Common.Model.Genres;
|
|
using WatchIt.Common.Model.Media;
|
|
using WatchIt.Common.Services.HttpClient;
|
|
using WatchIt.Website.Services.Configuration;
|
|
|
|
namespace WatchIt.Website.Services.Client.Genres;
|
|
|
|
public class GenresClientService : BaseClientService, IGenresClientService
|
|
{
|
|
#region SERVICES
|
|
|
|
private IHttpClientService _httpClientService;
|
|
private IConfigurationService _configurationService;
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region CONSTRUCTORS
|
|
|
|
public GenresClientService(IHttpClientService httpClientService, IConfigurationService configurationService) : base(configurationService)
|
|
{
|
|
_httpClientService = httpClientService;
|
|
_configurationService = configurationService;
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region PUBLIC METHODS
|
|
|
|
#region Main
|
|
|
|
public async Task GetGenres(GenreQueryParameters? query = null, Action<IEnumerable<GenreResponse>>? successAction = null)
|
|
{
|
|
string url = GetUrl(EndpointsConfiguration.Genres.GetGenres);
|
|
|
|
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
|
|
request.Query = query;
|
|
|
|
HttpResponse response = await _httpClientService.SendRequestAsync(request);
|
|
response.RegisterActionFor2XXSuccess(successAction)
|
|
.ExecuteAction();
|
|
}
|
|
|
|
public async Task GetGenre(long id, Action<GenreResponse>? successAction = null, Action? notFoundAction = null)
|
|
{
|
|
string url = GetUrl(EndpointsConfiguration.Genres.GetGenre, id);
|
|
|
|
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
|
|
|
|
HttpResponse response = await _httpClientService.SendRequestAsync(request);
|
|
response.RegisterActionFor2XXSuccess(successAction)
|
|
.RegisterActionFor404NotFound(notFoundAction)
|
|
.ExecuteAction();
|
|
}
|
|
|
|
public async Task PostGenre(GenreRequest data, Action<GenreResponse>? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null)
|
|
{
|
|
string url = GetUrl(EndpointsConfiguration.Genres.PostGenre);
|
|
|
|
HttpRequest request = new HttpRequest(HttpMethodType.Post, url);
|
|
request.Body = data;
|
|
|
|
HttpResponse response = await _httpClientService.SendRequestAsync(request);
|
|
response.RegisterActionFor2XXSuccess(successAction)
|
|
.RegisterActionFor400BadRequest(badRequestAction)
|
|
.RegisterActionFor401Unauthorized(unauthorizedAction)
|
|
.RegisterActionFor403Forbidden(forbiddenAction)
|
|
.ExecuteAction();
|
|
}
|
|
|
|
public async Task DeleteGenre(long id, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null)
|
|
{
|
|
string url = GetUrl(EndpointsConfiguration.Genres.DeleteGenre, id);
|
|
|
|
HttpRequest request = new HttpRequest(HttpMethodType.Delete, url);
|
|
|
|
HttpResponse response = await _httpClientService.SendRequestAsync(request);
|
|
response.RegisterActionFor2XXSuccess(successAction)
|
|
.RegisterActionFor401Unauthorized(unauthorizedAction)
|
|
.RegisterActionFor403Forbidden(forbiddenAction)
|
|
.ExecuteAction();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Media
|
|
|
|
public async Task GetGenreMedia(short id, MediaQueryParameters? query = null, Action<IEnumerable<MediaResponse>>? successAction = null, Action notFoundAction = null)
|
|
{
|
|
string url = GetUrl(EndpointsConfiguration.Genres.GetGenreMedia, id);
|
|
|
|
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
|
|
request.Query = query;
|
|
|
|
HttpResponse response = await _httpClientService.SendRequestAsync(request);
|
|
response.RegisterActionFor2XXSuccess(successAction)
|
|
.RegisterActionFor404NotFound(notFoundAction)
|
|
.ExecuteAction();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region PRIVATE METHODS
|
|
|
|
protected override string GetServiceBase() => EndpointsConfiguration.Genres.Base;
|
|
|
|
#endregion
|
|
} |