This commit is contained in:
2024-07-03 22:18:32 +02:00
Unverified
parent 4b333878b8
commit 008dcdf4ec
88 changed files with 3389 additions and 644 deletions

View File

@@ -0,0 +1,13 @@
using Microsoft.Extensions.Configuration;
using WatchIt.Website.Services.Utility.Configuration.Model;
namespace WatchIt.Website.Services.Utility.Configuration;
public class ConfigurationService(IConfiguration configuration) : IConfigurationService
{
#region PROPERTIES
public ConfigurationData Data => configuration.Get<ConfigurationData>()!;
#endregion
}

View File

@@ -0,0 +1,8 @@
using WatchIt.Website.Services.Utility.Configuration.Model;
namespace WatchIt.Website.Services.Utility.Configuration;
public interface IConfigurationService
{
ConfigurationData Data { get; }
}

View File

@@ -0,0 +1,9 @@
namespace WatchIt.Website.Services.Utility.Configuration.Model;
public class Accounts
{
public string Base { get; set; }
public string Register { get; set; }
public string Authenticate { get; set; }
public string AuthenticateRefresh { get; set; }
}

View File

@@ -0,0 +1,8 @@
namespace WatchIt.Website.Services.Utility.Configuration.Model;
public class ConfigurationData
{
public Logging Logging { get; set; }
public string AllowedHosts { get; set; }
public Endpoints Endpoints { get; set; }
}

View File

@@ -0,0 +1,10 @@
namespace WatchIt.Website.Services.Utility.Configuration.Model;
public class Endpoints
{
public string Base { get; set; }
public Accounts Accounts { get; set; }
public Genres Genres { get; set; }
public Movies Movies { get; set; }
public Media Media { get; set; }
}

View File

@@ -0,0 +1,11 @@
namespace WatchIt.Website.Services.Utility.Configuration.Model;
public class Genres
{
public string Base { get; set; }
public string GetAll { get; set; }
public string Get { get; set; }
public string Post { get; set; }
public string Put { get; set; }
public string Delete { get; set; }
}

View File

@@ -0,0 +1,7 @@
namespace WatchIt.Website.Services.Utility.Configuration.Model;
public class LogLevel
{
public string Default { get; set; }
public string Microsoft_AspNetCore { get; set; }
}

View File

@@ -0,0 +1,6 @@
namespace WatchIt.Website.Services.Utility.Configuration.Model;
public class Logging
{
public LogLevel LogLevel { get; set; }
}

View File

@@ -0,0 +1,16 @@
namespace WatchIt.Website.Services.Utility.Configuration.Model;
public class Media
{
public string Base { get; set; }
public string GetGenres { get; set; }
public string PostGenre { get; set; }
public string DeleteGenre { get; set; }
public string GetPhotoMediaRandomBackground { get; set; }
public string GetPhoto { get; set; }
public string GetPhotos { get; set; }
public string GetPhotoRandomBackground { get; set; }
public string PostPhoto { get; set; }
public string PutPhoto { get; set; }
public string DeletePhoto { get; set; }
}

View File

@@ -0,0 +1,14 @@
namespace WatchIt.Website.Services.Utility.Configuration.Model;
public class Movies
{
public string Base { get; set; }
public string GetAll { get; set; }
public string Get { get; set; }
public string Post { get; set; }
public string Put { get; set; }
public string Delete { get; set; }
public string GetGenres { get; set; }
public string PostGenre { get; set; }
public string DeleteGenre { get; set; }
}

View File

@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.1" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,63 @@
using WatchIt.Common.Model.Accounts;
using WatchIt.Common.Services.HttpClient;
using WatchIt.Website.Services.Utility.Configuration;
using WatchIt.Website.Services.Utility.Configuration.Model;
using WatchIt.Website.Services.WebAPI.Common;
namespace WatchIt.Website.Services.WebAPI.Accounts;
public class AccountsWebAPIService(IHttpClientService httpClientService, IConfigurationService configurationService) : BaseWebAPIService(configurationService), IAccountsWebAPIService
{
#region PUBLIC METHODS
public async Task Register(RegisterRequest data, Action<RegisterResponse> createdAction, Action<IDictionary<string, string[]>> badRequestAction)
{
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();
}
public async Task Authenticate(AuthenticateRequest data, Action<AuthenticateResponse> successAction, Action<IDictionary<string, string[]>> badRequestAction, Action unauthorizedAction)
{
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();
}
public async Task AuthenticateRefresh(Action<AuthenticateResponse> successAction, Action unauthorizedAction, Action forbiddenAction)
{
string url = GetUrl(EndpointsConfiguration.Accounts.AuthenticateRefresh);
HttpRequest request = new HttpRequest(HttpMethodType.Post, url);
HttpResponse response = await httpClientService.SendRequestAsync(request);
response.RegisterActionFor2XXSuccess(successAction)
.RegisterActionFor401Unauthorized(unauthorizedAction)
.RegisterActionFor403Forbidden(forbiddenAction)
.ExecuteAction();
}
#endregion
#region PRIVATE METHODS
protected override string GetServiceBase() => EndpointsConfiguration.Accounts.Base;
#endregion
}

