@@ -1,9 +1,4 @@
using JSMR.Application.Common.Caching ;
using JSMR.Application.Integrations.Chobit.Models ;
using JSMR.Application.Integrations.Chobit.Ports ;
using JSMR.Application.Integrations.DLSite.Models ;
using JSMR.Application.Integrations.DLSite.Models.ReleasedWorks ;
using JSMR.Application.Integrations.DLSite.Ports ;
using JSMR.Application.Scanning.Contracts ;
using JSMR.Application.Scanning.Ports ;
@@ -12,10 +7,8 @@ namespace JSMR.Application.Scanning;
public sealed class ScanVoiceWorksHandler (
IVoiceWorkScannerRepository scannerRepository ,
IVoiceWorkUpdaterRepository updaterRepository ,
IDLSiteClient dlsiteClient ,
IChobitClient chobitClient ,
ISpamCircleCache spamCircleCache ,
IReleasedWorksProvider releasedWorksProvi der ,
IVoiceWorkIngestBuilder ingestBuil der ,
IVoiceWorkSearchUpdater searchUpdater )
{
public async Task < ScanVoiceWorksResponse > HandleAsync ( ScanVoiceWorksRequest request , CancellationToken cancellationToken )
@@ -47,19 +40,7 @@ public sealed class ScanVoiceWorksHandler(
) ;
}
string [ ] productIds = [ . . scanResult . Works . Where ( x = > ! string . IsNullOrWhiteSpace ( x . ProductId ) ) . Select ( x = > x . ProductId ! ) ] ;
VoiceWorkDetailCollection voiceWorkDetails = await dlsiteClient . GetVoiceWorkDetailsAsync ( productIds , cancellationToken ) ;
ChobitResultCollection chobitResults = await chobitClient . GetSampleInfoAsync ( productIds , cancellationToken ) ;
ReleasedWorksCollection releasedWorkCollection = await releasedWorksProvider . GetReleasedWorksAsync ( scanResult , cancellationToken ) ;
VoiceWorkIngest [ ] ingests = [ . . scanResult . Works . Select ( work = >
{
voiceWorkDetails . TryGetValue ( work . ProductId ! , out VoiceWorkDetails ? value ) ;
chobitResults . TryGetValue ( work . ProductId , out ChobitResult ? chobit ) ;
releasedWorkCollection . TryGetValue ( work . ProductId , out ReleasedWork ? releasedWork ) ;
return VoiceWorkIngest . From ( work , value , chobit ) ;
} ) ] ;
VoiceWorkIngest [ ] ingests = await ingestBuilder . BuildAsync ( scanResult , cancellationToken ) ;
VoiceWorkUpsertResult [ ] upsertResults = await updater . UpsertAsync ( ingests , cancellationToken ) ;
int [ ] voiceWorkIds = [ . . upsertResults . Where ( x = > x . VoiceWorkId . HasValue ) . Select ( x = > x . VoiceWorkId ! . Value ) ] ;