mirror of https://github.com/usbharu/Hideout.git
fix: コントローラーのバグ修正
This commit is contained in:
parent
217a010b77
commit
64cd9c0a34
|
@ -2,6 +2,7 @@ package dev.usbharu.hideout.activitypub.interfaces.api.actor
|
|||
|
||||
import dev.usbharu.hideout.activitypub.domain.model.Person
|
||||
import dev.usbharu.hideout.activitypub.service.objects.user.APUserService
|
||||
import dev.usbharu.hideout.core.domain.exception.FailedToGetResourcesException
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
|
@ -9,7 +10,11 @@ import org.springframework.web.bind.annotation.RestController
|
|||
@RestController
|
||||
class UserAPControllerImpl(private val apUserService: APUserService) : UserAPController {
|
||||
override suspend fun userAp(username: String): ResponseEntity<Person> {
|
||||
val person = apUserService.getPersonByName(username)
|
||||
val person = try {
|
||||
apUserService.getPersonByName(username)
|
||||
} catch (e: FailedToGetResourcesException) {
|
||||
return ResponseEntity.notFound().build()
|
||||
}
|
||||
person.context += listOf("https://www.w3.org/ns/activitystreams")
|
||||
return ResponseEntity(person, HttpStatus.OK)
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ interface InboxController {
|
|||
"application/activity+json",
|
||||
"application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""
|
||||
],
|
||||
method = [RequestMethod.GET, RequestMethod.POST]
|
||||
method = [RequestMethod.POST]
|
||||
)
|
||||
suspend fun inbox(@RequestBody string: String): ResponseEntity<Unit>
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package dev.usbharu.hideout.activitypub.interfaces.api.outbox
|
||||
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.RequestBody
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RequestMethod
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
|
@ -9,5 +8,5 @@ import org.springframework.web.bind.annotation.RestController
|
|||
@RestController
|
||||
interface OutboxController {
|
||||
@RequestMapping("/outbox", "/users/{username}/outbox", method = [RequestMethod.POST, RequestMethod.GET])
|
||||
suspend fun outbox(@RequestBody string: String): ResponseEntity<Unit>
|
||||
suspend fun outbox(): ResponseEntity<Unit>
|
||||
}
|
||||
|
|
|
@ -2,11 +2,10 @@ package dev.usbharu.hideout.activitypub.interfaces.api.outbox
|
|||
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.RequestBody
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
|
||||
@RestController
|
||||
class OutboxControllerImpl : OutboxController {
|
||||
override suspend fun outbox(@RequestBody string: String): ResponseEntity<Unit> =
|
||||
override suspend fun outbox(): ResponseEntity<Unit> =
|
||||
ResponseEntity(HttpStatus.NOT_IMPLEMENTED)
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package dev.usbharu.hideout.activitypub.interfaces.api.webfinger
|
|||
import dev.usbharu.hideout.activitypub.domain.model.webfinger.WebFinger
|
||||
import dev.usbharu.hideout.activitypub.service.webfinger.WebFingerApiService
|
||||
import dev.usbharu.hideout.application.config.ApplicationConfig
|
||||
import dev.usbharu.hideout.core.domain.exception.FailedToGetResourcesException
|
||||
import dev.usbharu.hideout.util.AcctUtil
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.slf4j.LoggerFactory
|
||||
|
@ -26,8 +27,11 @@ class WebFingerController(
|
|||
logger.warn("FAILED Parse acct.", e)
|
||||
return@runBlocking ResponseEntity.badRequest().build()
|
||||
}
|
||||
val user =
|
||||
val user = try {
|
||||
webFingerApiService.findByNameAndDomain(acct.username, acct.domain ?: applicationConfig.url.host)
|
||||
} catch (_: FailedToGetResourcesException) {
|
||||
return@runBlocking ResponseEntity.notFound().build()
|
||||
}
|
||||
val webFinger = WebFinger(
|
||||
"acct:${user.name}@${user.domain}",
|
||||
listOf(
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package dev.usbharu.hideout.core.service.reaction
|
||||
|
||||
import dev.usbharu.hideout.activitypub.service.activity.like.APReactionService
|
||||
import dev.usbharu.hideout.core.domain.exception.FailedToGetResourcesException
|
||||
import dev.usbharu.hideout.core.domain.model.reaction.Reaction
|
||||
import dev.usbharu.hideout.core.domain.model.reaction.ReactionRepository
|
||||
import dev.usbharu.hideout.core.query.ReactionQueryService
|
||||
|
@ -26,18 +27,26 @@ class ReactionServiceImpl(
|
|||
}
|
||||
|
||||
override suspend fun sendReaction(name: String, userId: Long, postId: Long) {
|
||||
if (reactionQueryService.reactionAlreadyExist(postId, userId, 0)) {
|
||||
// delete
|
||||
reactionQueryService.deleteByPostIdAndUserId(postId, userId)
|
||||
} else {
|
||||
val reaction = Reaction(reactionRepository.generateId(), 0, postId, userId)
|
||||
reactionRepository.save(reaction)
|
||||
apReactionService.reaction(reaction)
|
||||
try {
|
||||
val findByPostIdAndUserIdAndEmojiId =
|
||||
reactionQueryService.findByPostIdAndUserIdAndEmojiId(postId, userId, 0)
|
||||
apReactionService.removeReaction(findByPostIdAndUserIdAndEmojiId)
|
||||
reactionRepository.delete(findByPostIdAndUserIdAndEmojiId)
|
||||
} catch (_: FailedToGetResourcesException) {
|
||||
}
|
||||
val reaction = Reaction(reactionRepository.generateId(), 0, postId, userId)
|
||||
reactionRepository.save(reaction)
|
||||
apReactionService.reaction(reaction)
|
||||
}
|
||||
|
||||
override suspend fun removeReaction(userId: Long, postId: Long) {
|
||||
reactionQueryService.deleteByPostIdAndUserId(postId, userId)
|
||||
try {
|
||||
val findByPostIdAndUserIdAndEmojiId =
|
||||
reactionQueryService.findByPostIdAndUserIdAndEmojiId(postId, userId, 0)
|
||||
reactionRepository.delete(findByPostIdAndUserIdAndEmojiId)
|
||||
apReactionService.removeReaction(findByPostIdAndUserIdAndEmojiId)
|
||||
} catch (e: FailedToGetResourcesException) {
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
|
Loading…
Reference in New Issue