mirror of
https://github.com/InsanusMokrassar/PlaguPoster.git
synced 2024-12-22 14:07:14 +00:00
add ratings
This commit is contained in:
parent
c4e7f338a9
commit
aa9f187203
22
ratings/build.gradle
Normal file
22
ratings/build.gradle
Normal 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 {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
1
ratings/src/commonMain/kotlin/PackageInfo.kt
Normal file
1
ratings/src/commonMain/kotlin/PackageInfo.kt
Normal file
@ -0,0 +1 @@
|
|||||||
|
package dev.inmo.plaguposter.ratings
|
10
ratings/src/commonMain/kotlin/models/Rating.kt
Normal file
10
ratings/src/commonMain/kotlin/models/Rating.kt
Normal 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
|
||||||
|
)
|
7
ratings/src/commonMain/kotlin/repo/RatingsRepo.kt
Normal file
7
ratings/src/commonMain/kotlin/repo/RatingsRepo.kt
Normal 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
|
7
ratings/src/commonMain/kotlin/repo/ReadRatingsRepo.kt
Normal file
7
ratings/src/commonMain/kotlin/repo/ReadRatingsRepo.kt
Normal 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>
|
7
ratings/src/commonMain/kotlin/repo/WriteRatingsRepo.kt
Normal file
7
ratings/src/commonMain/kotlin/repo/WriteRatingsRepo.kt
Normal 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>
|
14
ratings/src/jvmMain/kotlin/Plugin.kt
Normal file
14
ratings/src/jvmMain/kotlin/Plugin.kt
Normal 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) }
|
||||||
|
}
|
||||||
|
}
|
25
ratings/src/jvmMain/kotlin/exposed/ExposedRatingsRepo.kt
Normal file
25
ratings/src/jvmMain/kotlin/exposed/ExposedRatingsRepo.kt
Normal 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) }
|
||||||
|
)
|
1
ratings/src/main/AndroidManifest.xml
Normal file
1
ratings/src/main/AndroidManifest.xml
Normal file
@ -0,0 +1 @@
|
|||||||
|
<manifest package="dev.inmo.plaguposter.ratings"/>
|
@ -11,6 +11,7 @@ dependencies {
|
|||||||
api project(":plaguposter.posts")
|
api project(":plaguposter.posts")
|
||||||
api project(":plaguposter.posts_registrar")
|
api project(":plaguposter.posts_registrar")
|
||||||
api project(":plaguposter.triggers.command")
|
api project(":plaguposter.triggers.command")
|
||||||
|
api project(":plaguposter.ratings")
|
||||||
}
|
}
|
||||||
|
|
||||||
application {
|
application {
|
||||||
|
@ -4,6 +4,7 @@ String[] includes = [
|
|||||||
":common",
|
":common",
|
||||||
":posts",
|
":posts",
|
||||||
":posts_registrar",
|
":posts_registrar",
|
||||||
|
":ratings",
|
||||||
":triggers:command",
|
":triggers:command",
|
||||||
":runner"
|
":runner"
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user