gender controller finished

This commit is contained in:
2024-10-05 09:12:28 +02:00
Unverified
parent b43b319855
commit 065c27642e
16 changed files with 389 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ public class Endpoints
{
public string Base { get; set; }
public Accounts Accounts { get; set; }
public Genders Genders { get; set; }
public Genres Genres { get; set; }
public Media Media { get; set; }
public Movies Movies { get; set; }

View File

@@ -0,0 +1,10 @@
namespace WatchIt.Website.Services.Utility.Configuration.Model;
public class Genders
{
public string Base { get; set; }
public string GetAllGenders { get; set; }
public string GetGender { get; set; }
public string PostGender { get; set; }
public string DeleteGender { get; set; }
}

View File

@@ -0,0 +1,98 @@
using WatchIt.Common.Model.Genders;
using WatchIt.Common.Services.HttpClient;
using WatchIt.Website.Services.Utility.Configuration;
using WatchIt.Website.Services.WebAPI.Common;
namespace WatchIt.Website.Services.WebAPI.Genders;
public class GendersWebAPIService : BaseWebAPIService, IGendersWebAPIService
{
#region SERVICES
private IHttpClientService _httpClientService;
private IConfigurationService _configurationService;
#endregion
#region CONSTRUCTORS
public GendersWebAPIService(IHttpClientService httpClientService, IConfigurationService configurationService) : base(configurationService)
{
_httpClientService = httpClientService;
_configurationService = configurationService;
}
#endregion
#region PUBLIC METHODS
#region Main
public async Task GetAllGenders(GenderQueryParameters? query = null, Action<IEnumerable<GenderResponse>>? successAction = null)
{
string url = GetUrl(EndpointsConfiguration.Genders.GetAllGenders);
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
request.Query = query;
HttpResponse response = await _httpClientService.SendRequestAsync(request);
response.RegisterActionFor2XXSuccess(successAction)
.ExecuteAction();
}
public async Task GetGender(long id, Action<GenderResponse>? successAction = null, Action? notFoundAction = null)
{
string url = GetUrl(EndpointsConfiguration.Genders.GetGender, id);
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
HttpResponse response = await _httpClientService.SendRequestAsync(request);
response.RegisterActionFor2XXSuccess(successAction)
.RegisterActionFor404NotFound(notFoundAction)
.ExecuteAction();
}
public async Task PostGender(GenderRequest data, Action<GenderResponse>? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null)
{
string url = GetUrl(EndpointsConfiguration.Genders.PostGender);
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 DeleteGender(long id, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null)
{
string url = GetUrl(EndpointsConfiguration.Genders.DeleteGender, 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.Genders.Base;
#endregion
}

View File

@@ -0,0 +1,11 @@
using WatchIt.Common.Model.Genders;
namespace WatchIt.Website.Services.WebAPI.Genders;
public interface IGendersWebAPIService
{
Task GetAllGenders(GenderQueryParameters? query = null, Action<IEnumerable<GenderResponse>>? successAction = null);
Task GetGender(long id, Action<GenderResponse>? successAction = null, Action? notFoundAction = null);
Task PostGender(GenderRequest data, Action<GenderResponse>? successAction = null, Action<IDictionary<string, string[]>>? badRequestAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null);
Task DeleteGender(long id, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null);
}

View File

@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\WatchIt.Common\WatchIt.Common.Services\WatchIt.Common.Services.HttpClient\WatchIt.Common.Services.HttpClient.csproj" />
<ProjectReference Include="..\WatchIt.Website.Services.WebAPI.Common\WatchIt.Website.Services.WebAPI.Common.csproj" />
</ItemGroup>
</Project>

View File

@@ -20,6 +20,13 @@
"Logout": "/logout",
"GetProfilePicture": "/{0}/profile-picture"
},
"Genders": {
"Base": "/genders",
"GetAllGenders": "",
"GetGender": "/{0}",
"PostGender": "",
"DeleteGender": "/{0}"
},
"Genres": {
"Base": "/genres",
"GetAll": "",