Skip to content

Commit

Permalink
set ktlint
Browse files Browse the repository at this point in the history
  • Loading branch information
VladimirTambovtsev committed Feb 25, 2022
1 parent 499ec59 commit cfd6863
Show file tree
Hide file tree
Showing 37 changed files with 168 additions and 178 deletions.
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
root = true

[*.{kt, kts}]
disabled_rules = no-wildcard-imports, import-ordering, no-trailing-spaces
indent_size=4
insert_final_newline=true
4 changes: 2 additions & 2 deletions iosFood/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
17 changes: 15 additions & 2 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
id("com.android.library")
kotlin("plugin.serialization") version "1.6.10"
id("com.squareup.sqldelight")
id("org.jlleitschuh.gradle.ktlint") version "10.2.1"
}

version = "1.0"
Expand Down Expand Up @@ -97,10 +98,22 @@ android {
}
}


sqldelight {
database("RecipeDatabase") {
packageName = "pro.tambovtsev.kmmrestfood.datasource.cache"
sourceFolders = listOf("sqldelight")
}
}
}

//
// application {
// mainClass.set("org.jlleitschuh.gradle.ktlint.sample.mpp.MainKt")
// }
ktlint {
// verbose.set(true)
// outputToConsole.set(true)
filter {
exclude("**/build/**")
exclude("**/generated/**")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ actual class DriverFactory(private val context: Context) {
actual fun createDriver(): SqlDriver {
return AndroidSqliteDriver(RecipeDatabase.Schema, context, "recipes.db")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ actual class KtorClientFactory {
actual fun build(): HttpClient {
return HttpClient(Android) {
install(JsonFeature) {
serializer = KotlinxSerializer(kotlinx.serialization.json.Json {
ignoreUnknownKeys = true
})
serializer = KotlinxSerializer(
kotlinx.serialization.json.Json {
ignoreUnknownKeys = true
}
)
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package pro.tambovtsev.kmmrestfood.presentation.recipe_list

import pro.tambovtsev.kmmrestfood.domain.model.Recipe
import pro.tambovtsev.kmmrestfood.domain.model.GenericMessageInfo
import pro.tambovtsev.kmmrestfood.domain.model.Recipe
import pro.tambovtsev.kmmrestfood.domain.util.Queue

actual data class RecipeListState(
Expand All @@ -11,4 +11,4 @@ actual data class RecipeListState(
val selectedCategory: FoodCategory? = null,
val recipes: List<Recipe> = listOf(),
val queue: Queue<GenericMessageInfo> = Queue(mutableListOf()), // messages to be displayed in ui
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import pro.tambovtsev.kmmrestfood.datasource.network.RecipeServiceImpl.Companion
import pro.tambovtsev.kmmrestfood.domain.model.Recipe
import pro.tambovtsev.kmmrestfood.domain.util.DatetimeUtil



class RecipeCacheImpl(
val recipeDatabase: RecipeDatabase,
private val datetimeUtil: DatetimeUtil,
): RecipeCache {
) : RecipeCache {

private var queries: RecipeDBQueries = recipeDatabase.recipeDBQueries

Expand All @@ -28,7 +26,7 @@ class RecipeCacheImpl(
}

override fun insert(recipes: List<Recipe>) {
for(recipe in recipes){
for (recipe in recipes) {
insert(recipe)
}
}
Expand All @@ -53,8 +51,8 @@ class RecipeCacheImpl(
queries
.getRecipeById(id = recipeId.toLong())
.executeAsOne().toRecipe()
}catch (e: NullPointerException){
} catch (e: NullPointerException) {
null
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import com.squareup.sqldelight.db.SqlDriver
import pro.tambovtsev.kmmrestfood.domain.model.Recipe
import pro.tambovtsev.kmmrestfood.domain.util.DatetimeUtil


class RecipeDatabaseFactory(
private val driverFactory: DriverFactory
){
) {
fun createDatabase(): RecipeDatabase {
return RecipeDatabase(driverFactory.createDriver())
}
Expand All @@ -32,24 +31,24 @@ fun Recipe_Entity.toRecipe(): Recipe {
)
}

fun List<Recipe_Entity>.toRecipeList(): List<Recipe>{
return map{it.toRecipe()}
fun List<Recipe_Entity>.toRecipeList(): List<Recipe> {
return map { it.toRecipe() }
}

/**
* "Carrot, potato, Chicken, ..."
*/
fun List<String>.convertIngredientListToString(): String {
val ingredientsString = StringBuilder()
for(ingredient in this){
for (ingredient in this) {
ingredientsString.append("$ingredient,")
}
return ingredientsString.toString()
}

fun String.convertIngredientsToList(): List<String>{
fun String.convertIngredientsToList(): List<String> {
val list: ArrayList<String> = ArrayList()
for(ingredient in split(",")){
for (ingredient in split(",")) {
list.add(ingredient)
}
return list
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package pro.tambovtsev.kmmrestfood.datasource.network


import io.ktor.client.*
import pro.tambovtsev.kmmrestfood.datasource.network.model.RecipeDto
import pro.tambovtsev.kmmrestfood.domain.model.Recipe
Expand All @@ -26,5 +25,5 @@ fun RecipeDto.toRecipe(): Recipe {
}

fun List<RecipeDto>.toRecipeList(): List<Recipe> {
return map{ it.toRecipe() }
}
return map { it.toRecipe() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ interface RecipeService {
suspend fun search(page: Int, query: String): List<Recipe>

suspend fun get(id: Int): Recipe
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,21 @@ import pro.tambovtsev.kmmrestfood.datasource.network.model.RecipeDto
import pro.tambovtsev.kmmrestfood.datasource.network.model.RecipeSearchResponse
import pro.tambovtsev.kmmrestfood.domain.model.Recipe


class RecipeServiceImpl(
private val httpClient: HttpClient,
private val baseUrl: String,
): RecipeService {
) : RecipeService {

override suspend fun search(page: Int, query: String): List<Recipe> {
return httpClient.get<RecipeSearchResponse>{
return httpClient.get<RecipeSearchResponse> {
url("$baseUrl/search?page=$page&query=$query")
header("Authorization", TOKEN)
}
.results.toRecipeList()
}

override suspend fun get(id: Int): Recipe {
return httpClient.get<RecipeDto>{
return httpClient.get<RecipeDto> {
url("$baseUrl/get?id=$id")
header("Authorization", TOKEN)
}.toRecipe()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,30 @@ import kotlinx.serialization.Serializable
@Serializable
data class RecipeDto(

@SerialName("pk")
@SerialName("pk")
var pk: Int,

@SerialName("title")
@SerialName("title")
var title: String,

@SerialName("publisher")
@SerialName("publisher")
var publisher: String,

@SerialName("featured_image")
@SerialName("featured_image")
var featuredImage: String,

@SerialName("rating")
@SerialName("rating")
var rating: Int = 0,

@SerialName("source_url")
@SerialName("source_url")
var sourceUrl: String,

@SerialName("ingredients")
@SerialName("ingredients")
var ingredients: List<String> = emptyList(),

@SerialName("long_date_added")
@SerialName("long_date_added")
var longDateAdded: Long,

@SerialName("long_date_updated")
@SerialName("long_date_updated")
var longDateUpdated: Long,
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class RecipeSearchResponse (
@SerialName("count")
data class RecipeSearchResponse(
@SerialName("count")
var count: Long,

@SerialName("results")
@SerialName("results")
var results: List<RecipeDto>
)
)
Loading

0 comments on commit cfd6863

Please sign in to comment.