add ratings

This commit is contained in:
InsanusMokrassar 2022-08-21 16:03:27 +06:00
parent c4e7f338a9
commit aa9f187203
11 changed files with 96 additions and 0 deletions

22
ratings/build.gradle Normal file
View File

@ -0,0 +1,22 @@
plugins {
id "org.jetbrains.kotlin.multiplatform"
id "org.jetbrains.kotlin.plugin.serialization"
id "com.android.library"
}
apply from: "$mppProjectWithSerializationPresetPath"
kotlin {
sourceSets {
commonMain {
dependencies {
api project(":plaguposter.common")
api project(":plaguposter.posts")
}
}
jvmMain {
dependencies {
}
}
}
}

View File

@ -0,0 +1 @@
package dev.inmo.plaguposter.ratings

View File

@ -0,0 +1,10 @@
package dev.inmo.plaguposter.ratings.models
import kotlinx.serialization.Serializable
import kotlin.jvm.JvmInline
@Serializable
@JvmInline
value class Rating(
val double: Double
)

View File

@ -0,0 +1,7 @@
package dev.inmo.plaguposter.ratings.repo
import dev.inmo.micro_utils.repos.KeyValueRepo
import dev.inmo.plaguposter.posts.models.PostId
import dev.inmo.plaguposter.ratings.models.Rating
interface RatingsRepo : KeyValueRepo<PostId, Rating>, ReadRatingsRepo, WriteRatingsRepo

View File

@ -0,0 +1,7 @@
package dev.inmo.plaguposter.ratings.repo
import dev.inmo.micro_utils.repos.ReadKeyValueRepo
import dev.inmo.plaguposter.posts.models.PostId
import dev.inmo.plaguposter.ratings.models.Rating
interface ReadRatingsRepo : ReadKeyValueRepo<PostId, Rating>

View File

@ -0,0 +1,7 @@
package dev.inmo.plaguposter.ratings.repo
import dev.inmo.micro_utils.repos.WriteKeyValueRepo
import dev.inmo.plaguposter.posts.models.PostId
import dev.inmo.plaguposter.ratings.models.Rating
interface WriteRatingsRepo : WriteKeyValueRepo<PostId, Rating>

View File

@ -0,0 +1,14 @@
package dev.inmo.plaguposter.ratings
import dev.inmo.plagubot.Plugin
import dev.inmo.plaguposter.posts.exposed.ExposedPostsRepo
import dev.inmo.plaguposter.ratings.exposed.ExposedRatingsRepo
import kotlinx.serialization.json.*
import org.jetbrains.exposed.sql.Database
import org.koin.core.module.Module
object Plugin : Plugin {
override fun Module.setupDI(database: Database, params: JsonObject) {
single { ExposedRatingsRepo(database, get<ExposedPostsRepo>().idColumn) }
}
}

View File

@ -0,0 +1,25 @@
package dev.inmo.plaguposter.ratings.exposed
import dev.inmo.micro_utils.repos.KeyValueRepo
import dev.inmo.micro_utils.repos.exposed.keyvalue.ExposedKeyValueRepo
import dev.inmo.micro_utils.repos.mappers.withMapper
import dev.inmo.plaguposter.posts.models.PostId
import dev.inmo.plaguposter.ratings.models.Rating
import dev.inmo.plaguposter.ratings.repo.RatingsRepo
import org.jetbrains.exposed.sql.Column
import org.jetbrains.exposed.sql.Database
class ExposedRatingsRepo(
database: Database,
postIdColumnReference: Column<String>
) : RatingsRepo, KeyValueRepo<PostId, Rating> by ExposedKeyValueRepo(
database,
{ text("post_id") references postIdColumnReference },
{ double("rating") },
"ratings"
).withMapper(
{ string },
{ double },
{ PostId(this) },
{ Rating(this) }
)

View File

@ -0,0 +1 @@
<manifest package="dev.inmo.plaguposter.ratings"/>

View File

@ -11,6 +11,7 @@ dependencies {
api project(":plaguposter.posts")
api project(":plaguposter.posts_registrar")
api project(":plaguposter.triggers.command")
api project(":plaguposter.ratings")
}
application {

View File

@ -4,6 +4,7 @@ String[] includes = [
":common",
":posts",
":posts_registrar",
":ratings",
":triggers:command",
":runner"
]