2024-07-03 22:18:32 +02:00
|
|
|
|
using WatchIt.Common.Model.Accounts;
|
2024-11-01 01:03:00 +01:00
|
|
|
|
using WatchIt.Common.Model.Movies;
|
2024-11-01 20:44:01 +01:00
|
|
|
|
using WatchIt.Common.Model.Persons;
|
2024-11-01 01:03:00 +01:00
|
|
|
|
using WatchIt.Common.Model.Series;
|
2024-07-03 22:18:32 +02:00
|
|
|
|
using WatchIt.Common.Services.HttpClient;
|
2024-10-27 22:09:46 +01:00
|
|
|
|
using WatchIt.Website.Services.Configuration;
|
|
|
|
|
|
using WatchIt.Website.Services.Tokens;
|
2024-07-03 22:18:32 +02:00
|
|
|
|
|
2024-10-27 22:09:46 +01:00
|
|
|
|
namespace WatchIt.Website.Services.Client.Accounts;
|
2024-07-03 22:18:32 +02:00
|
|
|
|
|
2024-10-27 22:09:46 +01:00
|
|
|
|
public class AccountsClientService(IHttpClientService httpClientService, IConfigurationService configurationService, ITokensService tokensService) : BaseClientService(configurationService), IAccountsClientService
|
2024-07-03 22:18:32 +02:00
|
|
|
|
{
|
|
|
|
|
|
#region PUBLIC METHODS
|
|
|
|
|
|
|
2024-07-30 16:19:51 +02:00
|
|
|
|
public async Task Register(RegisterRequest data, Action<RegisterResponse>? createdAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null)
|
2024-07-03 22:18:32 +02:00
|
|
|
|
{
|
|
|
|
|
|
string url = GetUrl(EndpointsConfiguration.Accounts.Register);
|
|
|
|
|
|
HttpRequest request = new HttpRequest(HttpMethodType.Post, url)
|
|
|
|
|
|
{
|
|
|
|
|
|
Body = data,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
HttpResponse response = await httpClientService.SendRequestAsync(request);
|
|
|
|
|
|
response.RegisterActionFor2XXSuccess(createdAction)
|
|
|
|
|
|
.RegisterActionFor400BadRequest(badRequestAction)
|
|
|
|
|
|
.ExecuteAction();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-30 16:19:51 +02:00
|
|
|
|
public async Task Authenticate(AuthenticateRequest data, Action<AuthenticateResponse>? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? unauthorizedAction = null)
|
2024-07-03 22:18:32 +02:00
|
|
|
|
{
|
|
|
|
|
|
string url = GetUrl(EndpointsConfiguration.Accounts.Authenticate);
|
|
|
|
|
|
HttpRequest request = new HttpRequest(HttpMethodType.Post, url)
|
|
|
|
|
|
{
|
|
|
|
|
|
Body = data,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
HttpResponse response = await httpClientService.SendRequestAsync(request);
|
|
|
|
|
|
response.RegisterActionFor2XXSuccess(successAction)
|
|
|
|
|
|
.RegisterActionFor400BadRequest(badRequestAction)
|
|
|
|
|
|
.RegisterActionFor401Unauthorized(unauthorizedAction)
|
|
|
|
|
|
.ExecuteAction();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-30 16:19:51 +02:00
|
|
|
|
public async Task AuthenticateRefresh(Action<AuthenticateResponse>? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null)
|
2024-07-03 22:18:32 +02:00
|
|
|
|
{
|
|
|
|
|
|
string url = GetUrl(EndpointsConfiguration.Accounts.AuthenticateRefresh);
|
2024-07-30 16:19:51 +02:00
|
|
|
|
string? token = await tokensService.GetRefreshToken();
|
|
|
|
|
|
|
2024-07-03 22:18:32 +02:00
|
|
|
|
HttpRequest request = new HttpRequest(HttpMethodType.Post, url);
|
2024-07-30 16:19:51 +02:00
|
|
|
|
request.Headers.Add("Authorization", $"Bearer {token}");
|
2024-07-03 22:18:32 +02:00
|
|
|
|
|
|
|
|
|
|
HttpResponse response = await httpClientService.SendRequestAsync(request);
|
|
|
|
|
|
response.RegisterActionFor2XXSuccess(successAction)
|
|
|
|
|
|
.RegisterActionFor401Unauthorized(unauthorizedAction)
|
|
|
|
|
|
.RegisterActionFor403Forbidden(forbiddenAction)
|
|
|
|
|
|
.ExecuteAction();
|
|
|
|
|
|
}
|
2024-07-30 16:19:51 +02:00
|
|
|
|
|
|
|
|
|
|
public async Task Logout(Action? successAction = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
string url = GetUrl(EndpointsConfiguration.Accounts.Logout);
|
|
|
|
|
|
string? token = await tokensService.GetRefreshToken();
|
|
|
|
|
|
|
|
|
|
|
|
HttpRequest request = new HttpRequest(HttpMethodType.Delete, url);
|
|
|
|
|
|
request.Headers.Add("Authorization", $"Bearer {token}");
|
|
|
|
|
|
|
|
|
|
|
|
HttpResponse response = await httpClientService.SendRequestAsync(request);
|
|
|
|
|
|
response.RegisterActionFor2XXSuccess(successAction)
|
|
|
|
|
|
.ExecuteAction();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task GetAccountProfilePicture(long id, Action<AccountProfilePictureResponse>? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? notFoundAction = null)
|
|
|
|
|
|
{
|
2024-11-03 23:01:34 +01:00
|
|
|
|
string url = GetUrl(EndpointsConfiguration.Accounts.GetAccountProfilePicture, id);
|
2024-07-30 16:19:51 +02:00
|
|
|
|
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
|
|
|
|
|
|
|
|
|
|
|
|
HttpResponse response = await httpClientService.SendRequestAsync(request);
|
|
|
|
|
|
response.RegisterActionFor2XXSuccess(successAction)
|
|
|
|
|
|
.RegisterActionFor400BadRequest(badRequestAction)
|
|
|
|
|
|
.RegisterActionFor404NotFound(notFoundAction)
|
|
|
|
|
|
.ExecuteAction();
|
|
|
|
|
|
}
|
2024-11-03 23:01:34 +01:00
|
|
|
|
|
|
|
|
|
|
public async Task PutAccountProfilePicture(AccountProfilePictureRequest data, Action<AccountProfilePictureResponse>? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? unauthorizedAction = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
string url = GetUrl(EndpointsConfiguration.Accounts.PutAccountProfilePicture);
|
|
|
|
|
|
|
|
|
|
|
|
HttpRequest request = new HttpRequest(HttpMethodType.Put, url)
|
|
|
|
|
|
{
|
|
|
|
|
|
Body = data
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
HttpResponse response = await httpClientService.SendRequestAsync(request);
|
|
|
|
|
|
response.RegisterActionFor2XXSuccess(successAction)
|
|
|
|
|
|
.RegisterActionFor400BadRequest(badRequestAction)
|
|
|
|
|
|
.RegisterActionFor401Unauthorized(unauthorizedAction)
|
|
|
|
|
|
.ExecuteAction();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task DeleteAccountProfilePicture(Action? successAction = null, Action? unauthorizedAction = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
string url = GetUrl(EndpointsConfiguration.Accounts.DeleteAccountProfilePicture);
|
|
|
|
|
|
|
|
|
|
|
|
HttpRequest request = new HttpRequest(HttpMethodType.Delete, url);
|
|
|
|
|
|
|
|
|
|
|
|
HttpResponse response = await httpClientService.SendRequestAsync(request);
|
|
|
|
|
|
response.RegisterActionFor2XXSuccess(successAction)
|
|
|
|
|
|
.RegisterActionFor401Unauthorized(unauthorizedAction)
|
|
|
|
|
|
.ExecuteAction();
|
|
|
|
|
|
}
|
2024-07-03 22:18:32 +02:00
|
|
|
|
|
2024-11-01 01:03:00 +01:00
|
|
|
|
public async Task GetAccountInfo(long id, Action<AccountResponse>? successAction = null, Action? notFoundAction = null)
|
2024-10-27 20:22:55 +01:00
|
|
|
|
{
|
2024-11-01 01:03:00 +01:00
|
|
|
|
string url = GetUrl(EndpointsConfiguration.Accounts.GetAccountInfo, id);
|
2024-10-27 20:22:55 +01:00
|
|
|
|
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
|
|
|
|
|
|
|
|
|
|
|
|
HttpResponse response = await httpClientService.SendRequestAsync(request);
|
|
|
|
|
|
response.RegisterActionFor2XXSuccess(successAction)
|
|
|
|
|
|
.RegisterActionFor404NotFound(notFoundAction)
|
|
|
|
|
|
.ExecuteAction();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-03 23:01:34 +01:00
|
|
|
|
public async Task PutAccountProfileInfo(AccountProfileInfoRequest data, Action? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? unauthorizedAction = null)
|
2024-10-27 20:22:55 +01:00
|
|
|
|
{
|
2024-11-03 23:01:34 +01:00
|
|
|
|
string url = GetUrl(EndpointsConfiguration.Accounts.PutAccountProfileInfo);
|
2024-11-01 01:03:00 +01:00
|
|
|
|
HttpRequest request = new HttpRequest(HttpMethodType.Put, url)
|
|
|
|
|
|
{
|
|
|
|
|
|
Body = data,
|
|
|
|
|
|
};
|
2024-10-27 20:22:55 +01:00
|
|
|
|
|
|
|
|
|
|
HttpResponse response = await httpClientService.SendRequestAsync(request);
|
|
|
|
|
|
response.RegisterActionFor2XXSuccess(successAction)
|
2024-11-01 01:03:00 +01:00
|
|
|
|
.RegisterActionFor400BadRequest(badRequestAction)
|
2024-10-27 20:22:55 +01:00
|
|
|
|
.RegisterActionFor401Unauthorized(unauthorizedAction)
|
|
|
|
|
|
.ExecuteAction();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-01 01:03:00 +01:00
|
|
|
|
public async Task GetAccountRatedMovies(long id, MovieRatedQueryParameters query, Action<IEnumerable<MovieRatedResponse>>? successAction = null, Action? notFoundAction = null)
|
2024-10-27 20:22:55 +01:00
|
|
|
|
{
|
2024-11-01 01:03:00 +01:00
|
|
|
|
string url = GetUrl(EndpointsConfiguration.Accounts.GetAccountRatedMovies, id);
|
|
|
|
|
|
HttpRequest request = new HttpRequest(HttpMethodType.Get, url)
|
2024-10-27 20:22:55 +01:00
|
|
|
|
{
|
2024-11-01 01:03:00 +01:00
|
|
|
|
Query = query
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
HttpResponse response = await httpClientService.SendRequestAsync(request);
|
|
|
|
|
|
response.RegisterActionFor2XXSuccess(successAction)
|
|
|
|
|
|
.RegisterActionFor404NotFound(notFoundAction)
|
|
|
|
|
|
.ExecuteAction();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task GetAccountRatedSeries(long id, SeriesRatedQueryParameters query, Action<IEnumerable<SeriesRatedResponse>>? successAction = null, Action? notFoundAction = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
string url = GetUrl(EndpointsConfiguration.Accounts.GetAccountRatedSeries, id);
|
|
|
|
|
|
HttpRequest request = new HttpRequest(HttpMethodType.Get, url)
|
|
|
|
|
|
{
|
|
|
|
|
|
Query = query
|
2024-10-27 20:22:55 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
HttpResponse response = await httpClientService.SendRequestAsync(request);
|
|
|
|
|
|
response.RegisterActionFor2XXSuccess(successAction)
|
|
|
|
|
|
.RegisterActionFor404NotFound(notFoundAction)
|
|
|
|
|
|
.ExecuteAction();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-11-01 20:44:01 +01:00
|
|
|
|
public async Task GetAccountRatedPersons(long id, PersonRatedQueryParameters query, Action<IEnumerable<PersonRatedResponse>>? successAction = null, Action? notFoundAction = null)
|
|
|
|
|
|
{
|
|
|
|
|
|
string url = GetUrl(EndpointsConfiguration.Accounts.GetAccountRatedPersons, id);
|
|
|
|
|
|
HttpRequest request = new HttpRequest(HttpMethodType.Get, url)
|
|
|
|
|
|
{
|
|
|
|
|
|
Query = query
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
HttpResponse response = await httpClientService.SendRequestAsync(request);
|
|
|
|
|
|
response.RegisterActionFor2XXSuccess(successAction)
|
|
|
|
|
|
.RegisterActionFor404NotFound(notFoundAction)
|
|
|
|
|
|
.ExecuteAction();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-03 22:18:32 +02:00
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region PRIVATE METHODS
|
|
|
|
|
|
|
|
|
|
|
|
protected override string GetServiceBase() => EndpointsConfiguration.Accounts.Base;
|
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
}
|