refactor (core:network ) Network converted to KMP#2346
refactor (core:network ) Network converted to KMP#2346therajanmaurya merged 29 commits intoopenMF:kmp-implfrom
Conversation
# Conflicts: # core/network/build.gradle.kts
|
@biplab1 review it once if things are ok then we can merge this and complete the data and domain next |
core/network/src/commonMain/kotlin/com/mifos/core/network/BaseApiManager.kt
Outdated
Show resolved
Hide resolved
biplab1
left a comment
There was a problem hiding this comment.
These are some minor changes that needs to be addressed.
Also, add @OptIn(ExperimentalCoroutinesApi::class) to functions using flatMapLatest in DataManagers
| if (dueDateList.size > 2) { | ||
| return String.format(pattern, dueDateList[0], dueDateList[1], dueDateList[2]) | ||
| return "" | ||
| // return String.format(pattern, dueDateList[0], dueDateList[1], dueDateList[2]) |
There was a problem hiding this comment.
Can you tell me the reason for commenting out this code?
There was a problem hiding this comment.
by mistake uncommented it
core/network/build.gradle.kts
Outdated
| id("kotlinx-serialization") | ||
| id("com.google.devtools.ksp") |
There was a problem hiding this comment.
Please use version catalog instead:
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.ksp)
| @@ -47,15 +47,15 @@ class DataManagerCheckerInbox( | |||
| return mBaseApiManager.checkerInboxApi.getRescheduleLoansTaskList() | |||
There was a problem hiding this comment.
"getRechdeduleLoansTaskList" should be "getRescheduleLoansTaskList"
There was a problem hiding this comment.
I didn't understood . It's already getRescheduleLoansTaskList
| resourceId: Int?, | ||
| ): Flow<List<CheckerTask>> { | ||
| return flow { emit(dataManagerCheckerInbox.getCheckerTaskList()) } | ||
| return dataManagerCheckerInbox.getCheckerTaskList() |
There was a problem hiding this comment.
So due to Github limitation, I cannot comment on the lines that are outside this PR, so I am adding it here. In line no. 27 of this file,
"getRechdeduleLoansTaskList" should be "getRescheduleLoansTaskList"
| ) | ||
| clientsTemplate | ||
| } | ||
| flow { |
There was a problem hiding this comment.
clientTemplate should be marked with @OptIn(ExperimentalCoroutinesApi::class)
@OptIn(ExperimentalCoroutinesApi::class)
val clientTemplate: Flow<ClientsTemplateEntity>| @Serializable | ||
| data class GetCentersResponse( | ||
|
|
||
| val pageItems: kotlin.collections.Set<GetCentersPageItems>? = null, |
There was a problem hiding this comment.
kotlin.collections is redundant here and can be removed.
Similarly, other files in :core:network:model makes use of it, please check and update.
|
|
||
| val columnName: kotlin.String? = null, | ||
|
|
||
| val columnType: ResultsetColumnHeaderData.ColumnType? = null, |
There was a problem hiding this comment.
Here ResultsetColumnHeaderData is redundant. It is better to remove. There are two occurrences in this file.
There was a problem hiding this comment.
Please use an alternative to import java.util.Date which is compatible with KMP. Try using
import kotlinx.datetime.Instant and Instant in place of Date data type.
|
|
||
| @GET(APIEndPoint.MAKER_CHECKER + "/searchtemplate?fields=entityNames,actionNames") | ||
| fun getCheckerInboxSearchTempalate(): Observable<CheckerInboxSearchTemplate> | ||
| fun getCheckerInboxSearchTempalate(): Flow<CheckerInboxSearchTemplate> |
There was a problem hiding this comment.
getCheckerInboxSearchTempalate should be getCheckerInboxSearchTemplate. Please make appropriate changes in places where it is used.
There was a problem hiding this comment.
Line 40: saveindividualCollectionSheet should be saveIndividualCollectionSheet. Also, make changes where it is used.
|
@revanthkumarJ Just a quick note for future reference — it's best to leave the review comments unresolved even after you've fixed them. That way, maintainers and reviewers can go through and verify the changes before marking them resolved. |
|
@revanthkumarJ I have seen below in many places I give an example change all of them accordingly.
Api DataManager Repository UseCase (it is just an example fix it accordingly) |
| interface GenerateCollectionSheetRepository { | ||
|
|
||
| suspend fun getCentersInOffice(id: Int, params: Map<String, String>): List<CenterEntity> | ||
| suspend fun getCentersInOffice(id: Int, params: Map<String, String>): Flow<List<CenterEntity>> |
There was a problem hiding this comment.
why some functions like these are at the same time suspend and flowable
There was a problem hiding this comment.
ok i will resolve them . actually they belongs to data module at first i tried to resolve the things to make application run but later Rajan sir told that it will be done during data module migration
There was a problem hiding this comment.
@revanthkumarJ ok then keep your scope to your own and change it to where it belongs to your module. If it is sth like that can you revert it back so someone who works in data module should get any conflicts. and for them it might be confusing like ok it's suspend and at the same time stream and they keep it
|
|
||
| @GET(APIEndPoint.GROUPS) | ||
| suspend fun getAllGroupsInOffice( | ||
| fun getAllGroupsInOffice( |
There was a problem hiding this comment.
I see the API call previously was suspend not a stream. so keep it suspend. and you manually wrap it in flow {} at repository layer or wherever it is called.
There was a problem hiding this comment.
Or in the above i provided an example if you change it to stream how to do it. In chain some places you added both suspent and return type flow, in some places you removed suspend.
There was a problem hiding this comment.
in nagarjuna pr niyaj brother mentioned that if any service returns list make it flow and remove suspend i followed that .
There was a problem hiding this comment.
yes cause of that in my second message i mentioned that if you remove the suspend and add flow what you should do in other files that calls it
There was a problem hiding this comment.
yah after the domain and data are merged we have to change in all feature modules where they are called.
In mifos-mobile we have done similarly
There was a problem hiding this comment.
What niyaj mentioned in mifos-mobile network module conversion is
Few things to change I'm commenting on one place
if the function return as List or Observable then convert into Flow<List> or Flow
If the function return as a Flow then that shouldn't be suspend fun, so remove suspend modifier from function.
| override suspend fun uploadClientImage(id: Int, file: MultipartBody.Part?) { | ||
| dataManagerClient.uploadClientImage(id, file) | ||
| override suspend fun uploadClientImage(id: Int, file: PartData?) { | ||
| // dataManagerClient.uploadClientImage(id, file) |
There was a problem hiding this comment.
why you commented this one?
There was a problem hiding this comment.
uncommneted it was a mistake
|
|
||
| override fun offices(): Flow<List<OfficeEntity>> { | ||
| return dataManagerOffices.offices() | ||
| return dataManagerOffices.offices |
There was a problem hiding this comment.
previously it was calling offices() from DataManagerOffices, which you changed it to fetchOffices. But now you are calling offices not fetchOffices. what is the reason?
There was a problem hiding this comment.
resolved, used fetchoffices()
| ): Flow<SavingsAccountTransactionTemplateEntity?> { | ||
| return dataManagerSavings.getSavingsAccountTransactionTemplate( | ||
| type, | ||
| type!!, |
There was a problem hiding this comment.
- Don't force it like this in here that it is not null. If it is always not null then change the
typetype toStringwherever it is called.
| * This Method Request the REST API of Note and In response give the List of Notes | ||
| */ | ||
| fun getNotes(entityType: String?, entityId: Int): List<Note> { | ||
| fun getNotes(entityType: String, entityId: Int): List<Note> { |
There was a problem hiding this comment.
you changed the entityType type from String? to String. are you sure that when this function is called they entityType is not null, and also the actual api getNotes(...) only accept String cause of that you changed?
There was a problem hiding this comment.
The reason i done that is when i runned the application it showed the error like path parameter in ktorfit should not be null
| .apply { | ||
| logger(DebugLogger()) | ||
| }.build() | ||
| single { (context: Any) -> |
There was a problem hiding this comment.
This DI injection looks so messy. I haven't work on network, but ask @niyajali to review this file for you.
| code = entity.status?.code, | ||
| value = entity.status?.description, | ||
| code = entity.status.code, | ||
| value = entity.status.description, |
There was a problem hiding this comment.
Does GetGroupsStatus code and description is not nullable that you removed safe call?
There was a problem hiding this comment.
I don't think so so make it safe call
| @get:GET(APIEndPoint.CLIENTS + "/template") | ||
| val clientTemplate: Flow<ClientsTemplateEntity> | ||
| @GET(APIEndPoint.CLIENTS + "/template") | ||
| suspend fun getClientTemplate(): ClientsTemplateEntity |
There was a problem hiding this comment.
why you are making it suspend when it is stream
There was a problem hiding this comment.
it is not stream the below function to it is Flow it is not suspend function
| entityName: String? = null, | ||
| resourceId: Int? = null, | ||
| ): List<CheckerTask> | ||
| ): Flow<List<CheckerTask>> |
There was a problem hiding this comment.
when it is suspend why adding flow, maybe in the UseCase that it is called it will call this suspend function and then emit it accordigly
|
@biplab1 @HekmatullahAmin i have done all the suggestions you guys mentioned , see it once if i have missed anything let me know before standup i will do it |
| interface ClientDetailsRepository { | ||
|
|
||
| suspend fun uploadClientImage(id: Int, file: MultipartBody.Part?) | ||
| suspend fun uploadClientImage(id: Int, file: PartData?) |
There was a problem hiding this comment.
Are these two equivalent— okhttp3.MultipartBody and io.ktor.http.content.PartData? They must be having different APIs and hence different implementations.
There was a problem hiding this comment.
yes they have different implementations , while passing the the things in domain we have to take care of it
There was a problem hiding this comment.
I have taken reference from mifos-wallet there MultipartBody.Part? is replaced with PartData
There was a problem hiding this comment.
Thanks for the information
* initial setup * updated * Updated * Changed Imports in Services * Updated * Updated * Added ktorHttpClient * Added ktorHttpClient * Updated * Updated * Updated * updated mappers * updated mappers * Updated * Updated * Updated * Updated * Updated * Updated ImageLoader.Utils * changed observable to flow in data * Updated * Updated * Updated * Updated based on suggestions * Updated * Updated * Updated
* initial setup * updated * Updated * Changed Imports in Services * Updated * Updated * Added ktorHttpClient * Added ktorHttpClient * Updated * Updated * Updated * updated mappers * updated mappers * Updated * Updated * Updated * Updated * Updated * Updated ImageLoader.Utils * changed observable to flow in data * Updated * Updated * Updated * Updated based on suggestions * Updated * Updated * Updated


Fixes - Jira-#402
Didn't create a Jira ticket, click here to create new.
Please Add Screenshots If there are any UI changes.
Please make sure these boxes are checked before submitting your pull request - thanks!
Run the static analysis check
./gradlew checkorci-prepush.shto make sure you didn't break anythingIf you have multiple commits please combine them into one commit by squashing them.