Skip to content

Commit c3aaec1

Browse files
authored
Client Add/Edit Note (#2480)
1 parent 873a49a commit c3aaec1

File tree

19 files changed

+852
-141
lines changed

19 files changed

+852
-141
lines changed

cmp-navigation/src/commonMain/kotlin/cmp/navigation/navigation/FeatureNavHost.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ import com.mifos.feature.loan.navigation.loanNavGraph
4646
import com.mifos.feature.loan.navigation.navigateToGroupLoanScreen
4747
import com.mifos.feature.loan.navigation.navigateToLoanAccountScreen
4848
import com.mifos.feature.loan.navigation.navigateToLoanAccountSummaryScreen
49-
import com.mifos.feature.note.navigation.navigateToNoteScreen
5049
import com.mifos.feature.note.navigation.noteNavGraph
50+
import com.mifos.feature.note.notes.navigateToNoteScreen
5151
import com.mifos.feature.offline.navigation.offlineNavGraph
5252
import com.mifos.feature.path.tracking.navigation.pathTrackingNavGraph
5353
import com.mifos.feature.report.navigation.reportNavGraph

core/common/src/commonMain/kotlin/com/mifos/core/common/utils/DateHelper.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,4 +409,24 @@ object DateHelper {
409409
require(month in 1..12) { "Month should be between 1 and 12" }
410410
return Month.entries[month - 1].name.lowercase().replaceFirstChar { it.uppercase() }
411411
}
412+
413+
/**
414+
* This method is used to Convert IOS string date into dd MM yyyy formate
415+
* @param isoString take IOS date as a String
416+
* Example : ISO string 2025-08-28T16:02:32.242705+05:30 and return 28 08 2025
417+
*/
418+
fun formatIsoDateToDdMmYyyy(isoString: String): String {
419+
// Parse the string into an Instant
420+
val instant = Instant.parse(isoString)
421+
422+
// Convert to LocalDateTime in system timezone
423+
val localDate = instant.toLocalDateTime(TimeZone.currentSystemDefault()).date
424+
425+
val day = localDate.dayOfMonth.toString().padStart(2, '0')
426+
val monthName = localDate.month.name.lowercase()
427+
.replaceFirstChar { it.uppercase() } // "January", "February", etc.
428+
val year = localDate.year
429+
430+
return "$day $monthName $year"
431+
}
412432
}

core/domain/src/commonMain/kotlin/com/mifos/core/domain/di/UseCaseModule.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import com.mifos.core.domain.useCases.ActivateGroupUseCase
1515
import com.mifos.core.domain.useCases.ActivateSavingsUseCase
1616
import com.mifos.core.domain.useCases.AddClientPinpointLocationUseCase
1717
import com.mifos.core.domain.useCases.AddDataTableEntryUseCase
18+
import com.mifos.core.domain.useCases.AddNoteUseCase
1819
import com.mifos.core.domain.useCases.ApproveCheckerUseCase
1920
import com.mifos.core.domain.useCases.ApproveSavingsApplicationUseCase
2021
import com.mifos.core.domain.useCases.CreateChargesUseCase
@@ -28,6 +29,7 @@ import com.mifos.core.domain.useCases.DeleteCheckerUseCase
2829
import com.mifos.core.domain.useCases.DeleteClientAddressPinpointUseCase
2930
import com.mifos.core.domain.useCases.DeleteDataTableEntryUseCase
3031
import com.mifos.core.domain.useCases.DeleteIdentifierUseCase
32+
import com.mifos.core.domain.useCases.DeleteNoteUseCase
3133
import com.mifos.core.domain.useCases.DownloadDocumentUseCase
3234
import com.mifos.core.domain.useCases.FetchCenterDetailsUseCase
3335
import com.mifos.core.domain.useCases.FetchCollectionSheetUseCase
@@ -75,6 +77,7 @@ import com.mifos.core.domain.useCases.ServerConfigValidatorUseCase
7577
import com.mifos.core.domain.useCases.SubmitCollectionSheetUseCase
7678
import com.mifos.core.domain.useCases.SubmitProductiveSheetUseCase
7779
import com.mifos.core.domain.useCases.UpdateClientPinpointUseCase
80+
import com.mifos.core.domain.useCases.UpdateNoteUseCase
7881
import com.mifos.core.domain.useCases.UploadClientImageUseCase
7982
import com.mifos.core.domain.useCases.UsernameValidationUseCase
8083
import com.mifos.core.domain.useCases.ValidateServerApiPathUseCase
@@ -159,4 +162,7 @@ val UseCaseModule = module {
159162
factoryOf(::GetGroupDetailsUseCase)
160163
factoryOf(::GetLoanAndLoanRepaymentUseCase)
161164
factoryOf(::GetSavingsAccountAndTemplateUseCase)
165+
factoryOf(::AddNoteUseCase)
166+
factoryOf(::UpdateNoteUseCase)
167+
factoryOf(::DeleteNoteUseCase)
162168
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2025 Mifos Initiative
3+
*
4+
* This Source Code Form is subject to the terms of the Mozilla Public
5+
* License, v. 2.0. If a copy of the MPL was not distributed with this
6+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
7+
*
8+
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
9+
*/
10+
package com.mifos.core.domain.useCases
11+
12+
import com.mifos.core.common.utils.DataState
13+
import com.mifos.core.common.utils.asDataStateFlow
14+
import com.mifos.core.data.repository.NoteRepository
15+
import com.mifos.core.model.objects.payloads.NotesPayload
16+
import com.mifos.core.network.GenericResponse
17+
import kotlinx.coroutines.flow.Flow
18+
import kotlinx.coroutines.flow.flow
19+
20+
class AddNoteUseCase(
21+
val repository: NoteRepository,
22+
) {
23+
operator fun invoke(
24+
resourceType: String,
25+
resourceId: Long,
26+
notesPayload: NotesPayload,
27+
): Flow<DataState<GenericResponse>> = flow {
28+
emit(repository.addNewNote(resourceType, resourceId, notesPayload))
29+
}.asDataStateFlow()
30+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2025 Mifos Initiative
3+
*
4+
* This Source Code Form is subject to the terms of the Mozilla Public
5+
* License, v. 2.0. If a copy of the MPL was not distributed with this
6+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
7+
*
8+
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
9+
*/
10+
package com.mifos.core.domain.useCases
11+
12+
import com.mifos.core.common.utils.DataState
13+
import com.mifos.core.common.utils.asDataStateFlow
14+
import com.mifos.core.data.repository.NoteRepository
15+
import com.mifos.core.network.GenericResponse
16+
import kotlinx.coroutines.flow.Flow
17+
import kotlinx.coroutines.flow.flow
18+
19+
class DeleteNoteUseCase(
20+
val repository: NoteRepository,
21+
) {
22+
operator fun invoke(
23+
resourceType: String,
24+
resourceId: Long,
25+
noteId: Long,
26+
): Flow<DataState<GenericResponse>> = flow {
27+
emit(repository.deleteNote(resourceType, resourceId, noteId))
28+
}.asDataStateFlow()
29+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2025 Mifos Initiative
3+
*
4+
* This Source Code Form is subject to the terms of the Mozilla Public
5+
* License, v. 2.0. If a copy of the MPL was not distributed with this
6+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
7+
*
8+
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
9+
*/
10+
package com.mifos.core.domain.useCases
11+
12+
import com.mifos.core.common.utils.DataState
13+
import com.mifos.core.common.utils.asDataStateFlow
14+
import com.mifos.core.data.repository.NoteRepository
15+
import com.mifos.core.model.objects.payloads.NotesPayload
16+
import com.mifos.core.network.GenericResponse
17+
import kotlinx.coroutines.flow.Flow
18+
import kotlinx.coroutines.flow.flow
19+
20+
class UpdateNoteUseCase(
21+
val repository: NoteRepository,
22+
) {
23+
operator fun invoke(
24+
resourceType: String,
25+
resourceId: Long,
26+
noteId: Long,
27+
notesPayload: NotesPayload,
28+
): Flow<DataState<GenericResponse>> = flow {
29+
emit(repository.updateNote(resourceType, resourceId, noteId, notesPayload))
30+
}.asDataStateFlow()
31+
}

core/model/src/commonMain/kotlin/com/mifos/core/model/objects/notes/Note.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ data class Note(
3434

3535
val createdByUsername: String? = null,
3636

37-
val createdOn: Long? = null,
37+
val createdOn: String? = null,
3838

3939
val id: Long? = null,
4040

@@ -44,6 +44,6 @@ data class Note(
4444

4545
val updatedByUsername: String? = null,
4646

47-
val updatedOn: Long? = null,
47+
val updatedOn: String? = null,
4848

4949
)

core/network/src/commonMain/kotlin/com/mifos/core/network/GenericResponse.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
*/
1010
package com.mifos.core.network
1111

12-
/**
13-
* Created by ishankhanna on 24/06/14.
14-
*/
15-
class GenericResponse {
16-
var responseFields = HashMap<String, Any>()
12+
import kotlinx.serialization.Serializable
13+
import kotlinx.serialization.json.JsonElement
14+
15+
@Serializable
16+
data class GenericResponse(
17+
val responseFields: Map<String, JsonElement> = emptyMap(),
18+
) {
1719
override fun toString(): String {
18-
return "GenericResponse{" +
19-
"responseFields=" + responseFields +
20-
'}'
20+
return "GenericResponse{responseFields=$responseFields}"
2121
}
2222
}

feature/note/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ kotlin {
2525
implementation(compose.ui)
2626
implementation(projects.core.common)
2727
implementation(projects.core.model)
28+
implementation(projects.core.domain)
2829
implementation(libs.kotlinx.serialization.json)
2930
}
3031
}

feature/note/src/commonMain/composeResources/values/res.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,17 @@
2323
<string name="feature_note_item">Item</string>
2424
<string name="feature_note_Unexpected_error">"Unexpected error"</string>
2525
<string name="feature_note_delete_note_confirmation">Once deleted, this note cannot be recovered. Do you want to continue?</string>
26+
27+
<string name="feature_note_write_note_label">Write a Note</string>
28+
<string name="feature_note_edit_note_label">Edit a Note</string>
29+
<string name="feature_note_add_note">Add Note</string>
30+
<string name="feature_note_update_note">Update Note</string>
31+
<string name="feature_note_button_add">Add</string>
32+
<string name="feature_note_button_update">Update</string>
33+
<string name="feature_note_button_back">Back</string>
34+
<string name="feature_note_edit_success">Note Updated Successfully</string>
35+
<string name="feature_note_add_success">Note Added Successfully</string>
36+
<string name="feature_note_button_confirm">Confirm</string>
37+
<string name="feature_note_dialog_warning">Warning</string>
38+
<string name="feature_note_dialog_warning_message">Discard changes? Unsaved data will be lost.</string>
2639
</resources>

0 commit comments

Comments
 (0)