Added inital job entity and services. Added released works API integration.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
using JSMR.Application.Integrations.Chobit.Models;
|
||||
using JSMR.Application.Integrations.Ports;
|
||||
using JSMR.Application.Integrations.Chobit.Ports;
|
||||
using JSMR.Infrastructure.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
using JSMR.Application.Integrations.DLSite.Models;
|
||||
using JSMR.Application.Integrations.Ports;
|
||||
using JSMR.Application.Integrations.DLSite.Models.ReleasedWorks;
|
||||
using JSMR.Application.Integrations.DLSite.Ports;
|
||||
using JSMR.Infrastructure.Globalization;
|
||||
using JSMR.Infrastructure.Http;
|
||||
using JSMR.Infrastructure.Integrations.DLSite.Mapping;
|
||||
using JSMR.Infrastructure.Integrations.DLSite.Models;
|
||||
using JSMR.Infrastructure.Integrations.DLSite.Models.NewWorks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace JSMR.Infrastructure.Integrations.DLSite;
|
||||
@@ -23,4 +26,23 @@ public class DLSiteClient(HttpClient http, ILogger<DLSiteClient> logger) : ApiCl
|
||||
|
||||
return DLSiteToDomainMapper.Map(productInfoCollection);
|
||||
}
|
||||
|
||||
public async Task<ReleasedWorksCollection> GetReleasedWorksAsync(ReleasedWorksRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
string locale = LocaleMapper.ToDLSiteLocale(request.Locale);
|
||||
string date = request.Date.ToString("yyyy-MM-dd");
|
||||
string url = $"maniax/new/work/api?locale={locale}&date={date}&period={request.Period}";
|
||||
|
||||
NewWorksApiResponse response = await GetJsonAsync<NewWorksApiResponse>(url, cancellationToken: cancellationToken);
|
||||
|
||||
if (response.Meta.Code != 200)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"DLsite returned code {response.Meta.Code}. " +
|
||||
$"ErrorType: {response.Meta.ErrorType}. " +
|
||||
$"ErrorMessage: {response.Meta.ErrorMessage}");
|
||||
}
|
||||
|
||||
return DLSiteReleasedWorksMapper.Map(response);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
using JSMR.Application.Integrations.Ports;
|
||||
using JSMR.Infrastructure.Integrations.DLSite.Serialization;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
//using JSMR.Application.Integrations.Ports;
|
||||
//using JSMR.Infrastructure.Integrations.DLSite.Serialization;
|
||||
//using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace JSMR.Infrastructure.Integrations.DLSite;
|
||||
//namespace JSMR.Infrastructure.Integrations.DLSite;
|
||||
|
||||
public static class DLSiteClientRegistration
|
||||
{
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
using JSMR.Application.Integrations.DLSite.Models.ReleasedWorks;
|
||||
using JSMR.Infrastructure.Integrations.DLSite.Models.NewWorks;
|
||||
|
||||
namespace JSMR.Infrastructure.Integrations.DLSite.Mapping;
|
||||
|
||||
public static class DLSiteReleasedWorksMapper
|
||||
{
|
||||
public static ReleasedWorksCollection Map(NewWorksApiResponse response)
|
||||
{
|
||||
ReleasedWorksCollection result = [];
|
||||
|
||||
if (response.Data.Products.Length == 0)
|
||||
return result;
|
||||
|
||||
foreach (NewWorksApiProduct product in response.Data.Products)
|
||||
{
|
||||
result.Add(product.Id, Map(product));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static ReleasedWork Map(NewWorksApiProduct product)
|
||||
{
|
||||
return new ReleasedWork
|
||||
{
|
||||
ProductId = product.Id,
|
||||
Title = product.Name ?? string.Empty,
|
||||
MaskedTitle = product.NameMasked ?? string.Empty,
|
||||
Description = product.Description ?? string.Empty,
|
||||
MaskedDescription = product.DescriptionMasked ?? string.Empty
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace JSMR.Infrastructure.Integrations.DLSite.Models.NewWorks;
|
||||
|
||||
public record NewWorksApiData
|
||||
{
|
||||
[JsonPropertyName("products")]
|
||||
public required NewWorksApiProduct[] Products { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace JSMR.Infrastructure.Integrations.DLSite.Models.NewWorks;
|
||||
|
||||
public record NewWorksApiMeta
|
||||
{
|
||||
[JsonPropertyName("code")]
|
||||
public int Code { get; init; }
|
||||
|
||||
[JsonPropertyName("errorMessage")]
|
||||
public string ErrorMessage { get; init; } = string.Empty;
|
||||
|
||||
[JsonPropertyName("errorType")]
|
||||
public string ErrorType { get; init; } = string.Empty;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace JSMR.Infrastructure.Integrations.DLSite.Models.NewWorks;
|
||||
|
||||
public record NewWorksApiProduct
|
||||
{
|
||||
[JsonPropertyName("id")]
|
||||
public required string Id { get; init; }
|
||||
|
||||
[JsonPropertyName("name")]
|
||||
public string? Name { get; init; }
|
||||
|
||||
[JsonPropertyName("nameMasked")]
|
||||
public string? NameMasked { get; init; }
|
||||
|
||||
[JsonPropertyName("description")]
|
||||
public string? Description { get; init; }
|
||||
|
||||
[JsonPropertyName("descriptionMasked")]
|
||||
public string? DescriptionMasked { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace JSMR.Infrastructure.Integrations.DLSite.Models.NewWorks;
|
||||
|
||||
public record NewWorksApiResponse
|
||||
{
|
||||
[JsonPropertyName("meta")]
|
||||
public required NewWorksApiMeta Meta { get; init; }
|
||||
|
||||
[JsonPropertyName("data")]
|
||||
public required NewWorksApiData Data { get; init; }
|
||||
}
|
||||
Reference in New Issue
Block a user