Skip to content

Commit 94b0fc8

Browse files
authored
Merge pull request #7 from DevelopersBreach/shreyas/integrate-arrow-core
Integrate Arrow Core for exception handling
2 parents 8344543 + dcb3404 commit 94b0fc8

File tree

17 files changed

+220
-79
lines changed

17 files changed

+220
-79
lines changed

composeApp/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ kotlin {
9999
implementation(libs.koin.compose)
100100
implementation(libs.koin.compose.viewmodel)
101101
implementation(libs.kermit)
102+
implementation(libs.arrow.core)
103+
implementation(libs.arrow.fx.coroutines)
102104
}
103105
desktopMain.dependencies {
104106
implementation(compose.desktop.currentOs)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<resources>
3+
<string name="error_occurred">Error occurred</string>
4+
<string name="ok">OK</string>
5+
<string name="error_info_unavailable">Error information not available</string>
6+
</resources>

composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/core/ApiKey.kt

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package com.developersbreach.kotlindictionarymultiplatform.core.network
2+
3+
const val API_KEY = ""
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
package com.developersbreach.kotlindictionarymultiplatform.core
1+
package com.developersbreach.kotlindictionarymultiplatform.core.network
22

33
import com.developersbreach.kotlindictionarymultiplatform.Log
4-
import com.developersbreach.kotlindictionarymultiplatform.data.detail.ChatCompletionRequest
5-
import com.developersbreach.kotlindictionarymultiplatform.data.detail.ChatCompletionResponse
6-
import com.developersbreach.kotlindictionarymultiplatform.data.detail.ChatMessage
7-
import com.developersbreach.kotlindictionarymultiplatform.data.detail.FunctionDefinition
8-
import com.developersbreach.kotlindictionarymultiplatform.data.detail.KotlinTopicDetails
4+
import com.developersbreach.kotlindictionarymultiplatform.data.detail.model.ChatCompletionRequest
5+
import com.developersbreach.kotlindictionarymultiplatform.data.detail.model.ChatCompletionResponse
6+
import com.developersbreach.kotlindictionarymultiplatform.data.detail.model.ChatMessage
7+
import com.developersbreach.kotlindictionarymultiplatform.data.detail.model.FunctionDefinition
8+
import com.developersbreach.kotlindictionarymultiplatform.data.detail.model.KotlinTopicDetails
99
import io.ktor.client.HttpClient
1010
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
1111
import io.ktor.client.request.header
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.developersbreach.kotlindictionarymultiplatform.data.detail
1+
package com.developersbreach.kotlindictionarymultiplatform.data.detail.model
22

33
import kotlinx.serialization.Serializable
44
import kotlinx.serialization.SerialName
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.developersbreach.kotlindictionarymultiplatform.data.detail.repository
2+
3+
import arrow.core.Either
4+
import com.developersbreach.kotlindictionarymultiplatform.core.network.API_KEY
5+
import com.developersbreach.kotlindictionarymultiplatform.core.network.KtorHttpClient
6+
import com.developersbreach.kotlindictionarymultiplatform.data.detail.model.KotlinTopicDetails
7+
8+
class DetailRepository {
9+
10+
suspend fun fetchTopic(topicId: String): Either<Throwable, KotlinTopicDetails> =
11+
Either.catch {
12+
KtorHttpClient.generateTopicDetails(topicId, API_KEY)
13+
}
14+
}
Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
package com.developersbreach.kotlindictionarymultiplatform.data.topic.repository
22

3+
import arrow.core.Either
34
import com.developersbreach.kotlindictionarymultiplatform.data.topic.model.Topic
45

56
object TopicRepository {
6-
fun getTopics(): List<Topic> = listOf(
7-
Topic("Variables"),
8-
Topic("Strings"),
9-
Topic("Functions"),
10-
Topic("Coroutines"),
11-
Topic("Classes"),
12-
Topic("Interfaces"),
13-
Topic("Objects"),
14-
Topic("Collections"),
15-
Topic("Null Safety"),
16-
Topic("Lambdas"),
17-
Topic("Higher-Order Functions"),
18-
Topic("Delegation"),
19-
Topic("Sealed Classes"),
20-
Topic("Generics"),
21-
Topic("Annotations"),
22-
)
7+
fun getTopics(): Either<Throwable, List<Topic>> = Either.catch {
8+
listOf(
9+
Topic("Variables"),
10+
Topic("Strings"),
11+
Topic("Functions"),
12+
Topic("Coroutines"),
13+
Topic("Classes"),
14+
Topic("Interfaces"),
15+
Topic("Objects"),
16+
Topic("Collections"),
17+
Topic("Null Safety"),
18+
Topic("Lambdas"),
19+
Topic("Higher-Order Functions"),
20+
Topic("Delegation"),
21+
Topic("Sealed Classes"),
22+
Topic("Generics"),
23+
Topic("Annotations"),
24+
)
25+
}
2326
}
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
package com.developersbreach.kotlindictionarymultiplatform.di
22

3+
import com.developersbreach.kotlindictionarymultiplatform.data.detail.repository.DetailRepository
34
import org.koin.dsl.module
45
import com.developersbreach.kotlindictionarymultiplatform.ui.screens.detail.DetailViewModel
56
import com.developersbreach.kotlindictionarymultiplatform.ui.screens.topic.TopicViewModel
67
import org.koin.core.module.dsl.viewModel
8+
import androidx.lifecycle.SavedStateHandle
9+
import com.developersbreach.kotlindictionarymultiplatform.data.topic.repository.TopicRepository
710

811
val appModule = module {
9-
viewModel {
10-
DetailViewModel(get())
12+
single { DetailRepository() }
13+
single { TopicRepository }
14+
15+
viewModel { (handle: SavedStateHandle) ->
16+
DetailViewModel(handle, get())
1117
}
18+
1219
viewModel {
13-
TopicViewModel()
20+
TopicViewModel(get())
1421
}
1522
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.developersbreach.kotlindictionarymultiplatform.ui.components
2+
3+
import androidx.compose.material.AlertDialog
4+
import androidx.compose.material.Text
5+
import androidx.compose.material.TextButton
6+
import androidx.compose.runtime.Composable
7+
import androidx.compose.ui.Modifier
8+
import kotlindictionarymultiplatform.composeapp.generated.resources.Res
9+
import kotlindictionarymultiplatform.composeapp.generated.resources.ok
10+
import org.jetbrains.compose.resources.stringResource
11+
12+
@Composable
13+
fun ShowAlertDialog(
14+
onButtonClick: () -> Unit,
15+
modifier: Modifier = Modifier,
16+
title: String,
17+
description: String,
18+
) {
19+
AlertDialog(
20+
onDismissRequest = onButtonClick,
21+
title = { Text(title) },
22+
text = { Text(description) },
23+
confirmButton = {
24+
TextButton(onClick = onButtonClick) {
25+
Text(text = stringResource(Res.string.ok))
26+
}
27+
},
28+
modifier = modifier,
29+
)
30+
}

0 commit comments

Comments
 (0)