mirror of
https://github.com/usbharu/Hideout.git
synced 2026-09-29 08:21:11 +00:00
refactor: 公開範囲を列挙型に変更
This commit is contained in:
@@ -6,7 +6,7 @@ data class Post(
|
||||
val overview:String? = null,
|
||||
val text:String,
|
||||
val createdAt:Long,
|
||||
val visibility: Int,
|
||||
val visibility: Visibility,
|
||||
val url:String,
|
||||
val repostId:Long? = null,
|
||||
val replyId:Long? = null
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package dev.usbharu.hideout.domain.model.hideout.entity
|
||||
|
||||
enum class Visibility {
|
||||
PUBLIC,
|
||||
UNLISTED,
|
||||
FOLLOWERS,
|
||||
DIRECT
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.usbharu.hideout.repository
|
||||
|
||||
import dev.usbharu.hideout.domain.model.hideout.entity.Post
|
||||
import dev.usbharu.hideout.domain.model.hideout.entity.Visibility
|
||||
import dev.usbharu.hideout.service.IdGenerateService
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import org.jetbrains.exposed.sql.*
|
||||
@@ -33,7 +34,7 @@ class PostRepositoryImpl(database: Database, private val idGenerateService: IdGe
|
||||
it[overview] = post.overview
|
||||
it[text] = post.text
|
||||
it[createdAt] = post.createdAt
|
||||
it[visibility] = post.visibility
|
||||
it[visibility] = post.visibility.ordinal
|
||||
it[url] = post.url
|
||||
it[repostId] = post.repostId
|
||||
it[replyId] = post.replyId
|
||||
@@ -75,7 +76,7 @@ fun ResultRow.toPost(): Post {
|
||||
overview = this[Posts.overview],
|
||||
text = this[Posts.text],
|
||||
createdAt = this[Posts.createdAt],
|
||||
visibility = this[Posts.visibility],
|
||||
visibility = Visibility.values().first { visibility -> visibility.ordinal == this[Posts.visibility] },
|
||||
url = this[Posts.url],
|
||||
repostId = this[Posts.repostId],
|
||||
replyId = this[Posts.replyId]
|
||||
|
||||
@@ -2,6 +2,7 @@ package dev.usbharu.hideout.service.impl
|
||||
|
||||
import dev.usbharu.hideout.domain.model.hideout.dto.PostCreateDto
|
||||
import dev.usbharu.hideout.domain.model.hideout.entity.Post
|
||||
import dev.usbharu.hideout.domain.model.hideout.entity.Visibility
|
||||
import dev.usbharu.hideout.repository.IPostRepository
|
||||
import dev.usbharu.hideout.repository.Posts
|
||||
import dev.usbharu.hideout.repository.UsersFollowers
|
||||
@@ -36,7 +37,7 @@ class PostService(
|
||||
val id = postRepository.generateId()
|
||||
val postEntity = Post(
|
||||
id, user.id, null, post.text,
|
||||
Instant.now().toEpochMilli(), 0, "${user.url}/posts/$id", null, null
|
||||
Instant.now().toEpochMilli(), Visibility.PUBLIC, "${user.url}/posts/$id", null, null
|
||||
)
|
||||
postRepository.save(postEntity)
|
||||
}
|
||||
@@ -51,7 +52,7 @@ class PostService(
|
||||
): List<Post> {
|
||||
return transaction {
|
||||
val select = Posts.select {
|
||||
Posts.visibility.eq(0)
|
||||
Posts.visibility.eq(Visibility.PUBLIC.ordinal)
|
||||
}
|
||||
if (userId != null) {
|
||||
select.orWhere {
|
||||
|
||||
Reference in New Issue
Block a user