Skip to content

Commit

Permalink
Migration to atlas
Browse files Browse the repository at this point in the history
  • Loading branch information
mpetuska committed Apr 7, 2021
1 parent d097413 commit 725bf78
Show file tree
Hide file tree
Showing 62 changed files with 1,001 additions and 921 deletions.
9 changes: 5 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[*.{kt,kts}]
root = true

[*]
indent_size = 2
insert_final_newline = true
max_line_length = 280
disabled_rules=no-wildcard-imports
continuation_indent_size = 4
ij_kotlin_name_count_to_use_star_import = unset
131 changes: 0 additions & 131 deletions .gitlab-ci.yml

This file was deleted.

4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ afterEvaluate {
exclude("META-INF/*.DSA")
exclude("META-INF/*.RSA")
}

manifest {
attributes(
"Main-Class" to mainClassName,
Expand All @@ -107,7 +107,7 @@ afterEvaluate {
"Created-From" to Git.headCommitHash
)
}

inputs.property("mainClassName", mainClassName)
inputs.files(classpath)
inputs.files(jsBrowserDistribution.outputs)
Expand Down
2 changes: 1 addition & 1 deletion app/src/commonMain/kotlin/app/domain/LibraryCount.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package app.domain

import kotlinx.serialization.*
import kotlinx.serialization.Serializable

@Serializable
data class LibraryCount(val count: Long)
2 changes: 1 addition & 1 deletion app/src/commonMain/kotlin/app/domain/PagedResponse.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package app.domain

import kotlinx.serialization.*
import kotlinx.serialization.Serializable

@Serializable
data class PagedResponse<T>(
Expand Down
15 changes: 11 additions & 4 deletions app/src/commonMain/kotlin/app/service/LibraryService.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package app.service

import app.domain.*
import kamp.domain.*
import app.domain.LibraryCount
import app.domain.PagedResponse
import kamp.domain.KotlinMPPLibrary

expect class LibraryService {
suspend fun getAll(page: Int, size: Int = 20, search: String? = null, targets: Set<String>? = null): PagedResponse<KotlinMPPLibrary>
suspend fun getAll(
page: Int,
size: Int = 20,
search: String? = null,
targets: Set<String>? = null,
): PagedResponse<KotlinMPPLibrary>

suspend fun getCount(search: String? = null, targets: Set<String>? = null): LibraryCount

companion object
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package app.util

import org.kodein.di.*
import kotlin.properties.*
import kotlin.reflect.*
import org.kodein.di.DI
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty

class DIModule(
private val allowSilentOverride: Boolean = false,
Expand Down
30 changes: 18 additions & 12 deletions app/src/jsMain/kotlin/app/config/di.kt
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
package app.config

import app.service.*
import app.util.*
import io.ktor.client.*
import io.ktor.client.features.*
import io.ktor.client.features.json.*
import io.ktor.client.features.json.serializer.*
import io.ktor.http.*
import kotlinx.serialization.json.*
import org.kodein.di.*

import app.service.LibraryService
import app.util.DIModule
import io.ktor.client.HttpClient
import io.ktor.client.features.defaultRequest
import io.ktor.client.features.json.JsonFeature
import io.ktor.client.features.json.serializer.KotlinxSerializer
import io.ktor.http.ContentType
import io.ktor.http.contentType
import kotlinx.serialization.json.Json
import org.kodein.di.DI
import org.kodein.di.bind
import org.kodein.di.instance
import org.kodein.di.provider
import org.kodein.di.singleton

private val services by DIModule {
bind<LibraryService>() with provider { LibraryService(instance()) }
}

val di = DI {
bind() from provider {
Json {}
bind {
provider {
Json {}
}
}
bind<HttpClient>() with singleton {
HttpClient {
Expand Down
6 changes: 3 additions & 3 deletions app/src/jsMain/kotlin/app/config/env.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package app.config

import kotlinx.browser.*
import kotlinx.coroutines.*
import org.w3c.dom.*
import kotlinx.browser.window
import kotlinx.coroutines.await
import org.w3c.dom.Window

external interface AppEnv {
val API_URL: String
Expand Down
12 changes: 7 additions & 5 deletions app/src/jsMain/kotlin/app/index.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package app

import app.config.*
import app.store.thunk.*
import app.view.*
import dev.fritz2.dom.html.*
import kotlinx.coroutines.*
import app.config.loadEnv
import app.store.thunk.fetchLibraryCount
import app.store.thunk.fetchLibraryPage
import app.view.App
import dev.fritz2.dom.html.render
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch

suspend fun main() = coroutineScope {
loadEnv()
Expand Down
30 changes: 18 additions & 12 deletions app/src/jsMain/kotlin/app/service/LibraryService.kt
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
package app.service

import app.domain.*
import app.util.*
import io.ktor.client.*
import io.ktor.client.request.*
import kamp.domain.*
import app.domain.LibraryCount
import app.domain.PagedResponse
import app.util.toApi
import io.ktor.client.HttpClient
import io.ktor.client.request.get
import kamp.domain.KotlinMPPLibrary

actual class LibraryService(private val client: HttpClient) {
actual suspend fun getAll(page: Int, size: Int, search: String?, targets: Set<String>?): PagedResponse<KotlinMPPLibrary> {
actual suspend fun getAll(
page: Int,
size: Int,
search: String?,
targets: Set<String>?,
): PagedResponse<KotlinMPPLibrary> {
val pagination = "page=$page&size=$size"
val searchQuery = search?.let { "search=$it" } ?: ""
val targetsQuery = targets?.joinToString(prefix = "target=", separator = "&target=") ?: ""

return client.get("${path}${buildQuery(pagination, searchQuery, targetsQuery)}".toApi())
}

actual suspend fun getCount(search: String?, targets: Set<String>?): LibraryCount {
val searchQuery = search?.let { "search=$it" }
val targetsQuery = targets?.joinToString(prefix = "target=", separator = "&target=")
return client.get("${path}/count${buildQuery(searchQuery, targetsQuery)}".toApi())

return client.get("$path/count${buildQuery(searchQuery, targetsQuery)}".toApi())
}

private fun buildQuery(vararg query: String?): String {
return query.toSet().filterNotNull().takeIf(List<String>::isNotEmpty)?.joinToString("&", prefix = "?") ?: ""
}

actual companion object
}
22 changes: 11 additions & 11 deletions app/src/jsMain/kotlin/app/store/LibraryStore.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package app.store

import app.domain.*
import dev.fritz2.binding.*
import kamp.domain.*

import app.domain.PagedResponse
import dev.fritz2.binding.RootStore
import kamp.domain.KotlinMPPLibrary

object LibraryStore : RootStore<LibraryStore.LibraryState>(LibraryState()) {
data class LibraryState(
Expand All @@ -12,17 +11,18 @@ object LibraryStore : RootStore<LibraryStore.LibraryState>(LibraryState()) {
val targets: Set<String>? = null,
val count: Long? = null,
)

val setLibraries = handleAndEmit<PagedResponse<KotlinMPPLibrary>, PagedResponse<KotlinMPPLibrary>> { state, libraries ->
emit(libraries)
state.copy(libraries = libraries)
}


val setLibraries =
handleAndEmit<PagedResponse<KotlinMPPLibrary>, PagedResponse<KotlinMPPLibrary>> { state, libraries ->
emit(libraries)
state.copy(libraries = libraries)
}

val setSearch = handleAndEmit<String?, String?> { state, search ->
emit(search)
state.copy(search = search)
}

val setCount = handleAndEmit<Long?, Long?> { state, count ->
emit(count)
state.copy(count = count)
Expand Down
Loading

0 comments on commit 725bf78

Please sign in to comment.