-
Notifications
You must be signed in to change notification settings - Fork 617
feat(core:domain): Migrate to KMP #2350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
biplab1
wants to merge
16
commits into
openMF:kmp-impl
Choose a base branch
from
biplab1:core-domain-migrate-to-kmp
base: kmp-impl
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
395a235
refactor(core:domain): initial setup for KMP
5cdc8ff
fix(core:domain): correct import statements for resources
552b69a
refactor(core:domain): remove rxjava usage
4b3262d
refactor(core:domain): replace callbackFlow with flow
2501afa
remove mistakenly added file
c7eb812
refactor(core:domain): removed try and catch block from inside flow
1839f52
Merge branch 'kmp-impl' into core-domain-migrate-to-kmp
5b6ec78
refactor(core:domain): remove try and catch blocks
242d4b0
fix(core:domain): apply spotless changes
1b10449
refactor(core): added MFErrorparser, migrated classes to KMP
6cdd557
Merge branch 'kmp-impl' into core-domain-migrate-to-kmp
cadbdfa
refactor(core:domain): use case to use combine
754cbd1
Merge branch 'kmp-impl' into core-domain-migrate-to-kmp
76c5d7a
merge kmp-impl branch
4cf9e44
refactor(core:domain): replace OpenAPI model imports with :core:netwo…
fd7a848
Merge branch 'kmp-impl' into core-domain-migrate-to-kmp
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
core/common/src/commonMain/kotlin/com/mifos/core/common/utils/MFErrorParser.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2025 Mifos Initiative | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* See https://github.com/openMF/android-client/blob/master/LICENSE.md | ||
*/ | ||
package com.mifos.core.common.utils | ||
|
||
import com.mifos.core.model.objects.error.MifosError | ||
import io.ktor.client.plugins.ClientRequestException | ||
import io.ktor.client.plugins.ServerResponseException | ||
import io.ktor.client.statement.bodyAsText | ||
import kotlinx.serialization.json.Json | ||
|
||
object MFErrorParser { | ||
const val LOG_TAG: String = "MFErrorParser" | ||
|
||
private val json: Json = Json { ignoreUnknownKeys = true } | ||
|
||
private fun parseError(serverResponse: String?): MifosError { | ||
return json.decodeFromString(serverResponse ?: "{}") | ||
} | ||
|
||
suspend fun errorMessage(throwableError: Throwable): String { | ||
return try { | ||
when (throwableError) { | ||
is ClientRequestException, is ServerResponseException -> { | ||
val response = (throwableError as? ClientRequestException)?.response | ||
?: (throwableError as? ServerResponseException)?.response | ||
val errorBody = response?.bodyAsText() ?: "" | ||
parseError(errorBody).errors.firstOrNull()?.defaultUserMessage | ||
?: "Something went wrong!" | ||
} | ||
|
||
else -> throwableError.message ?: "Unknown error" | ||
} | ||
} catch (exception: Exception) { | ||
"Error processing response" | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...src/androidMain/kotlin/com/mifos/core/domain/useCases/UploadClientImageUseCase.android.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright 2025 Mifos Initiative | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* See https://github.com/openMF/android-client/blob/master/LICENSE.md | ||
*/ | ||
package com.mifos.core.domain.useCases | ||
|
||
import okhttp3.MediaType.Companion.toMediaTypeOrNull | ||
import okhttp3.MultipartBody | ||
import okhttp3.RequestBody.Companion.asRequestBody | ||
import java.io.File | ||
|
||
actual class PlatformFile(private val pngFile: File) { | ||
actual fun toMultipartData(): MultipartData { | ||
val requestFile = pngFile.asRequestBody("image/png".toMediaTypeOrNull()) | ||
val body = MultipartBody.Part.createFormData("file", pngFile.name, requestFile) | ||
return MultipartData(body) | ||
} | ||
} | ||
|
||
actual class MultipartData(val body: MultipartBody.Part) |
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
core/domain/src/commonMain/kotlin/com/mifos/core/domain/useCases/ActivateGroupUseCase.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2024 Mifos Initiative | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* See https://github.com/openMF/android-client/blob/master/LICENSE.md | ||
*/ | ||
package com.mifos.core.domain.useCases | ||
|
||
import com.mifos.core.common.utils.MFErrorParser | ||
import com.mifos.core.common.utils.Resource | ||
import com.mifos.core.data.repository.ActivateRepository | ||
import com.mifos.core.model.objects.clients.ActivatePayload | ||
import com.mifos.core.network.GenericResponse | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.flow | ||
|
||
class ActivateGroupUseCase( | ||
private val activateRepository: ActivateRepository, | ||
) { | ||
|
||
operator fun invoke( | ||
groupId: Int, | ||
groupPayload: ActivatePayload, | ||
): Flow<Resource<GenericResponse>> = flow { | ||
try { | ||
emit(Resource.Loading()) | ||
val response = activateRepository.activateGroup(groupId, groupPayload) | ||
emit(Resource.Success(response)) | ||
} catch (exception: Exception) { | ||
emit(Resource.Error(MFErrorParser.errorMessage(exception))) | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need this!?!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those are added for the following code in build.gradle of core:domain: