diff --git a/illust-crud/src/main/kotlin/dev/usbharu/unos/illust/crud/RequestTaggingService.kt b/illust-crud/src/main/kotlin/dev/usbharu/unos/illust/crud/RequestTaggingService.kt new file mode 100644 index 0000000..01ee41b --- /dev/null +++ b/illust-crud/src/main/kotlin/dev/usbharu/unos/illust/crud/RequestTaggingService.kt @@ -0,0 +1,31 @@ +package dev.usbharu.unos.illust.crud + +import illust.tag.IllustTaggingServiceGrpcKt +import illust.tag.taggingRequest +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.async +import kotlinx.coroutines.awaitAll +import kotlinx.coroutines.withContext +import java.util.* + +interface RequestTaggingService { + suspend fun requestTagging(illustId: UUID): List +} + +class RequestTaggingServiceImpl(private val clients: List) : + RequestTaggingService { + override suspend fun requestTagging(illustId: UUID): List { + val taggingResults = withContext(Dispatchers.IO) { + clients.map { + async { + it.requestTagging(taggingRequest { + this.illustId = illustId.toString() + }) + } + }.awaitAll() + } + + return taggingResults.flatMap { it.tagsList } + } + +} \ No newline at end of file diff --git a/unos-proto/src/main/proto/illust/tag/tag.proto b/unos-proto/src/main/proto/illust/tag/tag.proto index 697354b..19a1cfc 100644 --- a/unos-proto/src/main/proto/illust/tag/tag.proto +++ b/unos-proto/src/main/proto/illust/tag/tag.proto @@ -9,5 +9,9 @@ message TaggingRequest{ message TaggingResult{ string illust_id = 1; + repeated string tags = 2; +} +service IllustTaggingService { + rpc requestTagging(TaggingRequest) returns (TaggingResult); } \ No newline at end of file