From aa9f18720367f608ddf526e017f552b5f60ae708 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Sun, 21 Aug 2022 16:03:27 +0600 Subject: [PATCH] add ratings --- ratings/build.gradle | 22 ++++++++++++++++ ratings/src/commonMain/kotlin/PackageInfo.kt | 1 + .../src/commonMain/kotlin/models/Rating.kt | 10 ++++++++ .../src/commonMain/kotlin/repo/RatingsRepo.kt | 7 ++++++ .../commonMain/kotlin/repo/ReadRatingsRepo.kt | 7 ++++++ .../kotlin/repo/WriteRatingsRepo.kt | 7 ++++++ ratings/src/jvmMain/kotlin/Plugin.kt | 14 +++++++++++ .../kotlin/exposed/ExposedRatingsRepo.kt | 25 +++++++++++++++++++ ratings/src/main/AndroidManifest.xml | 1 + runner/build.gradle | 1 + settings.gradle | 1 + 11 files changed, 96 insertions(+) create mode 100644 ratings/build.gradle create mode 100644 ratings/src/commonMain/kotlin/PackageInfo.kt create mode 100644 ratings/src/commonMain/kotlin/models/Rating.kt create mode 100644 ratings/src/commonMain/kotlin/repo/RatingsRepo.kt create mode 100644 ratings/src/commonMain/kotlin/repo/ReadRatingsRepo.kt create mode 100644 ratings/src/commonMain/kotlin/repo/WriteRatingsRepo.kt create mode 100644 ratings/src/jvmMain/kotlin/Plugin.kt create mode 100644 ratings/src/jvmMain/kotlin/exposed/ExposedRatingsRepo.kt create mode 100644 ratings/src/main/AndroidManifest.xml diff --git a/ratings/build.gradle b/ratings/build.gradle new file mode 100644 index 0000000..779ca41 --- /dev/null +++ b/ratings/build.gradle @@ -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 { + } + } + } +} diff --git a/ratings/src/commonMain/kotlin/PackageInfo.kt b/ratings/src/commonMain/kotlin/PackageInfo.kt new file mode 100644 index 0000000..c14cfd1 --- /dev/null +++ b/ratings/src/commonMain/kotlin/PackageInfo.kt @@ -0,0 +1 @@ +package dev.inmo.plaguposter.ratings diff --git a/ratings/src/commonMain/kotlin/models/Rating.kt b/ratings/src/commonMain/kotlin/models/Rating.kt new file mode 100644 index 0000000..4f97d96 --- /dev/null +++ b/ratings/src/commonMain/kotlin/models/Rating.kt @@ -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 +) diff --git a/ratings/src/commonMain/kotlin/repo/RatingsRepo.kt b/ratings/src/commonMain/kotlin/repo/RatingsRepo.kt new file mode 100644 index 0000000..add8c9f --- /dev/null +++ b/ratings/src/commonMain/kotlin/repo/RatingsRepo.kt @@ -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, ReadRatingsRepo, WriteRatingsRepo diff --git a/ratings/src/commonMain/kotlin/repo/ReadRatingsRepo.kt b/ratings/src/commonMain/kotlin/repo/ReadRatingsRepo.kt new file mode 100644 index 0000000..f3845ed --- /dev/null +++ b/ratings/src/commonMain/kotlin/repo/ReadRatingsRepo.kt @@ -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 diff --git a/ratings/src/commonMain/kotlin/repo/WriteRatingsRepo.kt b/ratings/src/commonMain/kotlin/repo/WriteRatingsRepo.kt new file mode 100644 index 0000000..230b050 --- /dev/null +++ b/ratings/src/commonMain/kotlin/repo/WriteRatingsRepo.kt @@ -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 diff --git a/ratings/src/jvmMain/kotlin/Plugin.kt b/ratings/src/jvmMain/kotlin/Plugin.kt new file mode 100644 index 0000000..f602f06 --- /dev/null +++ b/ratings/src/jvmMain/kotlin/Plugin.kt @@ -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().idColumn) } + } +} diff --git a/ratings/src/jvmMain/kotlin/exposed/ExposedRatingsRepo.kt b/ratings/src/jvmMain/kotlin/exposed/ExposedRatingsRepo.kt new file mode 100644 index 0000000..a0877b6 --- /dev/null +++ b/ratings/src/jvmMain/kotlin/exposed/ExposedRatingsRepo.kt @@ -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 +) : RatingsRepo, KeyValueRepo by ExposedKeyValueRepo( + database, + { text("post_id") references postIdColumnReference }, + { double("rating") }, + "ratings" +).withMapper( + { string }, + { double }, + { PostId(this) }, + { Rating(this) } +) diff --git a/ratings/src/main/AndroidManifest.xml b/ratings/src/main/AndroidManifest.xml new file mode 100644 index 0000000..fc44e89 --- /dev/null +++ b/ratings/src/main/AndroidManifest.xml @@ -0,0 +1 @@ + diff --git a/runner/build.gradle b/runner/build.gradle index 0b00030..7548453 100644 --- a/runner/build.gradle +++ b/runner/build.gradle @@ -11,6 +11,7 @@ dependencies { api project(":plaguposter.posts") api project(":plaguposter.posts_registrar") api project(":plaguposter.triggers.command") + api project(":plaguposter.ratings") } application { diff --git a/settings.gradle b/settings.gradle index 60105c3..715c3d2 100644 --- a/settings.gradle +++ b/settings.gradle @@ -4,6 +4,7 @@ String[] includes = [ ":common", ":posts", ":posts_registrar", + ":ratings", ":triggers:command", ":runner" ]