feat: Timelineを追加

This commit is contained in:
usbharu 2023-09-29 15:18:29 +09:00
parent 0f0b2037f6
commit 8c34019728
6 changed files with 46 additions and 2 deletions

View File

@ -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")

View File

@ -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
)

View File

@ -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<Timeline, Long> {
override fun findByUserId(id: Long): List<Timeline>
override fun findByUserIdAndTimelineId(userId: Long, timelineId: Long): List<Timeline>
}

View File

@ -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<Timeline>
fun findByUserIdAndTimelineId(userId: Long, timelineId: Long): List<Timeline>
}

View File

@ -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)
}
}

View File

@ -22,6 +22,9 @@ spring:
url: "jdbc:h2:./test-dev2;MODE=POSTGRESQL"
username: ""
password: ""
data:
mongodb:
h2:
console: