feat: 所有しているタイムラインの一覧を取得できるように

This commit is contained in:
usbharu 2024-09-07 16:44:30 +09:00
parent 8c5c2abb3f
commit cf0b0017f6
Signed by: usbharu
GPG Key ID: 6556747BF94EEBC8
4 changed files with 69 additions and 0 deletions

View File

@ -0,0 +1,23 @@
package dev.usbharu.hideout.core.application.model
import dev.usbharu.hideout.core.domain.model.timeline.TimelineVisibility
data class Timeline(
val id: Long,
val userDetailId: Long,
val name: String,
val visibility: TimelineVisibility,
val isSystem: Boolean
) {
companion object {
fun of(timeline: dev.usbharu.hideout.core.domain.model.timeline.Timeline): Timeline {
return Timeline(
timeline.id.value,
timeline.userDetailId.id,
timeline.name.value,
timeline.visibility,
timeline.isSystem
)
}
}
}

View File

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

View File

@ -0,0 +1,37 @@
package dev.usbharu.hideout.core.application.timeline
import dev.usbharu.hideout.core.application.model.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.TimelineRepository
import dev.usbharu.hideout.core.domain.model.timeline.TimelineVisibility
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Service
@Service
class UserGetTimelinesApplicationService(transaction: Transaction, private val timelineRepository: TimelineRepository) :
AbstractApplicationService<GetTimelines, List<Timeline>>(
transaction, logger
) {
override suspend fun internalExecute(command: GetTimelines, principal: Principal): List<Timeline> {
val userDetailId = UserDetailId(command.userDetailId)
val timelineVisibility = if (userDetailId == principal.userDetailId) {
listOf(TimelineVisibility.PUBLIC, TimelineVisibility.UNLISTED, TimelineVisibility.PRIVATE)
} else {
listOf(TimelineVisibility.PUBLIC)
}
val timelineList =
timelineRepository.findAllByUserDetailIdAndVisibilityIn(userDetailId, timelineVisibility)
return timelineList.map { Timeline.of(it) }
}
companion object {
private val logger = LoggerFactory.getLogger(UserGetTimelinesApplicationService::class.java)
}
}

View File

@ -1,5 +1,7 @@
package dev.usbharu.hideout.core.domain.model.timeline package dev.usbharu.hideout.core.domain.model.timeline
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
interface TimelineRepository { interface TimelineRepository {
suspend fun save(timeline: Timeline): Timeline suspend fun save(timeline: Timeline): Timeline
suspend fun delete(timeline: Timeline) suspend fun delete(timeline: Timeline)
@ -7,4 +9,8 @@ interface TimelineRepository {
suspend fun findByIds(ids: List<TimelineId>): List<Timeline> suspend fun findByIds(ids: List<TimelineId>): List<Timeline>
suspend fun findById(id: TimelineId): Timeline? suspend fun findById(id: TimelineId): Timeline?
suspend fun findAllByUserDetailIdAndVisibilityIn(
userDetailId: UserDetailId,
visibility: List<TimelineVisibility>
): List<Timeline>
} }