mirror of https://github.com/usbharu/Hideout.git
feat: 所有しているタイムラインの一覧を取得できるように
This commit is contained in:
parent
8c5c2abb3f
commit
cf0b0017f6
|
@ -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
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
package dev.usbharu.hideout.core.application.timeline
|
||||
|
||||
data class GetTimelines(val userDetailId: Long)
|
|
@ -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)
|
||||
}
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
package dev.usbharu.hideout.core.domain.model.timeline
|
||||
|
||||
import dev.usbharu.hideout.core.domain.model.userdetails.UserDetailId
|
||||
|
||||
interface TimelineRepository {
|
||||
suspend fun save(timeline: Timeline): Timeline
|
||||
suspend fun delete(timeline: Timeline)
|
||||
|
@ -7,4 +9,8 @@ interface TimelineRepository {
|
|||
suspend fun findByIds(ids: List<TimelineId>): List<Timeline>
|
||||
|
||||
suspend fun findById(id: TimelineId): Timeline?
|
||||
suspend fun findAllByUserDetailIdAndVisibilityIn(
|
||||
userDetailId: UserDetailId,
|
||||
visibility: List<TimelineVisibility>
|
||||
): List<Timeline>
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue