mirror of
https://github.com/InsanusMokrassar/PlaguPoster.git
synced 2024-11-17 21:43:46 +00:00
fixes in exposed posts repo
This commit is contained in:
parent
65f613fd97
commit
6673b6c69b
@ -3,6 +3,7 @@ package dev.inmo.plaguposter.posts.exposed
|
|||||||
import com.benasher44.uuid.uuid4
|
import com.benasher44.uuid.uuid4
|
||||||
import com.soywiz.klock.DateTime
|
import com.soywiz.klock.DateTime
|
||||||
import dev.inmo.micro_utils.repos.KeyValuesRepo
|
import dev.inmo.micro_utils.repos.KeyValuesRepo
|
||||||
|
import dev.inmo.micro_utils.repos.UpdatedValuePair
|
||||||
import dev.inmo.micro_utils.repos.exposed.AbstractExposedCRUDRepo
|
import dev.inmo.micro_utils.repos.exposed.AbstractExposedCRUDRepo
|
||||||
import dev.inmo.micro_utils.repos.exposed.initTable
|
import dev.inmo.micro_utils.repos.exposed.initTable
|
||||||
import dev.inmo.plaguposter.posts.models.*
|
import dev.inmo.plaguposter.posts.models.*
|
||||||
@ -75,13 +76,15 @@ class ExposedPostsRepo(
|
|||||||
return id
|
return id
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun update(id: PostId?, value: NewPost, it: UpdateBuilder<Int>) {
|
override fun update(id: PostId?, value: NewPost, it: UpdateBuilder<Int>) {}
|
||||||
id ?: error("Unable to find post id in update")
|
|
||||||
|
private fun updateContent(post: RegisteredPost) {
|
||||||
|
transaction(database) {
|
||||||
with(contentRepo) {
|
with(contentRepo) {
|
||||||
deleteWhere { postIdColumn.eq(id.string) }
|
deleteWhere { postIdColumn.eq(post.id.string) }
|
||||||
value.content.forEach { contentInfo ->
|
post.content.forEach { contentInfo ->
|
||||||
insert {
|
insert {
|
||||||
it[postIdColumn] = id.string
|
it[postIdColumn] = post.id.string
|
||||||
it[chatIdColumn] = contentInfo.chatId.chatId
|
it[chatIdColumn] = contentInfo.chatId.chatId
|
||||||
it[messageIdColumn] = contentInfo.messageId
|
it[messageIdColumn] = contentInfo.messageId
|
||||||
it[groupColumn] = contentInfo.group
|
it[groupColumn] = contentInfo.group
|
||||||
@ -90,12 +93,27 @@ class ExposedPostsRepo(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun insert(value: NewPost, it: InsertStatement<Number>) {
|
override fun insert(value: NewPost, it: InsertStatement<Number>) {
|
||||||
super.insert(value, it)
|
super.insert(value, it)
|
||||||
it[createdColumn] = DateTime.now().unixMillis
|
it[createdColumn] = DateTime.now().unixMillis
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun onAfterCreate(values: List<Pair<NewPost, RegisteredPost>>): List<RegisteredPost> {
|
||||||
|
values.forEach {
|
||||||
|
updateContent(it.second)
|
||||||
|
}
|
||||||
|
return super.onAfterCreate(values)
|
||||||
|
}
|
||||||
|
|
||||||
|
override suspend fun onAfterUpdate(value: List<UpdatedValuePair<NewPost, RegisteredPost>>): List<RegisteredPost> {
|
||||||
|
value.forEach {
|
||||||
|
updateContent(it.second)
|
||||||
|
}
|
||||||
|
return super.onAfterUpdate(value)
|
||||||
|
}
|
||||||
|
|
||||||
override suspend fun deleteById(ids: List<PostId>) {
|
override suspend fun deleteById(ids: List<PostId>) {
|
||||||
onBeforeDelete(ids)
|
onBeforeDelete(ids)
|
||||||
val posts = ids.mapNotNull {
|
val posts = ids.mapNotNull {
|
||||||
|
Loading…
Reference in New Issue
Block a user