mirror of https://github.com/usbharu/Hideout.git
feat: 明示的に情報をアップデートするように
This commit is contained in:
parent
0779c92ec4
commit
208d1c519a
|
@ -0,0 +1,54 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2024 usbharu
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package dev.usbharu.hideout.mastodon.domain.exception
|
||||||
|
|
||||||
|
import dev.usbharu.hideout.domain.mastodon.model.generated.NotFoundResponse
|
||||||
|
import dev.usbharu.hideout.mastodon.domain.model.MastodonApiErrorResponse
|
||||||
|
|
||||||
|
class AccountNotFoundException : ClientException {
|
||||||
|
constructor(response: MastodonApiErrorResponse<NotFoundResponse>) : super(response)
|
||||||
|
constructor(message: String?, response: MastodonApiErrorResponse<NotFoundResponse>) : super(message, response)
|
||||||
|
constructor(message: String?, cause: Throwable?, response: MastodonApiErrorResponse<NotFoundResponse>) : super(
|
||||||
|
message,
|
||||||
|
cause,
|
||||||
|
response
|
||||||
|
)
|
||||||
|
|
||||||
|
constructor(cause: Throwable?, response: MastodonApiErrorResponse<NotFoundResponse>) : super(cause, response)
|
||||||
|
constructor(
|
||||||
|
message: String?,
|
||||||
|
cause: Throwable?,
|
||||||
|
enableSuppression: Boolean,
|
||||||
|
writableStackTrace: Boolean,
|
||||||
|
response: MastodonApiErrorResponse<NotFoundResponse>,
|
||||||
|
) : super(message, cause, enableSuppression, writableStackTrace, response)
|
||||||
|
|
||||||
|
fun getTypedResponse(): MastodonApiErrorResponse<NotFoundResponse> =
|
||||||
|
response as MastodonApiErrorResponse<NotFoundResponse>
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun ofId(id: Long): AccountNotFoundException = AccountNotFoundException(
|
||||||
|
"id: $id was not found.",
|
||||||
|
MastodonApiErrorResponse(
|
||||||
|
NotFoundResponse(
|
||||||
|
"Record not found"
|
||||||
|
),
|
||||||
|
404
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,6 +19,7 @@ package dev.usbharu.hideout.mastodon.service.account
|
||||||
import dev.usbharu.hideout.application.external.Transaction
|
import dev.usbharu.hideout.application.external.Transaction
|
||||||
import dev.usbharu.hideout.application.infrastructure.exposed.Page
|
import dev.usbharu.hideout.application.infrastructure.exposed.Page
|
||||||
import dev.usbharu.hideout.application.infrastructure.exposed.PaginationList
|
import dev.usbharu.hideout.application.infrastructure.exposed.PaginationList
|
||||||
|
import dev.usbharu.hideout.core.domain.exception.resource.UserNotFoundException
|
||||||
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
|
import dev.usbharu.hideout.core.domain.model.relationship.RelationshipRepository
|
||||||
import dev.usbharu.hideout.core.service.media.MediaService
|
import dev.usbharu.hideout.core.service.media.MediaService
|
||||||
import dev.usbharu.hideout.core.service.relationship.RelationshipService
|
import dev.usbharu.hideout.core.service.relationship.RelationshipService
|
||||||
|
@ -26,6 +27,7 @@ import dev.usbharu.hideout.core.service.user.UpdateUserDto
|
||||||
import dev.usbharu.hideout.core.service.user.UserCreateDto
|
import dev.usbharu.hideout.core.service.user.UserCreateDto
|
||||||
import dev.usbharu.hideout.core.service.user.UserService
|
import dev.usbharu.hideout.core.service.user.UserService
|
||||||
import dev.usbharu.hideout.domain.mastodon.model.generated.*
|
import dev.usbharu.hideout.domain.mastodon.model.generated.*
|
||||||
|
import dev.usbharu.hideout.mastodon.domain.exception.AccountNotFoundException
|
||||||
import dev.usbharu.hideout.mastodon.interfaces.api.media.MediaRequest
|
import dev.usbharu.hideout.mastodon.interfaces.api.media.MediaRequest
|
||||||
import dev.usbharu.hideout.mastodon.query.StatusQueryService
|
import dev.usbharu.hideout.mastodon.query.StatusQueryService
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
|
@ -127,6 +129,8 @@ class AccountApiServiceImpl(
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun verifyCredentials(userid: Long): CredentialAccount = transaction.transaction {
|
override suspend fun verifyCredentials(userid: Long): CredentialAccount = transaction.transaction {
|
||||||
|
userService.updateUserStatistics(userid)
|
||||||
|
|
||||||
val account = accountService.findById(userid)
|
val account = accountService.findById(userid)
|
||||||
from(account)
|
from(account)
|
||||||
}
|
}
|
||||||
|
@ -141,9 +145,17 @@ class AccountApiServiceImpl(
|
||||||
return@transaction fetchRelationship(loginUser, followTargetUserId)
|
return@transaction fetchRelationship(loginUser, followTargetUserId)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun account(id: Long): Account = transaction.transaction {
|
override suspend fun account(id: Long): Account {
|
||||||
|
return try {
|
||||||
|
transaction.transaction {
|
||||||
|
userService.updateUserStatistics(id)
|
||||||
return@transaction accountService.findById(id)
|
return@transaction accountService.findById(id)
|
||||||
}
|
}
|
||||||
|
} catch (e: UserNotFoundException) {
|
||||||
|
logger.debug("Account Not found $id")
|
||||||
|
throw AccountNotFoundException.ofId(id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun relationships(userid: Long, id: List<Long>, withSuspended: Boolean): List<Relationship> =
|
override suspend fun relationships(userid: Long, id: List<Long>, withSuspended: Boolean): List<Relationship> =
|
||||||
transaction.transaction {
|
transaction.transaction {
|
||||||
|
@ -160,7 +172,7 @@ class AccountApiServiceImpl(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun block(userid: Long, target: Long): Relationship = transaction.transaction {
|
override suspend fun block(userid: Long, target: Long) = transaction.transaction {
|
||||||
relationshipService.block(userid, target)
|
relationshipService.block(userid, target)
|
||||||
|
|
||||||
fetchRelationship(userid, target)
|
fetchRelationship(userid, target)
|
||||||
|
@ -339,6 +351,9 @@ class AccountApiServiceImpl(
|
||||||
ignoreFollowRequestToTarget = false
|
ignoreFollowRequestToTarget = false
|
||||||
)
|
)
|
||||||
|
|
||||||
|
userService.updateUserStatistics(userid)
|
||||||
|
userService.updateUserStatistics(targetId)
|
||||||
|
|
||||||
return Relationship(
|
return Relationship(
|
||||||
id = targetId.toString(),
|
id = targetId.toString(),
|
||||||
following = relationship.following,
|
following = relationship.following,
|
||||||
|
|
Loading…
Reference in New Issue