mirror of https://github.com/usbharu/Hideout.git
feat: Postのidが同じ時、上書きするように
This commit is contained in:
parent
48d44bdd0f
commit
cf6e66aa7d
|
@ -29,6 +29,8 @@ class PostRepositoryImpl(database: Database, private val idGenerateService: IdGe
|
||||||
|
|
||||||
override suspend fun save(post: Post): Post {
|
override suspend fun save(post: Post): Post {
|
||||||
return query {
|
return query {
|
||||||
|
val singleOrNull = Posts.select { Posts.id eq post.id }.singleOrNull()
|
||||||
|
if (singleOrNull == null) {
|
||||||
Posts.insert {
|
Posts.insert {
|
||||||
it[id] = post.id
|
it[id] = post.id
|
||||||
it[userId] = post.userId
|
it[userId] = post.userId
|
||||||
|
@ -42,6 +44,20 @@ class PostRepositoryImpl(database: Database, private val idGenerateService: IdGe
|
||||||
it[sensitive] = post.sensitive
|
it[sensitive] = post.sensitive
|
||||||
it[apId] = post.apId
|
it[apId] = post.apId
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Posts.update({ Posts.id eq post.id }) {
|
||||||
|
it[userId] = post.userId
|
||||||
|
it[overview] = post.overview
|
||||||
|
it[text] = post.text
|
||||||
|
it[createdAt] = post.createdAt
|
||||||
|
it[visibility] = post.visibility.ordinal
|
||||||
|
it[url] = post.url
|
||||||
|
it[repostId] = post.repostId
|
||||||
|
it[replyId] = post.replyId
|
||||||
|
it[sensitive] = post.sensitive
|
||||||
|
it[apId] = post.apId
|
||||||
|
}
|
||||||
|
}
|
||||||
return@query post
|
return@query post
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue