illust-data: タグ付けリクエストができるように

This commit is contained in:
usbharu 2024-03-17 17:56:20 +09:00
parent 68f07b0d16
commit 80c4b46336
Signed by: usbharu
GPG Key ID: 8CB1087135660B8D
2 changed files with 35 additions and 0 deletions

View File

@ -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<String>
}
class RequestTaggingServiceImpl(private val clients: List<IllustTaggingServiceGrpcKt.IllustTaggingServiceCoroutineStub>) :
RequestTaggingService {
override suspend fun requestTagging(illustId: UUID): List<String> {
val taggingResults = withContext(Dispatchers.IO) {
clients.map {
async {
it.requestTagging(taggingRequest {
this.illustId = illustId.toString()
})
}
}.awaitAll()
}
return taggingResults.flatMap { it.tagsList }
}
}

View File

@ -9,5 +9,9 @@ message TaggingRequest{
message TaggingResult{
string illust_id = 1;
repeated string tags = 2;
}
service IllustTaggingService {
rpc requestTagging(TaggingRequest) returns (TaggingResult);
}