refactor: Application Serviceをリファクタリング

This commit is contained in:
usbharu 2024-09-14 21:35:18 +09:00
parent 5f97c45906
commit bde0b31d28
Signed by: usbharu
GPG Key ID: 6556747BF94EEBC8
45 changed files with 86 additions and 349 deletions

View File

@ -1,5 +1,6 @@
package dev.usbharu.hideout.core.application.actor
import dev.usbharu.hideout.core.application.model.ActorDetail
import dev.usbharu.hideout.core.application.shared.AbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.config.ApplicationConfig

View File

@ -17,6 +17,7 @@
package dev.usbharu.hideout.core.application.actor
import dev.usbharu.hideout.core.application.exception.InternalServerException
import dev.usbharu.hideout.core.application.model.UserDetail
import dev.usbharu.hideout.core.application.shared.AbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository

View File

@ -17,6 +17,7 @@
package dev.usbharu.hideout.core.application.filter
import dev.usbharu.hideout.core.application.exception.PermissionDeniedException
import dev.usbharu.hideout.core.application.model.Filter
import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.filter.FilterId

View File

@ -16,10 +16,10 @@
package dev.usbharu.hideout.core.application.filter
import dev.usbharu.hideout.core.application.model.Filter
import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.filter.*
import dev.usbharu.hideout.core.domain.model.filter.FilterKeyword
import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser
import dev.usbharu.hideout.core.domain.shared.id.IdGenerateService
import org.slf4j.LoggerFactory

View File

@ -1,6 +1,7 @@
package dev.usbharu.hideout.core.application.instance
import dev.usbharu.hideout.core.application.exception.InternalServerException
import dev.usbharu.hideout.core.application.model.Instance
import dev.usbharu.hideout.core.application.shared.AbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.config.ApplicationConfig

View File