View File

@@ -0,0 +1,10 @@
using WatchIt.Common.Model.Accounts;
namespace WatchIt.Website.Services.WebAPI.Accounts;
public interface IAccountsWebAPIService
{
Task Register(RegisterRequest data, Action<RegisterResponse> createdAction, Action<IDictionary<string, string[]>> badRequestAction);
Task Authenticate(AuthenticateRequest data, Action<AuthenticateResponse> successAction, Action<IDictionary<string, string[]>> badRequestAction, Action unauthorizedAction);
Task AuthenticateRefresh(Action<AuthenticateResponse> successAction, Action unauthorizedAction, Action forbiddenAction);
}

View File

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

View File

@@ -0,0 +1,25 @@
using WatchIt.Website.Services.Utility.Configuration;
using WatchIt.Website.Services.Utility.Configuration.Model;
namespace WatchIt.Website.Services.WebAPI.Common;
public abstract class BaseWebAPIService(IConfigurationService configurationService)
{
#region FIELDS
protected Endpoints EndpointsConfiguration => configurationService.Data.Endpoints;
#endregion
#region PRIVATE METHODS
protected abstract string GetServiceBase();
protected string GetUrl(string suffix) => string.Concat(EndpointsConfiguration.Base, GetServiceBase(), suffix);
protected string GetUrl(string suffix, params object[] format) => string.Concat(EndpointsConfiguration.Base, GetServiceBase(), string.Format(suffix, format));
#endregion
}

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.WebAPI\WatchIt.WebAPI.Services\WatchIt.WebAPI.Services.Utility\WatchIt.WebAPI.Services.Utility.Configuration\WatchIt.WebAPI.Services.Utility.Configuration.csproj" />
<ProjectReference Include="..\..\WatchIt.Website.Services.Utility\WatchIt.Website.Services.Utility.Configuration\WatchIt.Website.Services.Utility.Configuration.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,11 @@
using WatchIt.Common.Model.Genres;
using WatchIt.Common.Model.Media;
namespace WatchIt.Website.Services.WebAPI.Media;
public interface IMediaWebAPIService
{
Task GetGenres(long mediaId, Action<IEnumerable<GenreResponse>> successAction, Action notFoundAction);
Task PostGenre(long mediaId, long genreId, Action successAction, Action unauthorizedAction, Action forbiddenAction, Action notFoundAction);
Task GetPhotoRandomBackground(Action<MediaPhotoResponse> successAction, Action notFoundAction);
}

View File

@@ -0,0 +1,61 @@
using WatchIt.Common.Model.Genres;
using WatchIt.Common.Model.Media;
using WatchIt.Common.Services.HttpClient;
using WatchIt.Website.Services.Utility.Configuration;
using WatchIt.Website.Services.Utility.Configuration.Model;
using WatchIt.Website.Services.WebAPI.Common;
namespace WatchIt.Website.Services.WebAPI.Media;
public class MediaWebAPIService(IHttpClientService httpClientService, IConfigurationService configurationService) : BaseWebAPIService(configurationService), IMediaWebAPIService
{
#region PUBLIC METHODS
public async Task GetGenres(long mediaId, Action<IEnumerable<GenreResponse>>? successAction = null, Action? notFoundAction = null)
{
string url = GetUrl(EndpointsConfiguration.Media.GetGenres, mediaId);
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
HttpResponse response = await httpClientService.SendRequestAsync(request);
response.RegisterActionFor2XXSuccess(successAction)
.RegisterActionFor404NotFound(notFoundAction)
.ExecuteAction();
}
public async Task PostGenre(long mediaId, long genreId, Action? successAction = null, Action? unauthorizedAction = null, Action? forbiddenAction = null, Action? notFoundAction = null)
{
string url = GetUrl(EndpointsConfiguration.Media.PostGenre, mediaId, genreId);
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
HttpResponse response = await httpClientService.SendRequestAsync(request);
response.RegisterActionFor2XXSuccess(successAction)
.RegisterActionFor401Unauthorized(unauthorizedAction)
.RegisterActionFor403Forbidden(forbiddenAction)
.RegisterActionFor404NotFound(notFoundAction)
.ExecuteAction();
}
public async Task GetPhotoRandomBackground(Action<MediaPhotoResponse>? successAction = null, Action? notFoundAction = null)
{
string url = GetUrl(EndpointsConfiguration.Media.GetPhotoRandomBackground);
HttpRequest request = new HttpRequest(HttpMethodType.Get, url);
HttpResponse response = await httpClientService.SendRequestAsync(request);
response.RegisterActionFor2XXSuccess(successAction)
.RegisterActionFor404NotFound(notFoundAction)
.ExecuteAction();
}
#endregion
#region PRIVATE METHODS
protected override string GetServiceBase() => EndpointsConfiguration.Media.Base;
#endregion
}

View File

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

View File

@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>