mirror of https://github.com/usbharu/Hideout.git
feat: Blockの配送処理を追加
This commit is contained in:
parent
bbc91ab981
commit
5559948ba6
|
@ -0,0 +1,34 @@
|
||||||
|
package dev.usbharu.hideout.activitypub.service.activity.block
|
||||||
|
|
||||||
|
import dev.usbharu.hideout.activitypub.service.common.APRequestService
|
||||||
|
import dev.usbharu.hideout.application.external.Transaction
|
||||||
|
import dev.usbharu.hideout.core.domain.model.user.UserRepository
|
||||||
|
import dev.usbharu.hideout.core.external.job.DeliverBlockJob
|
||||||
|
import dev.usbharu.hideout.core.external.job.DeliverBlockJobParam
|
||||||
|
import dev.usbharu.hideout.core.service.job.JobProcessor
|
||||||
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
|
@Service
|
||||||
|
class APDeliverBlockJobProcessor(
|
||||||
|
private val apRequestService: APRequestService,
|
||||||
|
private val userRepository: UserRepository,
|
||||||
|
private val transaction: Transaction,
|
||||||
|
private val deliverBlockJob: DeliverBlockJob
|
||||||
|
) : JobProcessor<DeliverBlockJobParam, DeliverBlockJob> {
|
||||||
|
override suspend fun process(param: DeliverBlockJobParam): Unit = transaction.transaction {
|
||||||
|
|
||||||
|
val signer = userRepository.findById(param.signer)
|
||||||
|
apRequestService.apPost(
|
||||||
|
param.inbox,
|
||||||
|
param.reject,
|
||||||
|
signer
|
||||||
|
)
|
||||||
|
apRequestService.apPost(
|
||||||
|
param.inbox,
|
||||||
|
param.block,
|
||||||
|
signer
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun job(): DeliverBlockJob = deliverBlockJob
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
package dev.usbharu.hideout.core.external.job
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper
|
||||||
|
import com.fasterxml.jackson.module.kotlin.readValue
|
||||||
|
import dev.usbharu.hideout.activitypub.domain.model.Block
|
||||||
|
import dev.usbharu.hideout.activitypub.domain.model.Reject
|
||||||
|
import kjob.core.dsl.ScheduleContext
|
||||||
|
import kjob.core.job.JobProps
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier
|
||||||
|
import org.springframework.stereotype.Component
|
||||||
|
|
||||||
|
data class DeliverBlockJobParam(
|
||||||
|
val signer: Long,
|
||||||
|
val block: Block,
|
||||||
|
val reject: Reject,
|
||||||
|
val inbox: String
|
||||||
|
)
|
||||||
|
|
||||||
|
@Component
|
||||||
|
class DeliverBlockJob(@Qualifier("activitypub") private val objectMapper: ObjectMapper) :
|
||||||
|
HideoutJob<DeliverBlockJobParam, DeliverBlockJob>("DeliverBlockJob") {
|
||||||
|
|
||||||
|
val block = string("block")
|
||||||
|
val reject = string("reject")
|
||||||
|
val inbox = string("inbox")
|
||||||
|
val signer = long("signer")
|
||||||
|
|
||||||
|
override fun convert(value: DeliverBlockJobParam): ScheduleContext<DeliverBlockJob>.(DeliverBlockJob) -> Unit = {
|
||||||
|
props[block] = objectMapper.writeValueAsString(value.block)
|
||||||
|
props[reject] = objectMapper.writeValueAsString(value.reject)
|
||||||
|
props[reject] = value.inbox
|
||||||
|
props[signer] = value.signer
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun convert(props: JobProps<DeliverBlockJob>): DeliverBlockJobParam = DeliverBlockJobParam(
|
||||||
|
props[signer],
|
||||||
|
objectMapper.readValue(props[block]),
|
||||||
|
objectMapper.readValue(props[reject]),
|
||||||
|
props[inbox]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue