diff --git a/build.gradle.kts b/build.gradle.kts index ae1ed371..17396d06 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -110,6 +110,7 @@ dependencies { implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310") implementation("com.fasterxml.jackson.module:jackson-module-kotlin") implementation("org.springframework.security:spring-security-oauth2-jose") + implementation("org.springframework.boot:spring-boot-starter-data-mongodb") implementation("io.ktor:ktor-client-logging-jvm:$ktor_version") diff --git a/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/entity/Timeline.kt b/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/entity/Timeline.kt new file mode 100644 index 00000000..a7536851 --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/domain/model/hideout/entity/Timeline.kt @@ -0,0 +1,18 @@ +package dev.usbharu.hideout.domain.model.hideout.entity + +import org.springframework.data.annotation.Id +import java.time.Instant + +data class Timeline( + @Id + val id: Long, + val userId: Long, + val timelineId: Long, + val postId: Long, + val postUserId: Long, + val createdAt: Instant, + val replyId: Long, + val repostId: Long, + val visibility: Visibility, + val sensitive: Boolean +) diff --git a/src/main/kotlin/dev/usbharu/hideout/repository/MongoTimelineRepository.kt b/src/main/kotlin/dev/usbharu/hideout/repository/MongoTimelineRepository.kt new file mode 100644 index 00000000..7077fe99 --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/repository/MongoTimelineRepository.kt @@ -0,0 +1,9 @@ +package dev.usbharu.hideout.repository + +import dev.usbharu.hideout.domain.model.hideout.entity.Timeline +import org.springframework.data.mongodb.repository.MongoRepository + +interface MongoTimelineRepository : TimelineRepository, MongoRepository { + override fun findByUserId(id: Long): List + override fun findByUserIdAndTimelineId(userId: Long, timelineId: Long): List +} diff --git a/src/main/kotlin/dev/usbharu/hideout/repository/TimelineRepository.kt b/src/main/kotlin/dev/usbharu/hideout/repository/TimelineRepository.kt new file mode 100644 index 00000000..80b88278 --- /dev/null +++ b/src/main/kotlin/dev/usbharu/hideout/repository/TimelineRepository.kt @@ -0,0 +1,8 @@ +package dev.usbharu.hideout.repository + +import dev.usbharu.hideout.domain.model.hideout.entity.Timeline + +interface TimelineRepository { + fun findByUserId(id: Long): List + fun findByUserIdAndTimelineId(userId: Long, timelineId: Long): List +} diff --git a/src/main/kotlin/dev/usbharu/hideout/service/post/PostServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/service/post/PostServiceImpl.kt index 2c7cc38a..d0f91b25 100644 --- a/src/main/kotlin/dev/usbharu/hideout/service/post/PostServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/service/post/PostServiceImpl.kt @@ -23,13 +23,18 @@ class PostServiceImpl( } override suspend fun createRemote(post: Post): Post { - return postRepository.save(post) + return internalCreate(post) } override fun addInterceptor(postCreateInterceptor: PostCreateInterceptor) { interceptors.add(postCreateInterceptor) } + private suspend fun internalCreate(post: Post): Post { + + return postRepository.save(post) + } + private suspend fun internalCreate(post: PostCreateDto): Post { val user = userRepository.findById(post.userId) ?: throw UserNotFoundException("${post.userId} was not found") val id = postRepository.generateId() @@ -44,6 +49,6 @@ class PostServiceImpl( repostId = null, replyId = null ) - return postRepository.save(createPost) + return internalCreate(post) } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 4d052250..876dbe3d 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -22,6 +22,9 @@ spring: url: "jdbc:h2:./test-dev2;MODE=POSTGRESQL" username: "" password: "" + data: + mongodb: + h2: console: