152 lines
5.9 KiB
C#
152 lines
5.9 KiB
C#
|
|
using WatchIt.Common.Model.Roles;
|
|||
|
|
using WatchIt.Common.Services.HttpClient;
|
|||
|
|
using WatchIt.Website.Services.Utility.Configuration;
|
|||
|
|
using WatchIt.Website.Services.WebAPI.Common;
|
|||
|
|
|
|||
|
|
namespace WatchIt.Website.Services.WebAPI.Roles;
|
|||
|
|
|
|||
|
|
public class RolesWebAPIService : BaseWebAPIService, IRolesWebAPIService
|
|||
|
|
{
|
|||
|
|
#region SERVICES
|
|||
|
|
|
|||
|
|
private IHttpClientService _httpClientService;
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
#region CONSTRUCTORS
|
|||
|
|
|
|||
|
|
public RolesWebAPIService(IHttpClientService httpClientService, IConfigurationService configurationService) : base(configurationService)
|
|||
|
|
{
|
|||
|
|
_httpClientService = httpClientService;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
#region PUBLIC METHODS
|
|||
|
|
|
|||
|
|
#region Actor
|
|||
|
|
|
|||
|
|
public async Task GetAllActorRoles(RoleQueryParameters? query = null, Action<IEnumerable<RoleResponse>>? successAction = null)
|
|||
|
|
{
|
|||
|
|
string url = GetUrl(EndpointsConfiguration.Roles.GetAllActorRoles);
|
|||
|
|
|
|||
|
|
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
|
|||
|
|
request.Query = query;
|
|||
|
|
|
|||
|
|
HttpResponse response = await _httpClientService.SendRequestAsync(request);
|
|||
|
|
response.RegisterActionFor2XXSuccess(successAction)
|
|||
|
|
.ExecuteAction();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public async Task GetActorRole(long id, Action<RoleResponse>? successAction = null, Action? notFoundAction = null)
|
|||
|
|
{
|
|||
|
|
string url = GetUrl(EndpointsConfiguration.Roles.GetActorRole, id);
|
|||
|
|
|
|||
|
|
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
|
|||
|
|
|
|||
|
|
HttpResponse response = await _httpClientService.SendRequestAsync(request);
|
|||
|
|
response.RegisterActionFor2XXSuccess(successAction)
|
|||
|
|
.RegisterActionFor404NotFound(notFoundAction)
|
|||
|
|
.ExecuteAction();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public async Task PostActorRole(RoleRequest data, Action<RoleResponse>? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null)
|
|||
|
|
{
|
|||
|
|
string url = GetUrl(EndpointsConfiguration.Roles.PostActorRole);
|
|||
|
|
|
|||
|
|
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 DeleteActorRole(long id, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null)
|
|||
|
|
{
|
|||
|
|
string url = GetUrl(EndpointsConfiguration.Roles.DeleteActorRole, id);
|
|||
|
|
|
|||
|
|
HttpRequest request = new HttpRequest(HttpMethodType.Delete, url);
|
|||
|
|
|
|||
|
|
HttpResponse response = await _httpClientService.SendRequestAsync(request);
|
|||
|
|
response.RegisterActionFor2XXSuccess(successAction)
|
|||
|
|
.RegisterActionFor401Unauthorized(unauthorizedAction)
|
|||
|
|
.RegisterActionFor403Forbidden(forbiddenAction)
|
|||
|
|
.ExecuteAction();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#region Creator
|
|||
|
|
|
|||
|
|
public async Task GetAllCreatorRoles(RoleQueryParameters? query = null, Action<IEnumerable<RoleResponse>>? successAction = null)
|
|||
|
|
{
|
|||
|
|
string url = GetUrl(EndpointsConfiguration.Roles.GetAllCreatorRoles);
|
|||
|
|
|
|||
|
|
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
|
|||
|
|
request.Query = query;
|
|||
|
|
|
|||
|
|
HttpResponse response = await _httpClientService.SendRequestAsync(request);
|
|||
|
|
response.RegisterActionFor2XXSuccess(successAction)
|
|||
|
|
.ExecuteAction();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public async Task GetCreatorRole(long id, Action<RoleResponse>? successAction = null, Action? notFoundAction = null)
|
|||
|
|
{
|
|||
|
|
string url = GetUrl(EndpointsConfiguration.Roles.GetCreatorRole, id);
|
|||
|
|
|
|||
|
|
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
|
|||
|
|
|
|||
|
|
HttpResponse response = await _httpClientService.SendRequestAsync(request);
|
|||
|
|
response.RegisterActionFor2XXSuccess(successAction)
|
|||
|
|
.RegisterActionFor404NotFound(notFoundAction)
|
|||
|
|
.ExecuteAction();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public async Task PostCreatorRole(RoleRequest data, Action<RoleResponse>? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null)
|
|||
|
|
{
|
|||
|
|
string url = GetUrl(EndpointsConfiguration.Roles.PostCreatorRole);
|
|||
|
|
|
|||
|
|
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 DeleteCreatorRole(long id, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null)
|
|||
|
|
{
|
|||
|
|
string url = GetUrl(EndpointsConfiguration.Roles.DeleteCreatorRole, id);
|
|||
|
|
|
|||
|
|
HttpRequest request = new HttpRequest(HttpMethodType.Delete, url);
|
|||
|
|
|
|||
|
|
HttpResponse response = await _httpClientService.SendRequestAsync(request);
|
|||
|
|
response.RegisterActionFor2XXSuccess(successAction)
|
|||
|
|
.RegisterActionFor401Unauthorized(unauthorizedAction)
|
|||
|
|
.RegisterActionFor403Forbidden(forbiddenAction)
|
|||
|
|
.ExecuteAction();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
#region PRIVATE METHODS
|
|||
|
|
|
|||
|
|
protected override string GetServiceBase() => EndpointsConfiguration.Roles.Base;
|
|||
|
|
|
|||
|
|
#endregion
|
|||
|
|
}
|