2024-10-03 16:18:17 +02:00
|
|
|
|
using System.Text;
|
|
|
|
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
|
|
using Microsoft.Extensions.Primitives;
|
|
|
|
|
|
using WatchIt.Common.Model.Persons;
|
2024-10-23 02:39:15 +02:00
|
|
|
|
using WatchIt.Common.Model.Rating;
|
2024-10-06 23:16:53 +02:00
|
|
|
|
using WatchIt.Common.Model.Roles;
|
2024-10-03 16:18:17 +02:00
|
|
|
|
using WatchIt.Common.Services.HttpClient;
|
2024-10-27 22:09:46 +01:00
|
|
|
|
using WatchIt.Website.Services.Configuration;
|
2024-10-03 16:18:17 +02:00
|
|
|
|
|
2024-10-27 22:09:46 +01:00
|
|
|
|
namespace WatchIt.Website.Services.Client.Persons;
|
2024-10-03 16:18:17 +02:00
|
|
|
|
|
2024-10-27 22:09:46 +01:00
|
|
|
|
public class PersonsClientService : BaseClientService, IPersonsClientService
|
2024-10-03 16:18:17 +02:00
|
|
|
|
{
|
|
|
|
|
|
#region SERVICES
|
|
|
|
|
|
|
|
|
|
|
|
private IHttpClientService _httpClientService;
|
|
|
|
|
|
private IConfigurationService _configurationService;
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region CONSTRUCTORS
|
|
|
|
|
|
|
2024-10-27 22:09:46 +01:00
|
|
|
|
public PersonsClientService(IHttpClientService httpClientService, IConfigurationService configurationService) : base(configurationService)
|
2024-10-03 16:18:17 +02:00
|
|
|
|
{
|
|
|
|
|
|
_httpClientService = httpClientService;
|
|
|
|
|
|
_configurationService = configurationService;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region PUBLIC METHODS
|
|
|
|
|
|
|
|
|
|
|
|
#region Main
|
|
|
|
|
|
|
|
|
|
|
|
public async Task GetAllPersons(PersonQueryParameters? query = null, Action<IEnumerable<PersonResponse>>? successAction = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
string url = GetUrl(EndpointsConfiguration.Persons.GetAllPersons);
|
|
|
|
|
|
|
|
|
|
|
|
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
|
|
|
|
|
|
request.Query = query;
|
|
|
|
|
|
|
|
|
|
|
|
HttpResponse response = await _httpClientService.SendRequestAsync(request);
|
|
|
|
|
|
response.RegisterActionFor2XXSuccess(successAction)
|
|
|
|
|
|
.ExecuteAction();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task GetPerson(long id, Action<PersonResponse>? successAction = null, Action? notFoundAction = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
string url = GetUrl(EndpointsConfiguration.Persons.GetPerson, id);
|
|
|
|
|
|
|
|
|
|
|
|
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
|
|
|
|
|
|
|
|
|
|
|
|
HttpResponse response = await _httpClientService.SendRequestAsync(request);
|
|
|
|
|
|
response.RegisterActionFor2XXSuccess(successAction)
|
|
|
|
|
|
.RegisterActionFor404NotFound(notFoundAction)
|
|
|
|
|
|
.ExecuteAction();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task PostPerson(PersonRequest data, Action<PersonResponse>? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
string url = GetUrl(EndpointsConfiguration.Persons.PostPerson);
|
|
|
|
|
|
|
|
|
|
|
|
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 PutPerson(long id, PersonRequest data, Action? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
string url = GetUrl(EndpointsConfiguration.Persons.PutPerson, id);
|
|
|
|
|
|
|
|
|
|
|
|
HttpRequest request = new HttpRequest(HttpMethodType.Put, url);
|
|
|
|
|
|
request.Body = data;
|
|
|
|
|
|
|
|
|
|
|
|
HttpResponse response = await _httpClientService.SendRequestAsync(request);
|
|
|
|
|
|
response.RegisterActionFor2XXSuccess(successAction)
|
|
|
|
|
|
.RegisterActionFor400BadRequest(badRequestAction)
|
|
|
|
|
|
.RegisterActionFor401Unauthorized(unauthorizedAction)
|
|
|
|
|
|
.RegisterActionFor403Forbidden(forbiddenAction)
|
|
|
|
|
|
.ExecuteAction();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task DeletePerson(long id, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
string url = GetUrl(EndpointsConfiguration.Persons.DeletePerson, id);
|
|
|
|
|
|
|
|
|
|
|
|
HttpRequest request = new HttpRequest(HttpMethodType.Delete, url);
|
|
|
|
|
|
|
|
|
|
|
|
HttpResponse response = await _httpClientService.SendRequestAsync(request);
|
|
|
|
|
|
response.RegisterActionFor2XXSuccess(successAction)
|
|
|
|
|
|
.RegisterActionFor401Unauthorized(unauthorizedAction)
|
|
|
|
|
|
.RegisterActionFor403Forbidden(forbiddenAction)
|
|
|
|
|
|
.ExecuteAction();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region View count
|
|
|
|
|
|
|
|
|
|
|
|
public async Task GetPersonsViewRank(int? first = null, int? days = null, Action<IEnumerable<PersonResponse>>? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
string url = GetUrl(EndpointsConfiguration.Persons.GetPersonsViewRank);
|
|
|
|
|
|
if (first.HasValue || days.HasValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
StringBuilder urlBuilder = new StringBuilder(url);
|
|
|
|
|
|
urlBuilder.Append('?');
|
|
|
|
|
|
bool firstParameter = true;
|
|
|
|
|
|
if (first.HasValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
urlBuilder.Append($"first={first.Value}");
|
|
|
|
|
|
firstParameter = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (days.HasValue)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!firstParameter)
|
|
|
|
|
|
{
|
|
|
|
|
|
urlBuilder.Append('&');
|
|
|
|
|
|
}
|
|
|
|
|
|
urlBuilder.Append($"days={days.Value}");
|
|
|
|
|
|
}
|
|
|
|
|
|
url = urlBuilder.ToString();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
|
|
|
|
|
|
|
|
|
|
|
|
HttpResponse response = await _httpClientService.SendRequestAsync(request);
|
|
|
|
|
|
response.RegisterActionFor2XXSuccess(successAction)
|
|
|
|
|
|
.RegisterActionFor400BadRequest(badRequestAction)
|
|
|
|
|
|
.ExecuteAction();
|
|
|
|
|
|
}
|
2024-10-19 17:29:36 +02:00
|
|
|
|
|
2024-10-22 02:34:02 +02:00
|
|
|
|
public async Task PostPersonView(long personId, Action? successAction = null, Action? notFoundAction = null)
|
2024-10-19 17:29:36 +02:00
|
|
|
|
{
|
|
|
|
|
|
string url = GetUrl(EndpointsConfiguration.Persons.PostPersonsView, personId);
|
|
|
|
|
|
|
|
|
|
|
|
HttpRequest request = new HttpRequest(HttpMethodType.Post, url);
|
|
|
|
|
|
|
|
|
|
|
|
HttpResponse response = await _httpClientService.SendRequestAsync(request);
|
|
|
|
|
|
response.RegisterActionFor2XXSuccess(successAction)
|
|
|
|
|
|
.RegisterActionFor404NotFound(notFoundAction)
|
|
|
|
|
|
.ExecuteAction();
|
|
|
|
|
|
}
|
2024-10-03 16:18:17 +02:00
|
|
|
|
|
2024-10-03 21:05:04 +02:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Photo
|
|
|
|
|
|
|
|
|
|
|
|
public async Task GetPersonPhoto(long id, Action<PersonPhotoResponse>? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? notFoundAction = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
string url = GetUrl(EndpointsConfiguration.Persons.GetPersonPhoto, id);
|
|
|
|
|
|
|
|
|
|
|
|
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
|
|
|
|
|
|
|
|
|
|
|
|
HttpResponse response = await _httpClientService.SendRequestAsync(request);
|
|
|
|
|
|
response.RegisterActionFor2XXSuccess(successAction)
|
|
|
|
|
|
.RegisterActionFor400BadRequest(badRequestAction)
|
|
|
|
|
|
.RegisterActionFor404NotFound(notFoundAction)
|
|
|
|
|
|
.ExecuteAction();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task PutPersonPhoto(long id, PersonPhotoRequest data, Action<PersonPhotoResponse>? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
string url = GetUrl(EndpointsConfiguration.Persons.PutPersonPhoto, id);
|
|
|
|
|
|
|
|
|
|
|
|
HttpRequest request = new HttpRequest(HttpMethodType.Put, url)
|
|
|
|
|
|
{
|
|
|
|
|
|
Body = data
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
HttpResponse response = await _httpClientService.SendRequestAsync(request);
|
|
|
|
|
|
response.RegisterActionFor2XXSuccess(successAction)
|
|
|
|
|
|
.RegisterActionFor400BadRequest(badRequestAction)
|
|
|
|
|
|
.RegisterActionFor401Unauthorized(unauthorizedAction)
|
|
|
|
|
|
.RegisterActionFor403Forbidden(forbiddenAction)
|
|
|
|
|
|
.ExecuteAction();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task DeletePersonPhoto(long id, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
string url = GetUrl(EndpointsConfiguration.Persons.DeletePersonPhoto, id);
|
|
|
|
|
|
|
|
|
|
|
|
HttpRequest request = new HttpRequest(HttpMethodType.Delete, url);
|
|
|
|
|
|
|
|
|
|
|
|
HttpResponse response = await _httpClientService.SendRequestAsync(request);
|
|
|
|
|
|
response.RegisterActionFor2XXSuccess(successAction)
|
|
|
|
|
|
.RegisterActionFor401Unauthorized(unauthorizedAction)
|
|
|
|
|
|
.RegisterActionFor403Forbidden(forbiddenAction)
|
|
|
|
|
|
.ExecuteAction();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-06 23:16:53 +02:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region Roles
|
|
|
|
|
|
|
|
|
|
|
|
public async Task GetPersonAllActorRoles(long id, ActorRolePersonQueryParameters? query = null, Action<IEnumerable<ActorRoleResponse>>? successAction = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
string url = GetUrl(EndpointsConfiguration.Persons.GetPersonAllActorRoles, id);
|
|
|
|
|
|
|
|
|
|
|
|
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
|
|
|
|
|
|
request.Query = query;
|
|
|
|
|
|
|
|
|
|
|
|
HttpResponse response = await _httpClientService.SendRequestAsync(request);
|
|
|
|
|
|
response.RegisterActionFor2XXSuccess(successAction)
|
|
|
|
|
|
.ExecuteAction();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-08 19:56:14 +02:00
|
|
|
|
public async Task PostPersonActorRole(long id, ActorRolePersonRequest data, Action<ActorRoleResponse>? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null)
|
2024-10-06 23:16:53 +02:00
|
|
|
|
{
|
|
|
|
|
|
string url = GetUrl(EndpointsConfiguration.Persons.PostPersonActorRole, id);
|
|
|
|
|
|
|
|
|
|
|
|
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 GetPersonAllCreatorRoles(long id, CreatorRolePersonQueryParameters? query = null, Action<IEnumerable<CreatorRoleResponse>>? successAction = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
string url = GetUrl(EndpointsConfiguration.Persons.GetPersonAllCreatorRoles, id);
|
|
|
|
|
|
|
|
|
|
|
|
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
|
|
|
|
|
|
request.Query = query;
|
|
|
|
|
|
|
|
|
|
|
|
HttpResponse response = await _httpClientService.SendRequestAsync(request);
|
|
|
|
|
|
response.RegisterActionFor2XXSuccess(successAction)
|
|
|
|
|
|
.ExecuteAction();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-08 19:56:14 +02:00
|
|
|
|
public async Task PostPersonCreatorRole(long id, CreatorRolePersonRequest data, Action<CreatorRoleResponse>? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null)
|
2024-10-06 23:16:53 +02:00
|
|
|
|
{
|
|
|
|
|
|
string url = GetUrl(EndpointsConfiguration.Persons.PostPersonCreatorRole, id);
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-10-03 16:18:17 +02:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
2024-10-23 02:39:15 +02:00
|
|
|
|
#region Rating
|
|
|
|
|
|
|
|
|
|
|
|
public async Task GetPersonGlobalRating(long id, Action<RatingResponse>? successAction = null, Action? notFoundAction = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
string url = GetUrl(EndpointsConfiguration.Persons.GetPersonGlobalRating, id);
|
|
|
|
|
|
|
|
|
|
|
|
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
|
|
|
|
|
|
|
|
|
|
|
|
HttpResponse response = await _httpClientService.SendRequestAsync(request);
|
|
|
|
|
|
response.RegisterActionFor2XXSuccess(successAction)
|
|
|
|
|
|
.RegisterActionFor404NotFound(notFoundAction)
|
|
|
|
|
|
.ExecuteAction();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task GetPersonUserRating(long id, long userId, Action<RatingResponse>? successAction = null, Action? notFoundAction = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
string url = GetUrl(EndpointsConfiguration.Persons.GetPersonUserRating, id, userId);
|
|
|
|
|
|
|
|
|
|
|
|
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
|
|
|
|
|
|
|
|
|
|
|
|
HttpResponse response = await _httpClientService.SendRequestAsync(request);
|
|
|
|
|
|
response.RegisterActionFor2XXSuccess(successAction)
|
|
|
|
|
|
.RegisterActionFor404NotFound(notFoundAction)
|
|
|
|
|
|
.ExecuteAction();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
2024-10-03 16:18:17 +02:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region PRIVATE METHODS
|
|
|
|
|
|
|
|
|
|
|
|
protected override string GetServiceBase() => EndpointsConfiguration.Persons.Base;
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|