@ -1,50 +0,0 @@
/*
* 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.core.application.media
import dev.usbharu.hideout.core.domain.model.media.FileType
import dev.usbharu.hideout.core.domain.model.media.Media
import dev.usbharu.hideout.core.domain.model.media.MimeType
import java.net.URI
data class Media(
val id: Long,
val name: String,
val url: URI,
val thumbprintURI: URI?,
val remoteURL: URI?,
val type: FileType,
val mimeType: MimeType,
val blurHash: String?,
val description: String?
) {
companion object {
fun of(media: Media): dev.usbharu.hideout.core.application.media.Media {
return Media(
id = media.id.id,
name = media.name.name,
url = media.url,
thumbprintURI = media.thumbnailUrl,
remoteURL = media.remoteUrl,
type = media.type,
mimeType = media.mimeType,
blurHash = media.blurHash?.hash,
description = media.description?.description
)
}
}
}

View File

@ -1,22 +0,0 @@
/*
* 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.core.application.media
import java.net.URI
import java.nio.file.Path
data class UploadMedia(val path: Path, val name: String, val remoteUri: URI?, val description: String?)

View File

@ -16,6 +16,7 @@
package dev.usbharu.hideout.core.application.media
import dev.usbharu.hideout.core.application.post.MediaDetail
import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.media.*
@ -26,6 +27,8 @@ import dev.usbharu.hideout.core.external.mediastore.MediaStore
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.stereotype.Service
import java.net.URI
import java.nio.file.Path
import dev.usbharu.hideout.core.domain.model.media.Media as MediaModel
@Service
@ -35,11 +38,11 @@ class UploadMediaApplicationService(
private val mediaRepository: MediaRepository,
private val idGenerateService: IdGenerateService,
transaction: Transaction
) : LocalUserAbstractApplicationService<UploadMedia, Media>(
) : LocalUserAbstractApplicationService<UploadMedia, MediaDetail>(
transaction,
logger
) {
override suspend fun internalExecute(command: UploadMedia, principal: LocalUser): Media {
override suspend fun internalExecute(command: UploadMedia, principal: LocalUser): MediaDetail {
val process = mediaProcessor.process(command.path, command.name, null)
val id = idGenerateService.generateId()
val thumbnailUri = if (process.thumbnailPath != null) {
@ -64,10 +67,17 @@ class UploadMediaApplicationService(
mediaRepository.save(media)
return Media.of(media)
return MediaDetail.of(media)
}
companion object {
private val logger = LoggerFactory.getLogger(UploadMediaApplicationService::class.java)
}
}
data class UploadMedia(
val path: Path,
val name: String,
val remoteUri: URI?,
val description: String?
)

View File

@ -1,6 +1,7 @@
package dev.usbharu.hideout.core.application.actor
package dev.usbharu.hideout.core.application.model
import dev.usbharu.hideout.core.domain.model.actor.Actor
import dev.usbharu.hideout.core.domain.model.media.Media
import java.net.URI
data class ActorDetail(
@ -18,7 +19,7 @@ data class ActorDetail(
val followersCount: Int?,
) {
companion object {
fun of(actor: Actor, iconUrl: URI?, bannerURL: URI?): ActorDetail {
fun of(actor: Actor, iconMedia: Media?, bannerMedia: Media?): ActorDetail {
return ActorDetail(
id = actor.id.id,
name = actor.name.name,
@ -28,8 +29,8 @@ data class ActorDetail(
locked = actor.locked,
description = actor.description.description,
postsCount = actor.postsCount.postsCount,
iconUrl = iconUrl,
bannerURL = bannerURL,
iconUrl = iconMedia?.url,
bannerURL = bannerMedia?.url,
followingCount = actor.followingCount?.relationshipCount,
followersCount = actor.followersCount?.relationshipCount,
)

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package dev.usbharu.hideout.core.application.filter
package dev.usbharu.hideout.core.application.model
import dev.usbharu.hideout.core.domain.model.filter.Filter
import dev.usbharu.hideout.core.domain.model.filter.FilterAction
@ -29,7 +29,7 @@ data class Filter(
val filterKeywords: Set<FilterKeyword>,
) {
companion object {
fun of(filter: Filter): dev.usbharu.hideout.core.application.filter.Filter {
fun of(filter: Filter): dev.usbharu.hideout.core.application.model.Filter {
return Filter(
filterId = filter.id.id,
userDetailId = filter.userDetailId.id,

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package dev.usbharu.hideout.core.application.filter
package dev.usbharu.hideout.core.application.model
import dev.usbharu.hideout.core.domain.model.filter.FilterMode

View File

@ -1,11 +1,11 @@
package dev.usbharu.hideout.core.application.instance
package dev.usbharu.hideout.core.application.model
import dev.usbharu.hideout.core.domain.model.instance.Instance
import java.net.URI
data class Instance(val id: Long, val name: String, val url: URI, val description: String) {
companion object {
fun of(instance: Instance): dev.usbharu.hideout.core.application.instance.Instance {
fun of(instance: Instance): dev.usbharu.hideout.core.application.model.Instance {
return Instance(
instance.id.instanceId,
instance.name.name,

View File

@ -1,6 +1,6 @@
package dev.usbharu.hideout.core.application.post
package dev.usbharu.hideout.core.application.model
import dev.usbharu.hideout.core.application.model.Reactions
import dev.usbharu.hideout.core.application.post.MediaDetail
import dev.usbharu.hideout.core.domain.model.actor.Actor
import dev.usbharu.hideout.core.domain.model.media.Media
import dev.usbharu.hideout.core.domain.model.post.Post
@ -43,7 +43,7 @@ data class PostDetail(
): PostDetail {
return PostDetail(
id = post.id.id,
actor = ActorDetail.of(actor, iconMedia),
actor = ActorDetail.of(actor, iconMedia, null),
overview = post.overview?.overview,
text = post.text,
content = post.content.content,

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package dev.usbharu.hideout.core.application.relationship.get
package dev.usbharu.hideout.core.application.model
import dev.usbharu.hideout.core.domain.model.actorinstancerelationship.ActorInstanceRelationship
import dev.usbharu.hideout.core.domain.model.relationship.Relationship
@ -38,7 +38,7 @@ data class Relationship(
relationship: Relationship,
relationship2: Relationship,
actorInstanceRelationship: ActorInstanceRelationship,
): dev.usbharu.hideout.core.application.relationship.get.Relationship {
): dev.usbharu.hideout.core.application.model.Relationship {
return Relationship(
actorId = relationship.actorId.id,
targetId = relationship.targetActorId.id,

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
package dev.usbharu.hideout.core.application.actor
package dev.usbharu.hideout.core.application.model
import dev.usbharu.hideout.core.domain.model.actor.Actor
import dev.usbharu.hideout.core.domain.model.emoji.CustomEmoji
@ -45,7 +45,7 @@ data class UserDetail(
actor: Actor,
userDetail: UserDetail,
customEmojis: List<CustomEmoji>,
): dev.usbharu.hideout.core.application.actor.UserDetail {
): dev.usbharu.hideout.core.application.model.UserDetail {
return UserDetail(
id = actor.id.id,
userDetailId = userDetail.id.id,

View File

@ -1,31 +0,0 @@
package dev.usbharu.hideout.core.application.post
import dev.usbharu.hideout.core.domain.model.actor.Actor
import dev.usbharu.hideout.core.domain.model.media.Media
import java.net.URI
data class ActorDetail(
val actorId: Long,
val instanceId: Long,
val name: String,
val domain: String,
val screenName: String,
val url: URI,
val locked: Boolean,
val icon: URI?,
) {
companion object {
fun of(actor: Actor, iconMedia: Media?): ActorDetail {
return ActorDetail(
actorId = actor.id.id,
instanceId = actor.instance.instanceId,
name = actor.name.name,
domain = actor.domain.domain,
screenName = actor.screenName.screenName,
url = actor.url,
locked = actor.locked,
icon = iconMedia?.url
)
}
}
}

View File

@ -1,3 +0,0 @@
package dev.usbharu.hideout.core.application.post
data class DeleteLocalPost(val postId: Long)

View File

@ -50,3 +50,5 @@ class DeleteLocalPostApplicationService(
private val logger = LoggerFactory.getLogger(DeleteLocalPostApplicationService::class.java)
}
}
data class DeleteLocalPost(val postId: Long)

View File

@ -1,21 +0,0 @@
/*
* 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.core.application.post
data class GetPost(
val postId: Long,
)

View File

@ -1,48 +0,0 @@
/*
* 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.core.application.post
import dev.usbharu.hideout.core.application.exception.PermissionDeniedException
import dev.usbharu.hideout.core.application.shared.AbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.post.PostId
import dev.usbharu.hideout.core.domain.model.post.PostRepository
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import dev.usbharu.hideout.core.domain.service.post.IPostReadAccessControl
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@Service
class GetPostApplicationService(
private val postRepository: PostRepository,
private val iPostReadAccessControl: IPostReadAccessControl,
transaction: Transaction
) :
AbstractApplicationService<GetPost, Post>(transaction, logger) {
override suspend fun internalExecute(command: GetPost, principal: Principal): Post {
val post = postRepository.findById(PostId(command.postId)) ?: throw IllegalArgumentException("Post not found")
if (iPostReadAccessControl.isAllow(post, principal).not()) {
throw PermissionDeniedException()
}
return Post.of(post)
}
companion object {
private val logger = LoggerFactory.getLogger(GetPostApplicationService::class.java)
}
}

View File

@ -1,6 +1,7 @@
package dev.usbharu.hideout.core.application.post
import dev.usbharu.hideout.core.application.exception.InternalServerException
import dev.usbharu.hideout.core.application.model.PostDetail
import dev.usbharu.hideout.core.application.shared.AbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.actor.Actor

View File

@ -17,6 +17,7 @@
package dev.usbharu.hideout.core.application.relationship.get
import dev.usbharu.hideout.core.application.exception.InternalServerException
import dev.usbharu.hideout.core.application.model.Relationship
import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.actor.ActorId

View File

@ -1,5 +0,0 @@
package dev.usbharu.hideout.core.application.timeline
import dev.usbharu.hideout.core.domain.model.post.PostId
data class AddPost(val postId: PostId)

View File

@ -1,11 +0,0 @@
package dev.usbharu.hideout.core.application.timeline
import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.model.timeline.TimelineId
import dev.usbharu.hideout.core.domain.model.timelinerelationship.Visible
data class AddTimelineRelationship(
val timelineId: TimelineId,
val actorId: ActorId,
val visible: Visible
)

View File

@ -1,3 +0,0 @@
package dev.usbharu.hideout.core.application.timeline
data class GetTimelines(val userDetailId: Long)

View File

@ -1,5 +0,0 @@
package dev.usbharu.hideout.core.application.timeline
import dev.usbharu.hideout.core.domain.model.support.page.Page
data class GetUserTimeline(val id: Long, val page: Page)

View File

@ -1,12 +1,13 @@
package dev.usbharu.hideout.core.application.timeline
import dev.usbharu.hideout.core.application.post.PostDetail
import dev.usbharu.hideout.core.application.model.PostDetail
import dev.usbharu.hideout.core.application.shared.AbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.model.post.PostId
import dev.usbharu.hideout.core.domain.model.post.PostRepository
import dev.usbharu.hideout.core.domain.model.post.Visibility
import dev.usbharu.hideout.core.domain.model.support.page.Page
import dev.usbharu.hideout.core.domain.model.support.page.PaginationList
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import dev.usbharu.hideout.core.query.usertimeline.UserTimelineQueryService
@ -51,3 +52,5 @@ class GetUserTimelineApplicationService(
private val logger = LoggerFactory.getLogger(GetUserTimelineApplicationService::class.java)
}
}
data class GetUserTimeline(val id: Long, val page: Page)

View File

@ -1,11 +0,0 @@
package dev.usbharu.hideout.core.application.timeline
import dev.usbharu.hideout.core.domain.model.support.page.Page
data class ReadTimeline(
val timelineId: Long,
val mediaOnly: Boolean,
val localOnly: Boolean,
val remoteOnly: Boolean,
val page: Page
)

View File

@ -1,9 +1,10 @@
package dev.usbharu.hideout.core.application.timeline
import dev.usbharu.hideout.core.application.post.PostDetail
import dev.usbharu.hideout.core.application.model.PostDetail
import dev.usbharu.hideout.core.application.shared.AbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.post.PostId
import dev.usbharu.hideout.core.domain.model.support.page.Page
import dev.usbharu.hideout.core.domain.model.support.page.PaginationList
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import dev.usbharu.hideout.core.domain.model.timeline.TimelineId
@ -88,3 +89,11 @@ class ReadTimelineApplicationService(
private val logger = LoggerFactory.getLogger(ReadTimelineApplicationService::class.java)
}
}
data class ReadTimeline(
val timelineId: Long,
val mediaOnly: Boolean,
val localOnly: Boolean,
val remoteOnly: Boolean,
val page: Page
)

View File

@ -1,8 +0,0 @@
package dev.usbharu.hideout.core.application.timeline
import dev.usbharu.hideout.core.domain.model.timeline.TimelineVisibility
data class RegisterTimeline(
val timelineName: String,
val visibility: TimelineVisibility
)

View File

@ -1,5 +0,0 @@
package dev.usbharu.hideout.core.application.timeline
import dev.usbharu.hideout.core.domain.model.timelinerelationship.TimelineRelationshipId
data class RemoveTimelineRelationship(val timelineRelationshipId: TimelineRelationshipId)

View File

@ -3,6 +3,7 @@ package dev.usbharu.hideout.core.application.timeline
import dev.usbharu.hideout.core.application.shared.AbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import dev.usbharu.hideout.core.domain.model.timeline.TimelineId
import dev.usbharu.hideout.core.domain.model.timeline.TimelineRepository
import dev.usbharu.hideout.core.external.timeline.TimelineStore
import org.slf4j.LoggerFactory
@ -28,3 +29,5 @@ class SetTimelineToTimelineStoreApplicationService(
private val logger = LoggerFactory.getLogger(SetTimelineToTimelineStoreApplicationService::class.java)
}
}
data class SetTimleineStore(val timelineId: TimelineId)

View File

@ -1,5 +0,0 @@
package dev.usbharu.hideout.core.application.timeline
import dev.usbharu.hideout.core.domain.model.timeline.TimelineId
data class SetTimleineStore(val timelineId: TimelineId)

View File

@ -2,6 +2,7 @@ package dev.usbharu.hideout.core.application.timeline
import dev.usbharu.hideout.core.application.shared.AbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.post.PostId
import dev.usbharu.hideout.core.domain.model.post.PostRepository
import dev.usbharu.hideout.core.domain.model.support.principal.Principal
import dev.usbharu.hideout.core.external.timeline.TimelineStore
@ -27,3 +28,5 @@ class TimelineAddPostApplicationService(
private val logger = LoggerFactory.getLogger(TimelineAddPostApplicationService::class.java)
}
}
data class AddPost(val postId: PostId)

View File

@ -3,11 +3,14 @@ package dev.usbharu.hideout.core.application.timeline
import dev.usbharu.hideout.core.application.exception.PermissionDeniedException
import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.actor.ActorId
import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser
import dev.usbharu.hideout.core.domain.model.timeline.TimelineId
import dev.usbharu.hideout.core.domain.model.timeline.TimelineRepository
import dev.usbharu.hideout.core.domain.model.timelinerelationship.TimelineRelationship
import dev.usbharu.hideout.core.domain.model.timelinerelationship.TimelineRelationshipId
import dev.usbharu.hideout.core.domain.model.timelinerelationship.TimelineRelationshipRepository
import dev.usbharu.hideout.core.domain.model.timelinerelationship.Visible
import dev.usbharu.hideout.core.domain.shared.id.IdGenerateService
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -45,3 +48,9 @@ class UserAddTimelineRelationshipApplicationService(
private val logger = LoggerFactory.getLogger(UserAddTimelineRelationshipApplicationService::class.java)
}
}
data class AddTimelineRelationship(
val timelineId: TimelineId,
val actorId: ActorId,
val visible: Visible
)

View File

@ -35,3 +35,5 @@ class UserGetTimelinesApplicationService(transaction: Transaction, private val t
private val logger = LoggerFactory.getLogger(UserGetTimelinesApplicationService::class.java)
}
}
data class GetTimelines(val userDetailId: Long)

View File

@ -3,10 +3,7 @@ package dev.usbharu.hideout.core.application.timeline
import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationService
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser
import dev.usbharu.hideout.core.domain.model.timeline.Timeline
import dev.usbharu.hideout.core.domain.model.timeline.TimelineId
import dev.usbharu.hideout.core.domain.model.timeline.TimelineName
import dev.usbharu.hideout.core.domain.model.timeline.TimelineRepository
import dev.usbharu.hideout.core.domain.model.timeline.*
import dev.usbharu.hideout.core.domain.shared.id.IdGenerateService
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Component
@ -35,3 +32,8 @@ class UserRegisterTimelineApplicationService(
private val logger = LoggerFactory.getLogger(UserRegisterTimelineApplicationService::class.java)
}
}
data class RegisterTimeline(
val timelineName: String,
val visibility: TimelineVisibility
)

View File

@ -5,6 +5,7 @@ import dev.usbharu.hideout.core.application.shared.LocalUserAbstractApplicationS
import dev.usbharu.hideout.core.application.shared.Transaction
import dev.usbharu.hideout.core.domain.model.support.principal.LocalUser
import dev.usbharu.hideout.core.domain.model.timeline.TimelineRepository
import dev.usbharu.hideout.core.domain.model.timelinerelationship.TimelineRelationshipId
import dev.usbharu.hideout.core.domain.model.timelinerelationship.TimelineRelationshipRepository
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@ -42,3 +43,5 @@ class UserRemoveTimelineRelationshipApplicationService(
private val logger = LoggerFactory.getLogger(UserRemoveTimelineRelationshipApplicationService::class.java)
}
}
data class RemoveTimelineRelationship(val timelineRelationshipId: TimelineRelationshipId)

View File

@ -1,22 +0,0 @@
package dev.usbharu.hideout.core.domain.model.support.postdetail
import dev.usbharu.hideout.core.domain.model.actor.Actor
import dev.usbharu.hideout.core.domain.model.post.Post
data class PostDetail(
val post: Post,
val reply: Post? = null,
val repost: Post? = null,
val postActor: Actor,
val replyActor: Actor? = null,
val repostActor: Actor? = null
) {
init {
require(post.replyId == reply?.id)
require(post.repostId == repost?.id)
require(post.actorId == postActor.id)
require(reply?.actorId == replyActor?.id)
require(repost?.actorId == repostActor?.id)
}
}

View File

@ -1,8 +1,8 @@
package dev.usbharu.hideout.core.infrastructure.exposedquery
import dev.usbharu.hideout.core.application.post.ActorDetail
import dev.usbharu.hideout.core.application.model.ActorDetail
import dev.usbharu.hideout.core.application.model.PostDetail
import dev.usbharu.hideout.core.application.post.MediaDetail
import dev.usbharu.hideout.core.application.post.PostDetail
import dev.usbharu.hideout.core.domain.model.post.PostId
import dev.usbharu.hideout.core.domain.model.post.Visibility
import dev.usbharu.hideout.core.domain.model.support.principal.Principal

View File

@ -1,6 +1,6 @@
package dev.usbharu.hideout.core.query.usertimeline
import dev.usbharu.hideout.core.application.post.PostDetail
import dev.usbharu.hideout.core.application.model.PostDetail
import dev.usbharu.hideout.core.domain.model.post.PostId
import dev.usbharu.hideout.core.domain.model.support.principal.Principal

View File

@ -8,7 +8,7 @@
<article class="post" th:fragment="single-simple-post(post)">
<!--/*@thymesVar id="post" type="dev.usbharu.hideout.core.application.post.PostDetail"*/-->
<!--/*@thymesVar id="post" type="dev.usbharu.hideout.core.application.model.PostDetail"*/-->
<img alt="" height="80px" src="" th:src="${post.actor.icon}" width="80px">
<div style="display: inline-block">
<a th:href="${post.actor.url}"
@ -43,7 +43,7 @@
</article>
<div class="post-controller" th:fragment="single-post-controller(post)">
<!--/*@thymesVar id="post" type="dev.usbharu.hideout.core.application.post.PostDetail"*/-->
<!--/*@thymesVar id="post" type="dev.usbharu.hideout.core.application.model.PostDetail"*/-->
<th:block th:if="${post.favourited}">
<form method="post" th:action="@{/users/a/posts/{id}/unfavourite(id=${post.id})}">
<a th:href="${'/publish?reply_to=' + post.id}">Reply</a>

View File

@ -6,7 +6,7 @@
</head>
<body>
<th:block th:fragment="simple-timline(timelineObject,href)">
<!--/*@thymesVar id="timelineObject" type="dev.usbharu.hideout.core.domain.model.support.page.PaginationList<dev.usbharu.hideout.core.application.post.PostDetail,dev.usbharu.hideout.core.domain.model.post.PostId>"*/-->
<!--/*@thymesVar id="timelineObject" type="dev.usbharu.hideout.core.domain.model.support.page.PaginationList<dev.usbharu.hideout.core.application.model.PostDetail,dev.usbharu.hideout.core.domain.model.post.PostId>"*/-->
<div th:if="${timelineObject.prev != null}">
<a th:href="${href + '?min_id=' + timelineObject.prev.id}" th:text="#{common.paging-load}">Show more</a>
</div>

View File

@ -1,64 +0,0 @@
package dev.usbharu.hideout.core.application.post
import dev.usbharu.hideout.core.application.exception.PermissionDeniedException
import dev.usbharu.hideout.core.domain.model.post.PostId
import dev.usbharu.hideout.core.domain.model.post.PostRepository
import dev.usbharu.hideout.core.domain.model.post.TestPostFactory
import dev.usbharu.hideout.core.domain.model.support.principal.Anonymous
import dev.usbharu.hideout.core.domain.service.post.IPostReadAccessControl
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import org.junit.jupiter.api.extension.ExtendWith
import org.mockito.InjectMocks
import org.mockito.Mock
import org.mockito.Spy
import org.mockito.junit.jupiter.MockitoExtension
import org.mockito.kotlin.any
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.whenever
import utils.TestTransaction
@ExtendWith(MockitoExtension::class)
class GetPostApplicationServiceTest {
@InjectMocks
lateinit var service: GetPostApplicationService
@Mock
lateinit var postRepository: PostRepository
@Mock
lateinit var iPostReadAccessControl: IPostReadAccessControl
@Spy
val transaction = TestTransaction
@Test
fun postReadAccessControlがtrueを返したらPostが返ってくる() = runTest {
val post = TestPostFactory.create(id = 1)
whenever(postRepository.findById(PostId(1))).doReturn(post)
whenever(iPostReadAccessControl.isAllow(any(), any())).doReturn(true)
val actual = service.execute(GetPost(1), Anonymous)
assertEquals(Post.of(post), actual)
}
@Test
fun postが見つからない場合失敗() = runTest {
assertThrows<IllegalArgumentException> {
service.execute(GetPost(2), Anonymous)
}
}
@Test
fun postReadAccessControlがfalseを返したら失敗() = runTest {
val post = TestPostFactory.create(id = 1)
whenever(postRepository.findById(PostId(1))).doReturn(post)
whenever(iPostReadAccessControl.isAllow(any(), any())).doReturn(false)
assertThrows<PermissionDeniedException> {
service.execute(GetPost(1), Anonymous)
}
}
}

View File

@ -27,8 +27,6 @@ import dev.usbharu.hideout.mastodon.application.filter.GetFilterV1
import dev.usbharu.hideout.mastodon.application.filter.GetFilterV1ApplicationService
import dev.usbharu.hideout.mastodon.interfaces.api.generated.FilterApi
import dev.usbharu.hideout.mastodon.interfaces.api.generated.model.*
import dev.usbharu.hideout.mastodon.interfaces.api.generated.model.Filter
import dev.usbharu.hideout.mastodon.interfaces.api.generated.model.FilterKeyword
import dev.usbharu.hideout.mastodon.interfaces.api.generated.model.FilterPostRequest.Context
import dev.usbharu.hideout.mastodon.interfaces.api.generated.model.V1FilterPostRequest.Context.*
import org.springframework.http.ResponseEntity
@ -131,7 +129,7 @@ class SpringFilterApi(
)
}
private fun filter(filter: dev.usbharu.hideout.core.application.filter.Filter) = Filter(
private fun filter(filter: dev.usbharu.hideout.core.application.model.Filter) = Filter(
id = filter.filterId.toString(),
title = filter.name,
context = filter.filterContext.map {