From 278da28c33a1130cc3fbda64b91a31d0ac11e6fd Mon Sep 17 00:00:00 2001 From: Sk Niyaj Ali Date: Mon, 30 Sep 2024 13:42:32 +0530 Subject: [PATCH] Feat: [:core:network] - Migrated to KMP (#1772) * Feat: [:core:network] - Migrated to KMP * Feat: [:core:data] - Migrated to KMP Library --- .../kotlin/KotlinInjectConventionPlugin.kt | 2 - .../kotlin/org/mifospay/core/common/Result.kt | 16 + .../org/mifospay/core/data/base/TaskLooper.kt | 62 ---- .../core/data/base/ThreadPoolQueue.kt | 24 -- .../org/mifospay/core/data/base/UseCase.kt | 45 --- .../mifospay/core/data/base/UseCaseFactory.kt | 33 -- .../mifospay/core/data/base/UseCaseHandler.kt | 65 ---- .../core/data/base/UseCaseScheduler.kt | 28 -- .../data/base/UseCaseThreadPoolScheduler.kt | 59 ---- .../org/mifospay/core/data/di/DataModule.kt | 214 ------------ .../usecase/account/BlockUnblockCommand.kt | 46 --- .../account/DownloadTransactionReceipt.kt | 45 --- .../domain/usecase/account/FetchAccount.kt | 66 ---- .../account/FetchAccountTransaction.kt | 62 ---- .../account/FetchAccountTransactions.kt | 53 --- .../usecase/account/FetchAccountTransfer.kt | 40 --- .../domain/usecase/account/FetchAccounts.kt | 55 --- .../domain/usecase/account/FetchMerchants.kt | 53 --- .../domain/usecase/account/TransferFunds.kt | 275 --------------- .../domain/usecase/client/CreateClient.kt | 54 --- .../domain/usecase/client/FetchClientData.kt | 75 ---- .../usecase/client/FetchClientDetails.kt | 44 --- .../domain/usecase/client/FetchClientImage.kt | 45 --- .../domain/usecase/client/SearchClient.kt | 55 --- .../domain/usecase/client/UpdateClient.kt | 55 --- .../usecase/history/TransactionsHistory.kt | 44 --- .../domain/usecase/invoice/FetchInvoice.kt | 63 ---- .../domain/usecase/invoice/FetchInvoices.kt | 48 --- .../usecase/kyc/FetchKYCLevel1Details.kt | 47 --- .../usecase/kyc/UpdateKYCLevel1Details.kt | 51 --- .../data/domain/usecase/kyc/UploadKYCDocs.kt | 57 ---- .../usecase/kyc/UploadKYCLevel1Details.kt | 50 --- .../notification/FetchNotifications.kt | 46 --- .../data/domain/usecase/savedcards/AddCard.kt | 43 --- .../domain/usecase/savedcards/DeleteCard.kt | 43 --- .../domain/usecase/savedcards/EditCard.kt | 44 --- .../usecase/savedcards/FetchSavedCards.kt | 48 --- .../CreateStandingTransaction.kt | 206 ----------- .../DeleteStandingInstruction.kt | 47 --- .../FetchStandingInstruction.kt | 46 --- .../GetAllStandingInstructions.kt | 51 --- .../UpdateStandingInstruction.kt | 89 ----- .../usecase/twofactor/FetchDeliveryMethods.kt | 45 --- .../domain/usecase/twofactor/RequestOTP.kt | 42 --- .../domain/usecase/twofactor/ValidateOTP.kt | 43 --- .../domain/usecase/user/AuthenticateUser.kt | 45 --- .../data/domain/usecase/user/CreateUser.kt | 51 --- .../data/domain/usecase/user/DeleteUser.kt | 42 --- .../domain/usecase/user/FetchUserDetails.kt | 42 --- .../data/domain/usecase/user/FetchUsers.kt | 51 --- .../data/domain/usecase/user/RegisterUser.kt | 45 --- .../data/domain/usecase/user/UpdateUser.kt | 52 --- .../data/domain/usecase/user/VerifyUser.kt | 44 --- .../fineract/entity/mapper/AccountMapper.kt | 35 -- .../entity/mapper/ClientDetailsMapper.kt | 34 -- .../fineract/entity/mapper/CurrencyMapper.kt | 23 -- .../fineract/entity/mapper/FetchAccount.kt | 62 ---- .../entity/mapper/SearchedEntitiesMapper.kt | 33 -- .../entity/mapper/TransactionMapper.kt | 60 ---- .../fineract/repository/FineractRepository.kt | 320 ------------------ .../auth/AuthenticationUserRepository.kt | 35 -- .../data/repository/local/LocalRepository.kt | 33 -- .../local/MifosLocalAssetRepository.kt | 47 --- .../di/AndroidPlatformDependentDataModule.kt | 32 ++ .../core/data/di/AndroidPlatformModule.kt | 41 +++ .../util/ConnectivityManagerNetworkMonitor.kt | 20 +- .../core/data/util/ErrorJsonMessageHelper.kt | 0 .../data/util/TimeZoneBroadcastMonitor.kt} | 12 +- .../assets/banks.json | 0 .../assets/cities.json | 0 .../assets/countriesToCities.json | 0 .../data/di/PlatformDependentDataModule.kt} | 12 +- .../mifospay/core/data/di/RepositoryModule.kt | 77 +++++ .../core/data/mapper/AccountMapper.kt | 26 ++ .../core/data/mapper/ClientDetailsMapper.kt | 34 ++ .../core/data/mapper/CurrencyMapper.kt | 21 ++ .../data/mapper/SearchedEntitiesMapper.kt | 23 ++ .../core/data/mapper/TransactionMapper.kt | 36 ++ .../data/repository/AccountRepository.kt} | 14 +- .../repository/AuthenticationRepository.kt | 19 ++ .../data/repository/BeneficiaryRepository.kt | 33 ++ .../core/data/repository/ClientRepository.kt | 36 ++ .../data/repository/DocumentRepository.kt | 40 +++ .../core/data/repository/InvoiceRepository.kt | 31 ++ .../data/repository/KycLevelRepository.kt | 29 ++ .../repository/NotificationRepository.kt} | 12 +- .../data/repository/RegistrationRepository.kt | 20 ++ .../data/repository/RunReportRepository.kt | 21 ++ .../data/repository/SavedCardRepository.kt | 25 ++ .../repository/SavingsAccountRepository.kt | 38 +++ .../core/data/repository/SearchRepository.kt | 22 ++ .../data/repository/SelfServiceRepository.kt | 52 +++ .../StandingInstructionRepository.kt | 37 ++ .../ThirdPartyTransferRepository.kt | 22 ++ .../repository/TwoFactorAuthRepository.kt | 23 ++ .../core/data/repository/UserRepository.kt | 29 ++ .../repositoryImp/AccountRepositoryImpl.kt | 32 ++ .../AuthenticationRepositoryImpl.kt | 29 ++ .../BeneficiaryRepositoryImpl.kt | 60 ++++ .../repositoryImp/ClientRepositoryImpl.kt | 78 +++++ .../repositoryImp/DocumentRepositoryImpl.kt | 77 +++++ .../repositoryImp/InvoiceRepositoryImpl.kt | 57 ++++ .../repositoryImp/KycLevelRepositoryImpl.kt | 49 +++ .../NotificationRepositoryImpl.kt | 32 ++ .../RegistrationRepositoryImpl.kt | 45 +++ .../repositoryImp/RunReportRepositoryImpl.kt | 37 ++ .../repositoryImp/SavedCardRepositoryImpl.kt | 47 +++ .../SavingsAccountRepositoryImpl.kt | 83 +++++ .../repositoryImp/SearchRepositoryImpl.kt | 34 ++ .../SelfServiceRepositoryImpl.kt | 95 ++++++ .../StandingInstructionRepositoryImpl.kt | 69 ++++ .../ThirdPartyTransferRepositoryImpl.kt | 38 +++ .../TwoFactorAuthRepositoryImpl.kt | 39 +++ .../data/repositoryImp/UserRepositoryImpl.kt | 47 +++ .../org/mifospay/core/data/util/Constants.kt | 8 +- .../mifospay/core/data/util/NetworkMonitor.kt | 0 .../core/data/util/TimeZoneMonitor.kt} | 20 +- .../data/JvmPlatformDependentDataModule.kt | 33 ++ .../data/NativePlatformDependentDataModule.kt | 33 ++ .../core/datastore/proto/ClientPreferences.kt | 11 +- .../core/datastore/proto/RolePreferences.kt | 13 +- .../datastore/proto/UserInfoPreferences.kt | 13 +- .../core/datastore/proto/UserPreferences.kt | 9 + .../core/model/domain/client/Client.kt | 17 +- .../entity/accounts/savings/PaymentType.kt | 1 + ...ns.kt => SavingsWithAssociationsEntity.kt} | 31 +- .../accounts/savings/TransactionType.kt | 4 +- ...{Transactions.kt => TransactionsEntity.kt} | 28 +- .../client/{Client.kt => ClientEntity.kt} | 27 +- .../StandingInstruction.kt | 6 +- core/network/build.gradle.kts | 4 + .../mifospay/core/network/ApiInterceptor.kt | 39 --- .../core/network/JvmLocalAssetManager.kt | 37 -- .../mifospay/core/network/KtorInterceptor.kt | 48 --- .../core/network/MifosWalletOkHttpClient.kt | 84 ----- .../mifospay/core/network/di/NetworkModule.kt | 233 ------------- .../core/network/services/ClientService.kt | 65 ---- .../services/KtorAuthenticationService.kt | 32 -- .../services/KtorSavingsAccountService.kt | 81 ----- .../services/ThirdPartyTransferService.kt | 30 -- .../core/network/services/UserService.kt | 47 --- .../assets/banks.json | 0 .../assets/cities.json | 0 .../assets/countries.json | 0 .../assets/countriesToCities.json | 0 .../assets/states.json | 0 .../org/mifospay/core/network/ApiEndPoints.kt | 0 .../org/mifospay/core/network/BaseURL.kt | 25 +- .../core/network/FineractApiManager.kt | 54 +-- .../mifospay/core/network/KtorfitClient.kt | 187 ++++++++++ .../core/network/SelfServiceApiManager.kt | 23 +- .../mifospay/core/network/di/LocalModule.kt | 6 +- .../mifospay/core/network/di/NetworkModule.kt | 50 +++ .../org/mifospay/core/network/di/Qualifier.kt | 4 +- .../localAssets/JvmLocalAssetManager.kt | 22 ++ .../localAssets/LocalAssetDataSource.kt | 0 .../network/localAssets/LocalAssetManager.kt | 4 +- .../localAssets/MifosLocalAssetDataSource.kt | 27 +- .../core/network/model/CommonResponse.kt} | 9 +- .../core/network/model}/GenericResponse.kt | 2 +- .../services/AccountTransfersService.kt | 10 +- .../network/services/AuthenticationService.kt | 12 +- .../network/services/BeneficiaryService.kt | 39 +-- .../core/network/services/ClientService.kt | 60 ++++ .../core/network/services/DocumentService.kt | 43 ++- .../core/network/services/InvoiceService.kt | 58 ++-- .../core/network/services/KYCLevel1Service.kt | 29 +- .../network/services/NotificationService.kt | 13 +- .../network/services/RegistrationService.kt | 14 +- .../core/network/services/RunReportService.kt | 16 +- .../core/network/services/SavedCardService.kt | 29 +- .../services/SavingsAccountsService.kt | 60 ++++ .../core/network/services/SearchService.kt | 12 +- .../services/StandingInstructionService.kt | 34 +- .../services/ThirdPartyTransferService.kt | 27 ++ .../network/services/TwoFactorAuthService.kt | 21 +- .../core/network/services/UserService.kt | 45 +++ gradle/libs.versions.toml | 6 +- settings.gradle.kts | 2 +- 179 files changed, 2570 insertions(+), 4890 deletions(-) create mode 100644 core/common/src/commonMain/kotlin/org/mifospay/core/common/Result.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/base/TaskLooper.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/base/ThreadPoolQueue.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/base/UseCase.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/base/UseCaseFactory.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/base/UseCaseHandler.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/base/UseCaseScheduler.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/base/UseCaseThreadPoolScheduler.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/di/DataModule.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/account/BlockUnblockCommand.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/account/DownloadTransactionReceipt.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/account/FetchAccount.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/account/FetchAccountTransaction.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/account/FetchAccountTransactions.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/account/FetchAccountTransfer.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/account/FetchAccounts.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/account/FetchMerchants.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/account/TransferFunds.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/client/CreateClient.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/client/FetchClientData.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/client/FetchClientDetails.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/client/FetchClientImage.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/client/SearchClient.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/client/UpdateClient.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/history/TransactionsHistory.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/invoice/FetchInvoice.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/invoice/FetchInvoices.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/kyc/FetchKYCLevel1Details.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/kyc/UpdateKYCLevel1Details.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/kyc/UploadKYCDocs.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/kyc/UploadKYCLevel1Details.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/notification/FetchNotifications.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/savedcards/AddCard.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/savedcards/DeleteCard.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/savedcards/EditCard.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/savedcards/FetchSavedCards.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/standinginstruction/CreateStandingTransaction.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/standinginstruction/DeleteStandingInstruction.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/standinginstruction/FetchStandingInstruction.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/standinginstruction/GetAllStandingInstructions.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/standinginstruction/UpdateStandingInstruction.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/twofactor/FetchDeliveryMethods.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/twofactor/RequestOTP.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/twofactor/ValidateOTP.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/user/AuthenticateUser.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/user/CreateUser.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/user/DeleteUser.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/user/FetchUserDetails.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/user/FetchUsers.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/user/RegisterUser.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/user/UpdateUser.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/user/VerifyUser.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/fineract/entity/mapper/AccountMapper.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/fineract/entity/mapper/ClientDetailsMapper.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/fineract/entity/mapper/CurrencyMapper.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/fineract/entity/mapper/FetchAccount.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/fineract/entity/mapper/SearchedEntitiesMapper.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/fineract/entity/mapper/TransactionMapper.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/fineract/repository/FineractRepository.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/repository/auth/AuthenticationUserRepository.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/repository/local/LocalRepository.kt delete mode 100644 core/data/src/androidMain/java/org/mifospay/core/data/repository/local/MifosLocalAssetRepository.kt create mode 100644 core/data/src/androidMain/kotlin/org/mifospay/core/data/di/AndroidPlatformDependentDataModule.kt create mode 100644 core/data/src/androidMain/kotlin/org/mifospay/core/data/di/AndroidPlatformModule.kt rename core/data/src/androidMain/{java => kotlin}/org/mifospay/core/data/util/ConnectivityManagerNetworkMonitor.kt (84%) rename core/data/src/androidMain/{java => kotlin}/org/mifospay/core/data/util/ErrorJsonMessageHelper.kt (100%) rename core/data/src/androidMain/{java/org/mifospay/core/data/util/TimeZoneMonitor.kt => kotlin/org/mifospay/core/data/util/TimeZoneBroadcastMonitor.kt} (91%) rename core/data/src/{androidMain => commonMain}/assets/banks.json (100%) rename core/data/src/{androidMain => commonMain}/assets/cities.json (100%) rename core/data/src/{androidMain => commonMain}/assets/countriesToCities.json (100%) rename core/data/src/{androidMain/java/org/mifospay/core/data/di/LocalDataModule.kt => commonMain/kotlin/org/mifospay/core/data/di/PlatformDependentDataModule.kt} (58%) create mode 100644 core/data/src/commonMain/kotlin/org/mifospay/core/data/di/RepositoryModule.kt create mode 100644 core/data/src/commonMain/kotlin/org/mifospay/core/data/mapper/AccountMapper.kt create mode 100644 core/data/src/commonMain/kotlin/org/mifospay/core/data/mapper/ClientDetailsMapper.kt create mode 100644 core/data/src/commonMain/kotlin/org/mifospay/core/data/mapper/CurrencyMapper.kt create mode 100644 core/data/src/commonMain/kotlin/org/mifospay/core/data/mapper/SearchedEntitiesMapper.kt create mode 100644 core/data/src/commonMain/kotlin/org/mifospay/core/data/mapper/TransactionMapper.kt rename core/data/src/{androidMain/java/org/mifospay/core/data/repository/auth/UserDataRepository.kt => commonMain/kotlin/org/mifospay/core/data/repository/AccountRepository.kt} (57%) create mode 100644 core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/AuthenticationRepository.kt create mode 100644 core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/BeneficiaryRepository.kt create mode 100644 core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/ClientRepository.kt create mode 100644 core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/DocumentRepository.kt create mode 100644 core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/InvoiceRepository.kt create mode 100644 core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/KycLevelRepository.kt rename core/data/src/{androidMain/java/org/mifospay/core/data/domain/usecase/history/HistoryContract.kt => commonMain/kotlin/org/mifospay/core/data/repository/NotificationRepository.kt} (51%) create mode 100644 core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/RegistrationRepository.kt create mode 100644 core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/RunReportRepository.kt create mode 100644 core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/SavedCardRepository.kt create mode 100644 core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/SavingsAccountRepository.kt create mode 100644 core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/SearchRepository.kt create mode 100644 core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/SelfServiceRepository.kt create mode 100644 core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/StandingInstructionRepository.kt create mode 100644 core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/ThirdPartyTransferRepository.kt create mode 100644 core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/TwoFactorAuthRepository.kt create mode 100644 core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/UserRepository.kt create mode 100644 core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/AccountRepositoryImpl.kt create mode 100644 core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/AuthenticationRepositoryImpl.kt create mode 100644 core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/BeneficiaryRepositoryImpl.kt create mode 100644 core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/ClientRepositoryImpl.kt create mode 100644 core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/DocumentRepositoryImpl.kt create mode 100644 core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/InvoiceRepositoryImpl.kt create mode 100644 core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/KycLevelRepositoryImpl.kt create mode 100644 core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/NotificationRepositoryImpl.kt create mode 100644 core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/RegistrationRepositoryImpl.kt create mode 100644 core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/RunReportRepositoryImpl.kt create mode 100644 core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/SavedCardRepositoryImpl.kt create mode 100644 core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/SavingsAccountRepositoryImpl.kt create mode 100644 core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/SearchRepositoryImpl.kt create mode 100644 core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/SelfServiceRepositoryImpl.kt create mode 100644 core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/StandingInstructionRepositoryImpl.kt create mode 100644 core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/ThirdPartyTransferRepositoryImpl.kt create mode 100644 core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/TwoFactorAuthRepositoryImpl.kt create mode 100644 core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/UserRepositoryImpl.kt rename core/data/src/{androidMain/java => commonMain/kotlin}/org/mifospay/core/data/util/Constants.kt (92%) rename core/data/src/{androidMain/java => commonMain/kotlin}/org/mifospay/core/data/util/NetworkMonitor.kt (100%) rename core/data/src/{androidMain/java/org/mifospay/core/data/repository/local/LocalAssetRepository.kt => commonMain/kotlin/org/mifospay/core/data/util/TimeZoneMonitor.kt} (50%) create mode 100644 core/data/src/jvmMain/kotlin/org/mifospay/core/data/JvmPlatformDependentDataModule.kt create mode 100644 core/data/src/nativeMain/kotlin/org/mifospay/core/data/NativePlatformDependentDataModule.kt rename core/model/src/commonMain/kotlin/org/mifospay/core/model/entity/accounts/savings/{SavingsWithAssociations.kt => SavingsWithAssociationsEntity.kt} (64%) rename core/model/src/commonMain/kotlin/org/mifospay/core/model/entity/accounts/savings/{Transactions.kt => TransactionsEntity.kt} (64%) rename core/model/src/commonMain/kotlin/org/mifospay/core/model/entity/client/{Client.kt => ClientEntity.kt} (68%) delete mode 100644 core/network/src/androidMain/kotlin/org/mifospay/core/network/ApiInterceptor.kt delete mode 100644 core/network/src/androidMain/kotlin/org/mifospay/core/network/JvmLocalAssetManager.kt delete mode 100644 core/network/src/androidMain/kotlin/org/mifospay/core/network/KtorInterceptor.kt delete mode 100644 core/network/src/androidMain/kotlin/org/mifospay/core/network/MifosWalletOkHttpClient.kt delete mode 100644 core/network/src/androidMain/kotlin/org/mifospay/core/network/di/NetworkModule.kt delete mode 100644 core/network/src/androidMain/kotlin/org/mifospay/core/network/services/ClientService.kt delete mode 100644 core/network/src/androidMain/kotlin/org/mifospay/core/network/services/KtorAuthenticationService.kt delete mode 100644 core/network/src/androidMain/kotlin/org/mifospay/core/network/services/KtorSavingsAccountService.kt delete mode 100644 core/network/src/androidMain/kotlin/org/mifospay/core/network/services/ThirdPartyTransferService.kt delete mode 100644 core/network/src/androidMain/kotlin/org/mifospay/core/network/services/UserService.kt rename core/network/src/{androidMain => commonMain}/assets/banks.json (100%) rename core/network/src/{androidMain => commonMain}/assets/cities.json (100%) rename core/network/src/{androidMain => commonMain}/assets/countries.json (100%) rename core/network/src/{androidMain => commonMain}/assets/countriesToCities.json (100%) rename core/network/src/{androidMain => commonMain}/assets/states.json (100%) rename core/network/src/{androidMain => commonMain}/kotlin/org/mifospay/core/network/ApiEndPoints.kt (100%) rename core/network/src/{androidMain => commonMain}/kotlin/org/mifospay/core/network/BaseURL.kt (52%) rename core/network/src/{androidMain => commonMain}/kotlin/org/mifospay/core/network/FineractApiManager.kt (54%) create mode 100644 core/network/src/commonMain/kotlin/org/mifospay/core/network/KtorfitClient.kt rename core/network/src/{androidMain => commonMain}/kotlin/org/mifospay/core/network/SelfServiceApiManager.kt (56%) rename core/network/src/{androidMain => commonMain}/kotlin/org/mifospay/core/network/di/LocalModule.kt (77%) create mode 100644 core/network/src/commonMain/kotlin/org/mifospay/core/network/di/NetworkModule.kt rename core/network/src/{androidMain => commonMain}/kotlin/org/mifospay/core/network/di/Qualifier.kt (93%) create mode 100644 core/network/src/commonMain/kotlin/org/mifospay/core/network/localAssets/JvmLocalAssetManager.kt rename core/network/src/{androidMain => commonMain}/kotlin/org/mifospay/core/network/localAssets/LocalAssetDataSource.kt (100%) rename core/network/src/{androidMain => commonMain}/kotlin/org/mifospay/core/network/localAssets/LocalAssetManager.kt (85%) rename core/network/src/{androidMain => commonMain}/kotlin/org/mifospay/core/network/localAssets/MifosLocalAssetDataSource.kt (61%) rename core/network/src/{androidMain/kotlin/org/mifospay/core/network/services/SavingsAccountsService.kt => commonMain/kotlin/org/mifospay/core/network/model/CommonResponse.kt} (68%) rename core/network/src/{androidMain/kotlin/org/mifospay/core/network => commonMain/kotlin/org/mifospay/core/network/model}/GenericResponse.kt (91%) rename core/network/src/{androidMain => commonMain}/kotlin/org/mifospay/core/network/services/AccountTransfersService.kt (74%) rename core/network/src/{androidMain => commonMain}/kotlin/org/mifospay/core/network/services/AuthenticationService.kt (69%) rename core/network/src/{androidMain => commonMain}/kotlin/org/mifospay/core/network/services/BeneficiaryService.kt (50%) create mode 100644 core/network/src/commonMain/kotlin/org/mifospay/core/network/services/ClientService.kt rename core/network/src/{androidMain => commonMain}/kotlin/org/mifospay/core/network/services/DocumentService.kt (82%) rename core/network/src/{androidMain => commonMain}/kotlin/org/mifospay/core/network/services/InvoiceService.kt (52%) rename core/network/src/{androidMain => commonMain}/kotlin/org/mifospay/core/network/services/KYCLevel1Service.kt (64%) rename core/network/src/{androidMain => commonMain}/kotlin/org/mifospay/core/network/services/NotificationService.kt (64%) rename core/network/src/{androidMain => commonMain}/kotlin/org/mifospay/core/network/services/RegistrationService.kt (57%) rename core/network/src/{androidMain => commonMain}/kotlin/org/mifospay/core/network/services/RunReportService.kt (67%) rename core/network/src/{androidMain => commonMain}/kotlin/org/mifospay/core/network/services/SavedCardService.kt (64%) create mode 100644 core/network/src/commonMain/kotlin/org/mifospay/core/network/services/SavingsAccountsService.kt rename core/network/src/{androidMain => commonMain}/kotlin/org/mifospay/core/network/services/SearchService.kt (71%) rename core/network/src/{androidMain => commonMain}/kotlin/org/mifospay/core/network/services/StandingInstructionService.kt (72%) create mode 100644 core/network/src/commonMain/kotlin/org/mifospay/core/network/services/ThirdPartyTransferService.kt rename core/network/src/{androidMain => commonMain}/kotlin/org/mifospay/core/network/services/TwoFactorAuthService.kt (59%) create mode 100644 core/network/src/commonMain/kotlin/org/mifospay/core/network/services/UserService.kt diff --git a/build-logic/convention/src/main/kotlin/KotlinInjectConventionPlugin.kt b/build-logic/convention/src/main/kotlin/KotlinInjectConventionPlugin.kt index 977f01b2d..cb89515b6 100644 --- a/build-logic/convention/src/main/kotlin/KotlinInjectConventionPlugin.kt +++ b/build-logic/convention/src/main/kotlin/KotlinInjectConventionPlugin.kt @@ -21,8 +21,6 @@ class KotlinInjectConventionPlugin: Plugin { // add("kspWasmJs", libs.findLibrary("kotlin.inject.compiler.ksp").get()) add("kspAndroid", libs.findLibrary("kotlin.inject.compiler.ksp").get()) add("kspJvm", libs.findLibrary("kotlin.inject.compiler.ksp").get()) - add("kspMacosX64", libs.findLibrary("kotlin.inject.compiler.ksp").get()) - add("kspMacosArm64", libs.findLibrary("kotlin.inject.compiler.ksp").get()) } } } diff --git a/core/common/src/commonMain/kotlin/org/mifospay/core/common/Result.kt b/core/common/src/commonMain/kotlin/org/mifospay/core/common/Result.kt new file mode 100644 index 000000000..19a72890e --- /dev/null +++ b/core/common/src/commonMain/kotlin/org/mifospay/core/common/Result.kt @@ -0,0 +1,16 @@ +package org.mifospay.core.common + +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.catch +import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.onStart + +sealed interface Result { + data class Success(val data: T) : Result + data class Error(val exception: Throwable) : Result + data object Loading : Result +} + +fun Flow.asResult(): Flow> = map> { Result.Success(it) } + .onStart { emit(Result.Loading) } + .catch { emit(Result.Error(it)) } \ No newline at end of file diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/base/TaskLooper.kt b/core/data/src/androidMain/java/org/mifospay/core/data/base/TaskLooper.kt deleted file mode 100644 index 6fa7abbf7..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/base/TaskLooper.kt +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.base - -import org.mifospay.core.data.base.UseCase.UseCaseCallback - -class TaskLooper( - private val mUseCaseHandler: UseCaseHandler, -) { - var isFailed = false - private var tasksPending: Long = 0 - private var listener: Listener? = null - - fun addTask( - useCase: UseCase, - values: T, - taskData: TaskData, - ) { - tasksPending++ - mUseCaseHandler.execute( - useCase, - values, - object : UseCaseCallback { - override fun onSuccess(response: R) { - if (isFailed) return - listener!!.onTaskSuccess(taskData, response) - tasksPending-- - if (isCompleted) { - listener!!.onComplete() - } - } - - override fun onError(message: String) { - isFailed = true - listener!!.onFailure(message) - } - }, - ) - } - - private val isCompleted: Boolean - get() = tasksPending == 0L - - fun listen(listener: Listener?) { - this.listener = listener - } - - interface Listener { - fun onTaskSuccess(taskData: TaskData, response: R) - fun onComplete() - fun onFailure(message: String?) - } - - class TaskData(var taskName: String, var taskId: Int) -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/base/ThreadPoolQueue.kt b/core/data/src/androidMain/java/org/mifospay/core/data/base/ThreadPoolQueue.kt deleted file mode 100644 index 083de6576..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/base/ThreadPoolQueue.kt +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.base - -import java.util.concurrent.ArrayBlockingQueue - -class ThreadPoolQueue(capacity: Int) : ArrayBlockingQueue(capacity) { - - override fun offer(e: Runnable?): Boolean { - try { - put(e) - } catch (e1: InterruptedException) { - return false - } - return true - } -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/base/UseCase.kt b/core/data/src/androidMain/java/org/mifospay/core/data/base/UseCase.kt deleted file mode 100644 index 2784fd0a8..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/base/UseCase.kt +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.base - -/** - * Use cases are the entry points to the domain layer. - * - * @param the request type - * @param

the response type -

*/ -abstract class UseCase { - lateinit var walletRequestValues: Q - lateinit var useCaseCallback: UseCaseCallback

- - fun setRequestValues(requestValues: Q) { - this.walletRequestValues = requestValues - } - - fun run() { - executeUseCase(walletRequestValues) - } - - protected abstract fun executeUseCase(requestValues: Q) - - /** - * Data passed to a request. - */ - interface RequestValues - - /** - * Data received from a request. - */ - interface ResponseValue - interface UseCaseCallback { - fun onSuccess(response: R) - fun onError(message: String) - } -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/base/UseCaseFactory.kt b/core/data/src/androidMain/java/org/mifospay/core/data/base/UseCaseFactory.kt deleted file mode 100644 index d7f6b510b..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/base/UseCaseFactory.kt +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.base - -import org.mifospay.core.data.domain.usecase.account.FetchAccountTransfer -import org.mifospay.core.data.domain.usecase.client.FetchClientDetails -import org.mifospay.core.data.fineract.repository.FineractRepository -import org.mifospay.core.data.util.Constants - -class UseCaseFactory( - private val mFineractRepository: FineractRepository, -) { - fun getUseCase(useCase: String): UseCase<*, *>? { - return when (useCase) { - Constants.FETCH_ACCOUNT_TRANSFER_USECASE -> { - FetchAccountTransfer(mFineractRepository) - } - - Constants.FETCH_CLIENT_DETAILS_USE_CASE -> { - FetchClientDetails(mFineractRepository) - } - - else -> null - } - } -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/base/UseCaseHandler.kt b/core/data/src/androidMain/java/org/mifospay/core/data/base/UseCaseHandler.kt deleted file mode 100644 index 9fe654b62..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/base/UseCaseHandler.kt +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.base - -import org.mifospay.core.data.base.UseCase.UseCaseCallback - -/** - * Runs [UseCase]s using a [UseCaseScheduler]. - */ -class UseCaseHandler(private val mUseCaseScheduler: UseCaseScheduler) { - fun execute( - useCase: UseCase, - values: T?, - callback: UseCaseCallback, - ) { - values?.let { useCase.walletRequestValues = values } - useCase.useCaseCallback = UiCallbackWrapper(callback, this) - mUseCaseScheduler.execute { useCase.run() } - } - - fun notifyResponse( - response: V, - useCaseCallback: UseCaseCallback?, - ) { - mUseCaseScheduler.notifyResponse(response, useCaseCallback) - } - - private fun notifyError( - message: String?, - useCaseCallback: UseCaseCallback?, - ) { - mUseCaseScheduler.onError(message, useCaseCallback) - } - - private class UiCallbackWrapper( - private val mCallback: UseCaseCallback?, - private val mUseCaseHandler: UseCaseHandler, - ) : UseCaseCallback { - override fun onSuccess(response: V) { - mUseCaseHandler.notifyResponse(response, mCallback) - } - - override fun onError(message: String) { - mUseCaseHandler.notifyError(message, mCallback) - } - } - - companion object { - var instance: UseCaseHandler? = null - get() { - if (field == null) { - field = UseCaseHandler(UseCaseThreadPoolScheduler()) - } - return field - } - private set - } -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/base/UseCaseScheduler.kt b/core/data/src/androidMain/java/org/mifospay/core/data/base/UseCaseScheduler.kt deleted file mode 100644 index bff30b7e4..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/base/UseCaseScheduler.kt +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.base - -import org.mifospay.core.data.base.UseCase.UseCaseCallback - -/** - * Interface for schedulers, see [UseCaseThreadPoolScheduler]. - */ -interface UseCaseScheduler { - fun execute(runnable: Runnable?) - fun notifyResponse( - response: V, - useCaseCallback: UseCaseCallback?, - ) - - fun onError( - message: String?, - useCaseCallback: UseCaseCallback?, - ) -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/base/UseCaseThreadPoolScheduler.kt b/core/data/src/androidMain/java/org/mifospay/core/data/base/UseCaseThreadPoolScheduler.kt deleted file mode 100644 index 2066f1faa..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/base/UseCaseThreadPoolScheduler.kt +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.base - -import android.os.Handler -import android.os.Looper -import org.mifospay.core.data.base.UseCase.UseCaseCallback -import java.util.concurrent.ThreadPoolExecutor -import java.util.concurrent.TimeUnit - -/** - * Executes asynchronous tasks using a [ThreadPoolExecutor]. - * - * - * See also [ThreadPoolExecutor] for a list of factory methods to create common - * [java.util.concurrent.ExecutorService]s for different scenarios. - */ -class UseCaseThreadPoolScheduler : UseCaseScheduler { - - private val mHandler = Handler(Looper.getMainLooper()) - private var mThreadPoolExecutor: ThreadPoolExecutor = ThreadPoolExecutor( - POOL_SIZE, - MAX_POOL_SIZE, - TIMEOUT.toLong(), - TimeUnit.SECONDS, - ThreadPoolQueue(MAX_POOL_SIZE), - ) - - override fun execute(runnable: Runnable?) { - mThreadPoolExecutor.execute(runnable) - } - - override fun notifyResponse( - response: V, - useCaseCallback: UseCaseCallback?, - ) { - mHandler.post { useCaseCallback!!.onSuccess(response) } - } - - override fun onError( - message: String?, - useCaseCallback: UseCaseCallback?, - ) { - mHandler.post { useCaseCallback!!.onError(message!!) } - } - - companion object { - const val POOL_SIZE = 2 - const val MAX_POOL_SIZE = 40 - const val TIMEOUT = 60 - } -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/di/DataModule.kt b/core/data/src/androidMain/java/org/mifospay/core/data/di/DataModule.kt deleted file mode 100644 index e498908c9..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/di/DataModule.kt +++ /dev/null @@ -1,214 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.di - -import org.koin.android.ext.koin.androidContext -import org.koin.core.qualifier.named -import org.koin.dsl.module -import org.mifos.core.network.localAssets.LocalAssetDataSource -import org.mifospay.core.data.base.TaskLooper -import org.mifospay.core.data.base.UseCaseFactory -import org.mifospay.core.data.base.UseCaseHandler -import org.mifospay.core.data.base.UseCaseScheduler -import org.mifospay.core.data.base.UseCaseThreadPoolScheduler -import org.mifospay.core.data.domain.usecase.account.BlockUnblockCommand -import org.mifospay.core.data.domain.usecase.account.DownloadTransactionReceipt -import org.mifospay.core.data.domain.usecase.account.FetchAccount -import org.mifospay.core.data.domain.usecase.account.FetchAccountTransaction -import org.mifospay.core.data.domain.usecase.account.FetchAccountTransactions -import org.mifospay.core.data.domain.usecase.account.FetchAccountTransfer -import org.mifospay.core.data.domain.usecase.account.FetchAccounts -import org.mifospay.core.data.domain.usecase.account.FetchMerchants -import org.mifospay.core.data.domain.usecase.account.TransferFunds -import org.mifospay.core.data.domain.usecase.client.CreateClient -import org.mifospay.core.data.domain.usecase.client.FetchClientData -import org.mifospay.core.data.domain.usecase.client.FetchClientDetails -import org.mifospay.core.data.domain.usecase.client.FetchClientImage -import org.mifospay.core.data.domain.usecase.client.SearchClient -import org.mifospay.core.data.domain.usecase.client.UpdateClient -import org.mifospay.core.data.domain.usecase.history.TransactionsHistory -import org.mifospay.core.data.domain.usecase.invoice.FetchInvoice -import org.mifospay.core.data.domain.usecase.invoice.FetchInvoices -import org.mifospay.core.data.domain.usecase.kyc.FetchKYCLevel1Details -import org.mifospay.core.data.domain.usecase.kyc.UpdateKYCLevel1Details -import org.mifospay.core.data.domain.usecase.kyc.UploadKYCDocs -import org.mifospay.core.data.domain.usecase.kyc.UploadKYCLevel1Details -import org.mifospay.core.data.domain.usecase.notification.FetchNotifications -import org.mifospay.core.data.domain.usecase.savedcards.AddCard -import org.mifospay.core.data.domain.usecase.savedcards.DeleteCard -import org.mifospay.core.data.domain.usecase.savedcards.EditCard -import org.mifospay.core.data.domain.usecase.savedcards.FetchSavedCards -import org.mifospay.core.data.domain.usecase.standinginstruction.CreateStandingTransaction -import org.mifospay.core.data.domain.usecase.standinginstruction.DeleteStandingInstruction -import org.mifospay.core.data.domain.usecase.standinginstruction.FetchStandingInstruction -import org.mifospay.core.data.domain.usecase.standinginstruction.GetAllStandingInstructions -import org.mifospay.core.data.domain.usecase.standinginstruction.UpdateStandingInstruction -import org.mifospay.core.data.domain.usecase.twofactor.FetchDeliveryMethods -import org.mifospay.core.data.domain.usecase.twofactor.RequestOTP -import org.mifospay.core.data.domain.usecase.twofactor.ValidateOTP -import org.mifospay.core.data.domain.usecase.user.AuthenticateUser -import org.mifospay.core.data.domain.usecase.user.CreateUser -import org.mifospay.core.data.domain.usecase.user.DeleteUser -import org.mifospay.core.data.domain.usecase.user.FetchUserDetails -import org.mifospay.core.data.domain.usecase.user.FetchUsers -import org.mifospay.core.data.domain.usecase.user.RegisterUser -import org.mifospay.core.data.domain.usecase.user.UpdateUser -import org.mifospay.core.data.domain.usecase.user.VerifyUser -import org.mifospay.core.data.fineract.entity.mapper.AccountMapper -import org.mifospay.core.data.fineract.entity.mapper.ClientDetailsMapper -import org.mifospay.core.data.fineract.entity.mapper.CurrencyMapper -import org.mifospay.core.data.fineract.entity.mapper.SearchedEntitiesMapper -import org.mifospay.core.data.fineract.entity.mapper.TransactionMapper -import org.mifospay.core.data.fineract.repository.FineractRepository -import org.mifospay.core.data.repository.auth.AuthenticationUserRepository -import org.mifospay.core.data.repository.auth.UserDataRepository -import org.mifospay.core.data.repository.local.LocalAssetRepository -import org.mifospay.core.data.repository.local.LocalRepository -import org.mifospay.core.data.repository.local.MifosLocalAssetRepository -import org.mifospay.core.data.util.ConnectivityManagerNetworkMonitor -import org.mifospay.core.data.util.NetworkMonitor -import org.mifospay.core.data.util.TimeZoneBroadcastMonitor -import org.mifospay.core.data.util.TimeZoneMonitor -import org.mifospay.core.datastore.PreferencesHelper -import org.mifospay.core.network.MifosDispatchers -import org.mifospay.core.network.di.LocalModule -import org.mifospay.core.network.localAssets.MifosLocalAssetDataSource - -val DataModule = module { - includes(LocalModule) - - single { UseCaseThreadPoolScheduler() } - single { UseCaseHandler(get()) } - single { TaskLooper(get()) } - single { UseCaseFactory(get()) } - single { FetchClientData(get(), get()) } - single { ClientDetailsMapper() } - single { SearchClient(get(), get()) } - single { UpdateClient(get()) } - single { CreateClient(get()) } - single { FetchClientDetails(get()) } - single { FetchClientImage(get()) } - single { BlockUnblockCommand(get()) } - single { DownloadTransactionReceipt(get()) } - single { AccountMapper(get()) } - single { FetchAccount(get(), get()) } - single { FetchAccounts(get(), get()) } - single { FetchAccountTransaction(get(), get()) } - single { FetchAccountTransactions(get(), get()) } - single { FetchAccountTransfer(get()) } - single { FetchMerchants(get()) } - single { TransferFunds(get()) } - single { - TransactionsHistory( - mUseCaseHandler = get(), - fetchAccountTransactionsUseCase = get(), - ) - } - - // Invoice UseCase - single { FetchInvoice(get()) } - single { FetchInvoices(get()) } - - // KYC UseCase - single { FetchKYCLevel1Details(get()) } - single { UpdateKYCLevel1Details(get()) } - single { UploadKYCDocs(get()) } - single { UploadKYCLevel1Details(get()) } - - // Notifications - single { FetchNotifications(get()) } - - // Saved Cards - single { AddCard(get()) } - single { DeleteCard(get()) } - single { EditCard(get()) } - single { FetchSavedCards(get()) } - - // Standing Instructions - single { CreateStandingTransaction(get()) } - single { DeleteStandingInstruction(get()) } - single { FetchStandingInstruction(get()) } - single { GetAllStandingInstructions(get()) } - single { UpdateStandingInstruction(get()) } - - // Two-Factor - single { FetchDeliveryMethods(get()) } - single { RequestOTP(get()) } - single { ValidateOTP(get()) } - - // User - single { AuthenticateUser(get()) } - single { CreateUser(get()) } - single { DeleteUser(get()) } - single { FetchUserDetails(get()) } - single { FetchUsers(get()) } - single { RegisterUser(get()) } - single { UpdateUser(get()) } - single { VerifyUser(get()) } - - // Fineract Entity Mappers - single { CurrencyMapper() } - single { SearchedEntitiesMapper() } - single { TransactionMapper(get()) } - single { AccountMapper(get()) } - single { ClientDetailsMapper() } - - // Fineract Repository - - single { - FineractRepository( - fineractApiManager = get(), - selfApiManager = get(), - ktorAuthenticationService = get(), - ) - } - - // Fineract Repository Auth - - single { AuthenticationUserRepository(get()) } - - // Fineract Repository Local - - single { - val preferencesHelper: PreferencesHelper = get() - LocalRepository(preferencesHelper) - } - - factory { - MifosLocalAssetDataSource( - ioDispatcher = get( - named(MifosDispatchers.IO.name), - ), - networkJson = get(), - assets = get(), - ) - } - - factory { - MifosLocalAssetRepository( - ioDispatcher = get( - named(MifosDispatchers.IO.name), - ), - datasource = get(), - ) - } - - // Util - - single { ConnectivityManagerNetworkMonitor(context = androidContext()) } - - single { - TimeZoneBroadcastMonitor( - context = androidContext(), - appScope = get(named("ApplicationScope")), - ioDispatcher = get(named(MifosDispatchers.IO.name)), - ) - } -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/account/BlockUnblockCommand.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/account/BlockUnblockCommand.kt deleted file mode 100644 index 45075fd22..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/account/BlockUnblockCommand.kt +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.account - -import android.util.Log -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.repository.FineractRepository - -class BlockUnblockCommand( - private val mFineractRepository: FineractRepository, -) : UseCase() { - - override fun executeUseCase(requestValues: RequestValues) { - CoroutineScope(Dispatchers.IO).launch { - try { - val res = mFineractRepository.blockUnblockAccount( - requestValues.accountId, - requestValues.command, - ) - withContext(Dispatchers.Main) { - Log.d("BlockUnblockCommand@@@@", "$res") - useCaseCallback.onSuccess(ResponseValue) - } - } catch (e: Exception) { - Log.d("BlockUnblockCommand@@@@", "${e.message}") - useCaseCallback.onError( - "Error " + requestValues.command + "ing account", - ) - } - } - } - - data class RequestValues(val accountId: Long, val command: String) : UseCase.RequestValues - data object ResponseValue : UseCase.ResponseValue -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/account/DownloadTransactionReceipt.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/account/DownloadTransactionReceipt.kt deleted file mode 100644 index 36d955040..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/account/DownloadTransactionReceipt.kt +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.account - -import okhttp3.ResponseBody -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.repository.FineractRepository -import org.mifospay.core.data.util.Constants -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers - -class DownloadTransactionReceipt( - private val mFineractRepository: FineractRepository, -) : UseCase() { - override fun executeUseCase(requestValues: RequestValues) { - requestValues.transactionId?.let { - mFineractRepository.getTransactionReceipt(Constants.PDF, it) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(e.toString()) - } - - override fun onNext(t: ResponseBody) { - useCaseCallback.onSuccess(ResponseValue(t)) - } - }, - ) - } - } - - data class RequestValues(val transactionId: String?) : UseCase.RequestValues - data class ResponseValue(val responseBody: ResponseBody) : UseCase.ResponseValue -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/account/FetchAccount.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/account/FetchAccount.kt deleted file mode 100644 index 4bc88a5e1..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/account/FetchAccount.kt +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.account - -import com.mifospay.core.model.domain.Account -import com.mifospay.core.model.entity.client.ClientAccounts -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.entity.mapper.AccountMapper -import org.mifospay.core.data.fineract.repository.FineractRepository -import org.mifospay.core.data.util.Constants -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers - -class FetchAccount( - private val fineractRepository: FineractRepository, - private val accountMapper: AccountMapper, -) : UseCase() { - - override fun executeUseCase(requestValues: RequestValues) { - fineractRepository.getSelfAccounts(requestValues.clientId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber() { - override fun onCompleted() {} - - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.ERROR_FETCHING_ACCOUNTS) - } - - override fun onNext(clientAccounts: ClientAccounts) { - val accounts = accountMapper.transform(clientAccounts) - - if (accounts.isNotEmpty()) { - var walletAccount: Account? = null - for (account in accounts) { - if (account.productId.toInt() == Constants.WALLET_ACCOUNT_SAVINGS_PRODUCT_ID) { - walletAccount = account - break - } - } - if (walletAccount != null) { - useCaseCallback.onSuccess(ResponseValue(walletAccount)) - } else { - useCaseCallback.onError(Constants.NO_ACCOUNT_FOUND) - } - } else { - useCaseCallback.onError(Constants.NO_ACCOUNTS_FOUND) - } - } - }, - ) - } - - data class RequestValues(val clientId: Long) : UseCase.RequestValues - - data class ResponseValue(val account: Account) : UseCase.ResponseValue -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/account/FetchAccountTransaction.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/account/FetchAccountTransaction.kt deleted file mode 100644 index 6ad743a05..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/account/FetchAccountTransaction.kt +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.account - -import android.util.Log -import com.mifospay.core.model.domain.Transaction -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.entity.mapper.TransactionMapper -import org.mifospay.core.data.fineract.repository.FineractRepository -import org.mifospay.core.data.util.Constants - -class FetchAccountTransaction( - private val fineractRepository: FineractRepository, - private val transactionMapper: TransactionMapper, -) : - UseCase() { - override fun executeUseCase(requestValues: RequestValues) { - CoroutineScope(Dispatchers.IO).launch { - try { - val res = fineractRepository.getSelfAccountTransactionFromId( - requestValues.accountId, - requestValues.transactionId, - ) - withContext(Dispatchers.Main) { - Log.d("FetchTransactions@@@@", "$res") - useCaseCallback.onSuccess( - ResponseValue(transactionMapper.transformInvoice(res)), - ) - } - } catch (e: Exception) { - Log.d("FetchTransactions@@@@", "${e.message}") - withContext(Dispatchers.Main) { - if (e.message == "HTTP 401 Unauthorized") { - useCaseCallback.onError(Constants.UNAUTHORIZED_ERROR) - } else { - useCaseCallback.onError( - Constants.ERROR_FETCHING_REMOTE_ACCOUNT_TRANSACTIONS, - ) - } - } - } - } - } - - data class RequestValues( - val accountId: Long, - val transactionId: Long, - ) : UseCase.RequestValues - - data class ResponseValue(val transaction: Transaction) : UseCase.ResponseValue -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/account/FetchAccountTransactions.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/account/FetchAccountTransactions.kt deleted file mode 100644 index 7ab0830d4..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/account/FetchAccountTransactions.kt +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.account - -import android.util.Log -import com.mifospay.core.model.domain.Transaction -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.entity.mapper.TransactionMapper -import org.mifospay.core.data.fineract.repository.FineractRepository -import org.mifospay.core.data.util.Constants - -class FetchAccountTransactions( - private val fineractRepository: FineractRepository, - private val transactionMapper: TransactionMapper, -) : UseCase() { - - override fun executeUseCase(requestValues: RequestValues) { - CoroutineScope(Dispatchers.IO).launch { - try { - val api = fineractRepository.getSelfAccountTransactions(requestValues.accountId) - withContext(Dispatchers.Main) { - Log.d("FetchTransactions@@@@", "$api") - useCaseCallback.onSuccess( - ResponseValue( - transactionMapper.transformTransactionList(api), - ), - ) - } - } catch (e: Exception) { - withContext(Dispatchers.Main) { - Log.d("FetchTransactions@@@@", "${e.message}") - useCaseCallback.onError( - Constants.ERROR_FETCHING_REMOTE_ACCOUNT_TRANSACTIONS, - ) - } - } - } - } - - data class RequestValues(var accountId: Long) : UseCase.RequestValues - data class ResponseValue(val transactions: List) : UseCase.ResponseValue -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/account/FetchAccountTransfer.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/account/FetchAccountTransfer.kt deleted file mode 100644 index 78cc231a7..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/account/FetchAccountTransfer.kt +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.account - -import com.mifospay.core.model.entity.accounts.savings.TransferDetail -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.repository.FineractRepository -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers - -class FetchAccountTransfer( - private val mFineractRepository: FineractRepository, -) : UseCase() { - override fun executeUseCase(requestValues: RequestValues) { - mFineractRepository.getAccountTransfer(requestValues.transferId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(e.toString()) - } - - override fun onNext(transferDetail: TransferDetail) { - useCaseCallback.onSuccess(ResponseValue(transferDetail)) - } - }) - } - - data class RequestValues(var transferId: Long) : UseCase.RequestValues - data class ResponseValue(val transferDetail: TransferDetail) : UseCase.ResponseValue -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/account/FetchAccounts.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/account/FetchAccounts.kt deleted file mode 100644 index 9b3b4732f..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/account/FetchAccounts.kt +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.account - -import com.mifospay.core.model.domain.Account -import com.mifospay.core.model.entity.client.ClientAccounts -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.entity.mapper.AccountMapper -import org.mifospay.core.data.fineract.repository.FineractRepository -import org.mifospay.core.data.util.Constants -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers - -class FetchAccounts( - private val fineractRepository: FineractRepository, - private val accountMapper: AccountMapper, -) : UseCase() { - - override fun executeUseCase(requestValues: RequestValues) { - fineractRepository.getAccounts(requestValues.clientId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.ERROR_FETCHING_ACCOUNTS) - } - - override fun onNext(t: ClientAccounts?) { - if (t != null) { - useCaseCallback.onSuccess( - ResponseValue( - accountMapper.transform(t), - ), - ) - } else { - useCaseCallback.onError(Constants.NO_ACCOUNTS_FOUND) - } - } - }, - ) - } - - data class RequestValues(val clientId: Long) : UseCase.RequestValues - data class ResponseValue(val accountList: List) : UseCase.ResponseValue -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/account/FetchMerchants.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/account/FetchMerchants.kt deleted file mode 100644 index 57bdbba0a..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/account/FetchMerchants.kt +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.account - -import android.util.Log -import com.mifospay.core.model.entity.accounts.savings.SavingsWithAssociations -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.repository.FineractRepository -import org.mifospay.core.data.util.Constants - -class FetchMerchants( - private val mFineractRepository: FineractRepository, -) : UseCase() { - override fun executeUseCase(requestValues: RequestValues) { - CoroutineScope(Dispatchers.IO).launch { - try { - val res = mFineractRepository.savingsAccounts() - withContext(Dispatchers.Main) { - Log.d("FetchMerchants@@@@", "$res") - val savingsWithAssociationsList = res.pageItems - val merchantsList: MutableList = ArrayList() - for (i in savingsWithAssociationsList.indices) { - if (savingsWithAssociationsList[i].savingsProductId == - Constants.MIFOS_MERCHANT_SAVINGS_PRODUCT_ID - ) { - merchantsList.add(savingsWithAssociationsList[i]) - } - } - useCaseCallback.onSuccess(ResponseValue(merchantsList)) - } - } catch (e: Exception) { - Log.d("FetchTransactions@@@@", "${e.message}") - e.message?.let { useCaseCallback.onError(it) } - } - } - } - - class RequestValues : UseCase.RequestValues - data class ResponseValue( - val savingsWithAssociationsList: List, - ) : UseCase.ResponseValue -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/account/TransferFunds.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/account/TransferFunds.kt deleted file mode 100644 index ec3efb669..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/account/TransferFunds.kt +++ /dev/null @@ -1,275 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.account - -import com.mifospay.core.model.entity.TPTResponse -import com.mifospay.core.model.entity.accounts.savings.SavingAccount -import com.mifospay.core.model.entity.beneficary.Beneficiary -import com.mifospay.core.model.entity.beneficary.BeneficiaryPayload -import com.mifospay.core.model.entity.beneficary.BeneficiaryUpdatePayload -import com.mifospay.core.model.entity.client.Client -import com.mifospay.core.model.entity.client.ClientAccounts -import com.mifospay.core.model.entity.payload.TransferPayload -import com.mifospay.core.model.utils.DateHelper -import okhttp3.ResponseBody -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.repository.FineractRepository -import org.mifospay.core.data.util.Constants -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers - -@Suppress("UnusedPrivateMember") -class TransferFunds( - private val apiRepository: FineractRepository, -) : UseCase() { - - // override var requestValues: RequestValues - private lateinit var fromClient: Client - private lateinit var toClient: Client - private lateinit var fromAccount: SavingAccount - private lateinit var toAccount: SavingAccount - - override fun executeUseCase(requestValues: RequestValues) { - this.walletRequestValues = requestValues - apiRepository.getSelfClientDetails(requestValues.fromClientId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber() { - override fun onCompleted() {} - - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.ERROR_FETCHING_CLIENT_DATA) - } - - override fun onNext(client: Client) { - fromClient = client - fetchToClientDetails() - } - }, - ) - } - - private fun fetchToClientDetails() { - apiRepository.getClientDetails(walletRequestValues.toClientId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber() { - override fun onCompleted() {} - - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.ERROR_FETCHING_CLIENT_DATA) - } - - override fun onNext(client: Client) { - toClient = client - fetchFromAccountDetails() - } - }, - ) - } - - private fun fetchFromAccountDetails() { - apiRepository.getSelfAccounts(walletRequestValues.fromClientId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber() { - override fun onCompleted() {} - - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.ERROR_FETCHING_FROM_ACCOUNT) - } - - override fun onNext(clientAccounts: ClientAccounts) { - val accounts = clientAccounts.savingsAccounts - if (accounts.isNotEmpty()) { - var walletAccount: SavingAccount? = null - for (account in accounts) { - if (account.productId == Constants.WALLET_ACCOUNT_SAVINGS_PRODUCT_ID) { - walletAccount = account - break - } - } - if (walletAccount != null) { - fromAccount = walletAccount - fetchToAccountDetails() - } else { - useCaseCallback.onError(Constants.NO_WALLET_FOUND) - } - } else { - useCaseCallback.onError(Constants.ERROR_FETCHING_FROM_ACCOUNT) - } - } - }, - ) - } - - private fun fetchToAccountDetails() { - apiRepository.getAccounts(walletRequestValues.toClientId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber() { - override fun onCompleted() {} - - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.ERROR_FETCHING_TO_ACCOUNT) - } - - override fun onNext(clientAccounts: ClientAccounts) { - val accounts = clientAccounts.savingsAccounts - if (accounts.isNotEmpty()) { - var walletAccount: SavingAccount? = null - for (account in accounts) { - if (account.productId == Constants.WALLET_ACCOUNT_SAVINGS_PRODUCT_ID) { - walletAccount = account - break - } - } - if (walletAccount != null) { - toAccount = walletAccount - makeTransfer() - } else { - useCaseCallback.onError(Constants.NO_WALLET_FOUND) - } - } else { - useCaseCallback.onError(Constants.ERROR_FETCHING_TO_ACCOUNT) - } - } - }, - ) - } - - private fun checkBeneficiary() { - apiRepository.beneficiaryList - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber>() { - override fun onCompleted() {} - - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.ERROR_FETCHING_BENEFICIARIES) - } - - override fun onNext(beneficiaries: List) { - var exists = false - beneficiaries.forEach { beneficiary -> - if (beneficiary.accountNumber == toAccount.accountNo) { - exists = true - if (beneficiary.transferLimit >= walletRequestValues.amount) { - makeTransfer() - } else { - updateTransferLimit(beneficiary.id?.toLong()!!) - } - return@forEach - } - } - if (!exists) { - addBeneficiary() - } - } - }, - ) - } - - private fun addBeneficiary() { - val payload = BeneficiaryPayload().apply { - accountNumber = toAccount.accountNo - name = toClient.displayName - officeName = toClient.officeName - transferLimit = walletRequestValues.amount.toInt() - accountType = 2 - } - - apiRepository.createBeneficiary(payload) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber() { - override fun onCompleted() {} - - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.ERROR_ADDING_BENEFICIARY) - } - - override fun onNext(responseBody: ResponseBody) { - makeTransfer() - } - }, - ) - } - - private fun updateTransferLimit(beneficiaryId: Long) { - val updatePayload = BeneficiaryUpdatePayload().apply { - transferLimit = walletRequestValues.amount.toInt() - } - apiRepository.updateBeneficiary(beneficiaryId, updatePayload) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber() { - override fun onCompleted() {} - - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.ERROR_ADDING_BENEFICIARY) - } - - override fun onNext(responseBody: ResponseBody) { - makeTransfer() - } - }, - ) - } - - private fun makeTransfer() { - val transferPayload = TransferPayload().apply { - fromAccountId = fromAccount.id.toInt() - fromClientId = fromClient.id.toLong() - fromAccountType = 2 - fromOfficeId = fromClient.officeId - toOfficeId = toClient.officeId - toAccountId = toAccount.id.toInt() - toClientId = toClient.id.toLong() - toAccountType = 2 - transferDate = DateHelper.getDateAsStringFromLong(System.currentTimeMillis()) - transferAmount = walletRequestValues.amount - transferDescription = Constants.WALLET_TRANSFER - } - - apiRepository.makeThirdPartyTransfer(transferPayload) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber() { - override fun onCompleted() {} - - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.ERROR_MAKING_TRANSFER) - } - - override fun onNext(responseBody: TPTResponse) { - useCaseCallback.onSuccess(ResponseValue()) - } - }, - ) - } - - data class RequestValues( - val fromClientId: Long, - val toClientId: Long, - val amount: Double, - ) : UseCase.RequestValues - - class ResponseValue : UseCase.ResponseValue -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/client/CreateClient.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/client/CreateClient.kt deleted file mode 100644 index fd84e1477..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/client/CreateClient.kt +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.client - -import com.mifospay.core.model.domain.client.NewClient -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.repository.FineractRepository -import org.mifospay.core.data.util.ErrorJsonMessageHelper.getUserMessage -import retrofit2.HttpException -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers - -class CreateClient( - private val apiRepository: FineractRepository, -) : UseCase() { - - data class RequestValues(val client: NewClient) : UseCase.RequestValues - - data class ResponseValue(val clientId: Int) : UseCase.ResponseValue - - override fun executeUseCase(requestValues: RequestValues) { - apiRepository.createClient(requestValues.client) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - var message: String - try { - message = - (e as HttpException).response()?.errorBody()?.string().toString() - message = getUserMessage(message) - } catch (e1: Exception) { - message = e1.message.toString() - } - useCaseCallback.onError(message) - } - - override fun onNext(genericResponse: ResponseValue) { - useCaseCallback.onSuccess(genericResponse) - } - }, - ) - } -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/client/FetchClientData.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/client/FetchClientData.kt deleted file mode 100644 index ad588cd33..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/client/FetchClientData.kt +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.client - -import com.mifospay.core.model.entity.Page -import com.mifospay.core.model.entity.client.Client -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.entity.mapper.ClientDetailsMapper -import org.mifospay.core.data.fineract.repository.FineractRepository -import org.mifospay.core.data.util.Constants -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers - -class FetchClientData( - private val fineractRepository: FineractRepository, - private val clientDetailsMapper: ClientDetailsMapper, -) : UseCase() { - - override fun executeUseCase(requestValues: RequestValues) { - requestValues.clientId?.let { clientId -> - fineractRepository.getSelfClientDetails(clientId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.ERROR_FETCHING_CLIENT_DATA) - } - - override fun onNext(client: Client) { - useCaseCallback.onSuccess( - ResponseValue(clientDetailsMapper.transform(client)), - ) - } - }, - ) - } ?: run { - fineractRepository.selfClientDetails - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber>() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.ERROR_FETCHING_CLIENT_DATA) - } - - override fun onNext(client: Page) { - if (client.pageItems.size != 0) { - useCaseCallback.onSuccess( - ResponseValue(clientDetailsMapper.transform(client.pageItems[0])), - ) - } else { - useCaseCallback.onError(Constants.NO_CLIENT_FOUND) - } - } - }, - ) - } - } - - data class RequestValues(val clientId: Long?) : UseCase.RequestValues - data class ResponseValue( - val clientDetails: com.mifospay.core.model.domain.client.Client, - ) : UseCase.ResponseValue -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/client/FetchClientDetails.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/client/FetchClientDetails.kt deleted file mode 100644 index 3ab9b074f..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/client/FetchClientDetails.kt +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.client - -import com.mifospay.core.model.entity.client.Client -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.repository.FineractRepository -import org.mifospay.core.data.util.Constants -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers - -class FetchClientDetails( - private val mFineractRepository: FineractRepository, -) : UseCase() { - - data class RequestValues(val clientId: Long) : UseCase.RequestValues - data class ResponseValue(val client: Client) : UseCase.ResponseValue - - override fun executeUseCase(requestValues: RequestValues) { - mFineractRepository.getClientDetails(requestValues.clientId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.ERROR_FETCHING_CLIENT_DATA) - } - - override fun onNext(client: Client) { - useCaseCallback.onSuccess(ResponseValue(client)) - } - }, - ) - } -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/client/FetchClientImage.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/client/FetchClientImage.kt deleted file mode 100644 index 90bd05665..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/client/FetchClientImage.kt +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.client - -import okhttp3.ResponseBody -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.repository.FineractRepository -import org.mifospay.core.data.util.ErrorJsonMessageHelper.getUserMessage -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers - -class FetchClientImage( - private val mFineractRepository: FineractRepository, -) : - UseCase() { - - data class RequestValues(val clientId: Long) : UseCase.RequestValues - data class ResponseValue(val responseBody: ResponseBody) : UseCase.ResponseValue - - override fun executeUseCase(requestValues: RequestValues) { - mFineractRepository.getClientImage(requestValues.clientId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - getUserMessage(e)?.let { useCaseCallback.onError(it) } - } - - override fun onNext(responseBody: ResponseBody) { - useCaseCallback.onSuccess(ResponseValue(responseBody)) - } - }, - ) - } -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/client/SearchClient.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/client/SearchClient.kt deleted file mode 100644 index 05b882da0..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/client/SearchClient.kt +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.client - -import com.mifospay.core.model.domain.SearchResult -import com.mifospay.core.model.entity.SearchedEntity -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.entity.mapper.SearchedEntitiesMapper -import org.mifospay.core.data.fineract.repository.FineractRepository -import org.mifospay.core.data.util.Constants -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers - -class SearchClient( - private val apiRepository: FineractRepository, - private val searchedEntitiesMapper: SearchedEntitiesMapper, -) : UseCase() { - - data class RequestValues(val externalId: String) : UseCase.RequestValues - data class ResponseValue(val results: List) : UseCase.ResponseValue - - override fun executeUseCase(requestValues: RequestValues) { - apiRepository.searchResources(requestValues.externalId, Constants.CLIENTS, false) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber>() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.ERROR_SEARCHING_CLIENTS) - } - - override fun onNext(results: List) { - if (results.isNotEmpty()) { - useCaseCallback.onSuccess( - ResponseValue( - searchedEntitiesMapper.transformList(results), - ), - ) - } else { - useCaseCallback.onError(Constants.NO_CLIENTS_FOUND) - } - } - }, - ) - } -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/client/UpdateClient.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/client/UpdateClient.kt deleted file mode 100644 index 6badef3e6..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/client/UpdateClient.kt +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.client - -import okhttp3.ResponseBody -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.repository.FineractRepository -import org.mifospay.core.data.util.ErrorJsonMessageHelper.getUserMessage -import retrofit2.HttpException -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers - -class UpdateClient( - private val fineractRepository: FineractRepository, -) : UseCase() { - - data class RequestValues(val updateClientEntity: Any, val clientId: Long) : - UseCase.RequestValues - - data class ResponseValue(val responseBody: ResponseBody) : UseCase.ResponseValue - - override fun executeUseCase(requestValues: RequestValues) { - fineractRepository.updateClient(requestValues.clientId, requestValues.updateClientEntity) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - var message: String - try { - message = - (e as HttpException).response()?.errorBody()?.string().toString() - message = getUserMessage(message) - } catch (e1: Exception) { - message = e1.message.toString() - } - useCaseCallback.onError(message) - } - - override fun onNext(responseBody: ResponseBody) { - useCaseCallback.onSuccess(ResponseValue(responseBody)) - } - }, - ) - } -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/history/TransactionsHistory.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/history/TransactionsHistory.kt deleted file mode 100644 index 10e105b76..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/history/TransactionsHistory.kt +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.history - -import com.mifospay.core.model.domain.Transaction -import org.mifospay.core.data.base.UseCase.UseCaseCallback -import org.mifospay.core.data.base.UseCaseHandler -import org.mifospay.core.data.domain.usecase.account.FetchAccountTransactions - -class TransactionsHistory( - private val mUseCaseHandler: UseCaseHandler, - private val fetchAccountTransactionsUseCase: FetchAccountTransactions, -) { - var delegate: HistoryContract.TransactionsHistoryAsync? = null - private var transactions: List? - - init { - transactions = ArrayList() - } - - fun fetchTransactionsHistory(accountId: Long) { - mUseCaseHandler.execute( - fetchAccountTransactionsUseCase, - FetchAccountTransactions.RequestValues(accountId), - object : UseCaseCallback { - override fun onSuccess(response: FetchAccountTransactions.ResponseValue?) { - transactions = response?.transactions - delegate!!.onTransactionsFetchCompleted(transactions) - } - - override fun onError(message: String) { - transactions = null - } - }, - ) - } -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/invoice/FetchInvoice.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/invoice/FetchInvoice.kt deleted file mode 100644 index 4a6cf57ea..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/invoice/FetchInvoice.kt +++ /dev/null @@ -1,63 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.invoice - -import android.net.Uri -import android.util.Log -import com.mifospay.core.model.entity.Invoice -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.repository.FineractRepository -import org.mifospay.core.data.util.Constants -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers - -class FetchInvoice( - private val mFineractRepository: FineractRepository, -) : UseCase() { - - class RequestValues(val uniquePaymentLink: Uri?) : UseCase.RequestValues - class ResponseValue( - val invoices: List, - ) : UseCase.ResponseValue - - override fun executeUseCase(requestValues: RequestValues) { - val paymentLink = requestValues.uniquePaymentLink - try { - val params = paymentLink?.pathSegments - val clientId = params?.get(0) // "clientId" - val invoiceId = params?.get(1) // "invoiceId" - if (clientId != null && invoiceId != null) { - mFineractRepository.fetchInvoice(clientId, invoiceId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber?>() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.INVALID_UPL) - } - - override fun onNext(invoices: List?) { - if (invoices?.isNotEmpty() == true) { - useCaseCallback.onSuccess(ResponseValue(invoices)) - } else { - useCaseCallback.onError(Constants.INVOICE_DOES_NOT_EXIST) - } - } - }, - ) - } - } catch (e: IndexOutOfBoundsException) { - Log.e("Error", e.message.toString()) - useCaseCallback.onError("Invalid link used to open the App") - } - } -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/invoice/FetchInvoices.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/invoice/FetchInvoices.kt deleted file mode 100644 index e9a4b5b2a..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/invoice/FetchInvoices.kt +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.invoice - -import android.util.Log -import com.mifospay.core.model.entity.Invoice -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.repository.FineractRepository -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers - -class FetchInvoices( - private val mFineractRepository: FineractRepository, -) : - UseCase() { - - class RequestValues(val clientId: String) : UseCase.RequestValues - class ResponseValue( - val invoiceList: List, - ) : UseCase.ResponseValue - - override fun executeUseCase(requestValues: RequestValues) { - mFineractRepository.fetchInvoices(requestValues.clientId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber>() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - Log.e("Invoices", e.message.toString()) - useCaseCallback.onError(e.toString()) - } - - override fun onNext(invoices: List) { - useCaseCallback.onSuccess(ResponseValue(invoices)) - } - }, - ) - } -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/kyc/FetchKYCLevel1Details.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/kyc/FetchKYCLevel1Details.kt deleted file mode 100644 index 42e9d19c9..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/kyc/FetchKYCLevel1Details.kt +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.kyc - -import com.mifospay.core.model.entity.kyc.KYCLevel1Details -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.repository.FineractRepository -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers - -class FetchKYCLevel1Details( - private val mFineractRepository: FineractRepository, -) : UseCase() { - - class RequestValues(val clientId: Int) : UseCase.RequestValues - class ResponseValue( - val kycLevel1DetailsList: List, - ) : UseCase.ResponseValue - - override fun executeUseCase(requestValues: RequestValues) { - mFineractRepository.fetchKYCLevel1Details(requestValues.clientId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber>() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(e.toString()) - } - - override fun onNext(kycLevel1Details: List) { - useCaseCallback.onSuccess( - ResponseValue(kycLevel1Details), - ) - } - }, - ) - } -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/kyc/UpdateKYCLevel1Details.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/kyc/UpdateKYCLevel1Details.kt deleted file mode 100644 index 6f232ca29..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/kyc/UpdateKYCLevel1Details.kt +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.kyc - -import com.mifospay.core.model.entity.kyc.KYCLevel1Details -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.repository.FineractRepository -import org.mifospay.core.network.GenericResponse -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers - -class UpdateKYCLevel1Details( - private val mFineractRepository: FineractRepository, -) : UseCase() { - - class RequestValues( - val clientId: Int, - val kycLevel1Details: KYCLevel1Details, - ) : UseCase.RequestValues - - class ResponseValue : UseCase.ResponseValue - - override fun executeUseCase(requestValues: RequestValues) { - mFineractRepository.updateKYCLevel1Details( - requestValues.clientId, - requestValues.kycLevel1Details, - ) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(e.toString()) - } - - override fun onNext(t: GenericResponse) { - useCaseCallback.onSuccess(ResponseValue()) - } - }, - ) - } -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/kyc/UploadKYCDocs.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/kyc/UploadKYCDocs.kt deleted file mode 100644 index 6eb539c1f..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/kyc/UploadKYCDocs.kt +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.kyc - -import okhttp3.MultipartBody -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.repository.FineractRepository -import org.mifospay.core.network.GenericResponse -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers - -class UploadKYCDocs( - private val apiRepository: FineractRepository, -) : UseCase() { - - class RequestValues( - val entityType: String, - val clientId: Long, - val docname: String, - val identityType: String, - val file: MultipartBody.Part, - ) : UseCase.RequestValues - - class ResponseValue : UseCase.ResponseValue - - override fun executeUseCase(requestValues: RequestValues) { - apiRepository.uploadKYCDocs( - requestValues.entityType, - requestValues.clientId, - requestValues.docname, - requestValues.identityType, - requestValues.file, - ) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(e.toString()) - } - - override fun onNext(t: GenericResponse) { - useCaseCallback.onSuccess(ResponseValue()) - } - }, - ) - } -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/kyc/UploadKYCLevel1Details.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/kyc/UploadKYCLevel1Details.kt deleted file mode 100644 index 74ace32cb..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/kyc/UploadKYCLevel1Details.kt +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.kyc - -import com.mifospay.core.model.entity.kyc.KYCLevel1Details -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.repository.FineractRepository -import org.mifospay.core.network.GenericResponse -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers - -class UploadKYCLevel1Details( - var mFineractRepository: FineractRepository, -) : UseCase() { - class RequestValues( - val clientId: Int, - val mKYCLevel1Details: KYCLevel1Details, - ) : UseCase.RequestValues - - class ResponseValue : UseCase.ResponseValue - - override fun executeUseCase(requestValues: RequestValues) { - mFineractRepository.uploadKYCLevel1Details( - requestValues.clientId, - requestValues.mKYCLevel1Details, - ) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(e.toString()) - } - - override fun onNext(t: GenericResponse) { - useCaseCallback.onSuccess(ResponseValue()) - } - }, - ) - } -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/notification/FetchNotifications.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/notification/FetchNotifications.kt deleted file mode 100644 index 4237dc12a..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/notification/FetchNotifications.kt +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.notification - -import com.mifospay.core.model.domain.NotificationPayload -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.repository.FineractRepository -import org.mifospay.core.data.util.Constants -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers - -class FetchNotifications( - private val mFineractRepository: FineractRepository, -) : UseCase() { - - class RequestValues(val clientId: Long) : UseCase.RequestValues - class ResponseValue( - val notificationPayloadList: List?, - ) : UseCase.ResponseValue - - override fun executeUseCase(requestValues: RequestValues) { - mFineractRepository.fetchNotifications(requestValues.clientId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber>() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.ERROR_FETCHING_NOTIFICATIONS) - } - - override fun onNext(notificationPayloads: List) { - useCaseCallback.onSuccess(ResponseValue(notificationPayloads)) - } - }, - ) - } -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/savedcards/AddCard.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/savedcards/AddCard.kt deleted file mode 100644 index 73bb2bbcc..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/savedcards/AddCard.kt +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.savedcards - -import com.mifospay.core.model.entity.savedcards.Card -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.repository.FineractRepository -import org.mifospay.core.network.GenericResponse -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers - -class AddCard( - private val mFineractRepository: FineractRepository, -) : UseCase() { - class RequestValues(val clientId: Long, val card: Card) : UseCase.RequestValues - class ResponseValue : UseCase.ResponseValue - - override fun executeUseCase(requestValues: RequestValues) { - mFineractRepository.addSavedCards(requestValues.clientId, requestValues.card) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(e.toString()) - } - - override fun onNext(t: GenericResponse?) { - useCaseCallback.onSuccess(ResponseValue()) - } - }, - ) - } -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/savedcards/DeleteCard.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/savedcards/DeleteCard.kt deleted file mode 100644 index c11cb90f0..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/savedcards/DeleteCard.kt +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.savedcards - -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.repository.FineractRepository -import org.mifospay.core.network.GenericResponse -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers - -class DeleteCard( - private val mFineractRepository: FineractRepository, -) : UseCase() { - - class RequestValues(val clientId: Int, val cardId: Int) : UseCase.RequestValues - class ResponseValue : UseCase.ResponseValue - - override fun executeUseCase(requestValues: RequestValues) { - mFineractRepository.deleteSavedCard(requestValues.clientId, requestValues.cardId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(e.toString()) - } - - override fun onNext(t: GenericResponse?) { - useCaseCallback.onSuccess(ResponseValue()) - } - }, - ) - } -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/savedcards/EditCard.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/savedcards/EditCard.kt deleted file mode 100644 index 7f0440b18..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/savedcards/EditCard.kt +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.savedcards - -import com.mifospay.core.model.entity.savedcards.Card -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.repository.FineractRepository -import org.mifospay.core.network.GenericResponse -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers - -class EditCard( - private val mFineractRepository: FineractRepository, -) : UseCase() { - - class RequestValues(val clientId: Int, val card: Card) : UseCase.RequestValues - class ResponseValue : UseCase.ResponseValue - - override fun executeUseCase(requestValues: RequestValues) { - mFineractRepository.editSavedCard(requestValues.clientId, requestValues.card) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(e.toString()) - } - - override fun onNext(t: GenericResponse?) { - useCaseCallback.onSuccess(ResponseValue()) - } - }, - ) - } -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/savedcards/FetchSavedCards.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/savedcards/FetchSavedCards.kt deleted file mode 100644 index 8750008de..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/savedcards/FetchSavedCards.kt +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.savedcards - -import com.mifospay.core.model.entity.savedcards.Card -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.repository.FineractRepository -import org.mifospay.core.data.util.Constants -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers - -class FetchSavedCards( - private val mFineractRepository: FineractRepository, -) : UseCase() { - - class RequestValues(val clientId: Long) : UseCase.RequestValues - class ResponseValue(val cardList: List) : UseCase.ResponseValue - - override fun executeUseCase(requestValues: RequestValues) { - mFineractRepository.fetchSavedCards(requestValues.clientId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber>() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(e.toString()) - } - - override fun onNext(cards: List) { - if (cards.isNotEmpty()) { - useCaseCallback.onSuccess(ResponseValue(cards)) - } else { - useCaseCallback.onError(Constants.NO_SAVED_CARDS) - } - } - }, - ) - } -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/standinginstruction/CreateStandingTransaction.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/standinginstruction/CreateStandingTransaction.kt deleted file mode 100644 index 5e4dfd300..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/standinginstruction/CreateStandingTransaction.kt +++ /dev/null @@ -1,206 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.standinginstruction - -import com.mifospay.core.model.entity.accounts.savings.SavingAccount -import com.mifospay.core.model.entity.client.Client -import com.mifospay.core.model.entity.client.ClientAccounts -import com.mifospay.core.model.entity.payload.StandingInstructionPayload -import com.mifospay.core.model.entity.standinginstruction.SDIResponse -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.repository.FineractRepository -import org.mifospay.core.data.util.Constants -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers - -class CreateStandingTransaction( - private val apiRepository: FineractRepository, -) : UseCase() { - - lateinit var fromClient: Client - lateinit var toClient: Client - lateinit var fromAccount: SavingAccount - lateinit var toAccount: SavingAccount - - override fun executeUseCase(requestValues: RequestValues) { - apiRepository.getSelfClientDetails(requestValues.fromClientId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber() { - - override fun onCompleted() { - } - - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.ERROR_FETCHING_CLIENT_DATA) - } - - override fun onNext(client: Client) { - fromClient = client - fetchToClientData() - } - }, - ) - } - - private fun fetchToClientData() { - apiRepository.getClientDetails(walletRequestValues.toClientId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber() { - - override fun onCompleted() { - } - - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.ERROR_FETCHING_CLIENT_DATA) - } - - override fun onNext(client: Client) { - toClient = client - fetchFromAccountDetails() - } - }, - ) - } - - private fun fetchFromAccountDetails() { - apiRepository.getSelfAccounts(walletRequestValues.fromClientId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber() { - override fun onCompleted() { - } - - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.ERROR_FETCHING_FROM_ACCOUNT) - } - - override fun onNext(clientAccounts: ClientAccounts) { - val accounts = clientAccounts.savingsAccounts - if (accounts.isNotEmpty()) { - var walletAccount: SavingAccount? = null - for (account in accounts) { - if (account.productId == - Constants.WALLET_ACCOUNT_SAVINGS_PRODUCT_ID - ) { - walletAccount = account - break - } - } - walletAccount?.let { - fromAccount = walletAccount - fetchToAccountDetails() - } ?: useCaseCallback.onError(Constants.NO_WALLET_FOUND) - } else { - useCaseCallback.onError(Constants.ERROR_FETCHING_FROM_ACCOUNT) - } - } - }, - ) - } - - private fun fetchToAccountDetails() { - apiRepository.getAccounts(walletRequestValues.toClientId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.ERROR_FETCHING_TO_ACCOUNT) - } - - override fun onNext(clientAccounts: ClientAccounts) { - val accounts = clientAccounts.savingsAccounts - if (accounts.isNotEmpty()) { - var walletAccount: SavingAccount? = null - for (account in accounts) { - if (account.productId == - Constants.WALLET_ACCOUNT_SAVINGS_PRODUCT_ID - ) { - walletAccount = account - break - } - } - walletAccount?.let { - toAccount = walletAccount - createNewStandingInstruction() - } ?: useCaseCallback.onError(Constants.NO_WALLET_FOUND) - } else { - useCaseCallback.onError(Constants.ERROR_FETCHING_TO_ACCOUNT) - } - } - }, - ) - } - - private fun createNewStandingInstruction() { - val standingInstructionPayload = StandingInstructionPayload( - fromClient.officeId, - fromClient.id, - 2, - "wallet standing transaction", - 1, - 2, - 1, - fromAccount.id, - toClient.officeId, - toClient.id, - 2, - toAccount.id, - 1, - walletRequestValues.amount, - walletRequestValues.validFrom, - 1, - walletRequestValues.recurrenceInterval, - 2, - "en", - "dd MM yyyy", - walletRequestValues.validTill, - walletRequestValues.recurrenceOnDayMonth, - "dd MM", - ) - apiRepository.createStandingInstruction(standingInstructionPayload) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber() { - - override fun onCompleted() { - } - - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.ERROR_MAKING_TRANSFER) - } - - override fun onNext(sdiResponse: SDIResponse) { - useCaseCallback.onSuccess(ResponseValue()) - } - }, - ) - } - - class RequestValues( - val validTill: String, - val validFrom: String, - val recurrenceInterval: Int, - val recurrenceOnDayMonth: String, - val fromClientId: Long, - val toClientId: Long, - val amount: Double, - ) : UseCase.RequestValues - - class ResponseValue : UseCase.ResponseValue -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/standinginstruction/DeleteStandingInstruction.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/standinginstruction/DeleteStandingInstruction.kt deleted file mode 100644 index 569a9149b..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/standinginstruction/DeleteStandingInstruction.kt +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.standinginstruction - -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.repository.FineractRepository -import org.mifospay.core.network.GenericResponse -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers - -class DeleteStandingInstruction( - private val apiRepository: FineractRepository, -) : UseCase() { - - override fun executeUseCase(requestValues: RequestValues) { - apiRepository.deleteStandingInstruction(requestValues.standingInstructionId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber() { - - override fun onCompleted() { - } - - override fun onError(e: Throwable) { - e.message?.let { useCaseCallback.onError(it) } - } - - override fun onNext(genericResponse: GenericResponse) = - useCaseCallback.onSuccess(ResponseValue()) - }, - ) - } - - class RequestValues(val standingInstructionId: Long) : - UseCase.RequestValues - - class ResponseValue : UseCase.ResponseValue -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/standinginstruction/FetchStandingInstruction.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/standinginstruction/FetchStandingInstruction.kt deleted file mode 100644 index 8e165f333..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/standinginstruction/FetchStandingInstruction.kt +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.standinginstruction - -import com.mifospay.core.model.entity.standinginstruction.StandingInstruction -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.repository.FineractRepository -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers - -class FetchStandingInstruction( - private val apiRepository: FineractRepository, -) : UseCase() { - - override fun executeUseCase(requestValues: RequestValues) { - apiRepository.getStandingInstruction(requestValues.standingInstructionId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber() { - - override fun onCompleted() { - } - - override fun onError(e: Throwable) { - e.message?.let { useCaseCallback.onError(it) } - } - - override fun onNext(standingInstruction: StandingInstruction) = - useCaseCallback.onSuccess(ResponseValue(standingInstruction)) - }, - ) - } - - class RequestValues(val standingInstructionId: Long) : UseCase.RequestValues - - class ResponseValue(val standingInstruction: StandingInstruction) : UseCase.ResponseValue -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/standinginstruction/GetAllStandingInstructions.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/standinginstruction/GetAllStandingInstructions.kt deleted file mode 100644 index 1e4338704..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/standinginstruction/GetAllStandingInstructions.kt +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.standinginstruction - -import com.mifospay.core.model.entity.Page -import com.mifospay.core.model.entity.standinginstruction.StandingInstruction -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.repository.FineractRepository -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers - -class GetAllStandingInstructions( - private val apiRepository: FineractRepository, -) : UseCase() { - - override fun executeUseCase(requestValues: RequestValues) { - apiRepository.getAllStandingInstructions(requestValues.clientId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber>() { - - override fun onCompleted() { - } - - override fun onError(e: Throwable) { - e.message?.let { useCaseCallback.onError(it) } - } - - override fun onNext(standingInstructionPage: Page) { - return useCaseCallback.onSuccess( - ResponseValue(standingInstructionPage.pageItems), - ) - } - }, - ) - } - - class RequestValues(val clientId: Long) : UseCase.RequestValues - - class ResponseValue(val standingInstructionsList: List) : - UseCase.ResponseValue -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/standinginstruction/UpdateStandingInstruction.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/standinginstruction/UpdateStandingInstruction.kt deleted file mode 100644 index 8eef580b2..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/standinginstruction/UpdateStandingInstruction.kt +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.standinginstruction - -import com.mifospay.core.model.entity.payload.StandingInstructionPayload -import com.mifospay.core.model.entity.standinginstruction.StandingInstruction -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.repository.FineractRepository -import org.mifospay.core.network.GenericResponse -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers - -class UpdateStandingInstruction( - private val apiRepository: FineractRepository, -) : UseCase() { - - override fun executeUseCase(requestValues: RequestValues) { - val validTillString = "${requestValues.standingInstruction.validTill?.get(2)} " + - "${requestValues.standingInstruction.validTill?.get(1)} " + - "${requestValues.standingInstruction.validTill?.get(0)}" - val validFromString = "${requestValues.standingInstruction.validFrom[2]} " + - "${requestValues.standingInstruction.validFrom[1]} " + - "${requestValues.standingInstruction.validFrom[0]}" - val recurrenceOnMonthDayString = "${requestValues.standingInstruction.validFrom[2]} " + - "${requestValues.standingInstruction.validFrom[1]}" - - val standingInstructionPayload = StandingInstructionPayload( - requestValues.standingInstruction.fromClient.officeId, - requestValues.standingInstruction.fromClient.id, - 2, - "wallet standing transaction", - 1, - 2, - 1, - requestValues.standingInstruction.fromAccount.id, - requestValues.standingInstruction.toClient.officeId, - requestValues.standingInstruction.toClient.id, - 2, - requestValues.standingInstruction.toAccount.id, - 1, - requestValues.standingInstruction.amount, - validFromString, - 1, - 1, - 2, - "en", - "dd MM yyyy", - validTillString, - recurrenceOnMonthDayString, - "dd MM", - ) - - apiRepository.updateStandingInstruction( - requestValues.standingInstructionId, - standingInstructionPayload, - ) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber() { - - override fun onCompleted() { - } - - override fun onError(e: Throwable) { - e.message?.let { useCaseCallback.onError(it) } - } - - override fun onNext(genericResponse: GenericResponse) = - useCaseCallback.onSuccess(ResponseValue()) - }, - ) - } - - class RequestValues( - val standingInstructionId: Long, - val standingInstruction: StandingInstruction, - ) : UseCase.RequestValues - - class ResponseValue : UseCase.ResponseValue -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/twofactor/FetchDeliveryMethods.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/twofactor/FetchDeliveryMethods.kt deleted file mode 100644 index 29cf2bb7c..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/twofactor/FetchDeliveryMethods.kt +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.twofactor - -import com.mifospay.core.model.domain.twofactor.DeliveryMethod -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.repository.FineractRepository -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers - -class FetchDeliveryMethods( - private val mFineractRepository: FineractRepository, -) : UseCase() { - - class RequestValues : UseCase.RequestValues - class ResponseValue( - val deliveryMethodList: List, - ) : UseCase.ResponseValue - - override fun executeUseCase(requestValues: RequestValues) { - mFineractRepository.deliveryMethods - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber>() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(e.toString()) - } - - override fun onNext(deliveryMethods: List) { - useCaseCallback.onSuccess(ResponseValue(deliveryMethods)) - } - }, - ) - } -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/twofactor/RequestOTP.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/twofactor/RequestOTP.kt deleted file mode 100644 index 004806f96..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/twofactor/RequestOTP.kt +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.twofactor - -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.repository.FineractRepository -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers - -class RequestOTP( - private val mFineractRepository: FineractRepository, -) : UseCase() { - - class RequestValues(val deliveryMethod: String) : UseCase.RequestValues - class ResponseValue(val response: String) : UseCase.ResponseValue - - override fun executeUseCase(requestValues: RequestValues) { - mFineractRepository.requestOTP(requestValues.deliveryMethod) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(e.toString()) - } - - override fun onNext(response: String) { - useCaseCallback.onSuccess(ResponseValue(response)) - } - }, - ) - } -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/twofactor/ValidateOTP.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/twofactor/ValidateOTP.kt deleted file mode 100644 index 1249e58be..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/twofactor/ValidateOTP.kt +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.twofactor - -import com.mifospay.core.model.domain.twofactor.AccessToken -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.repository.FineractRepository -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers - -class ValidateOTP( - private val mFineractRepository: FineractRepository, -) : UseCase() { - - class RequestValues(val token: String) : UseCase.RequestValues - class ResponseValue(val accessToken: AccessToken) : UseCase.ResponseValue - - override fun executeUseCase(requestValues: RequestValues) { - mFineractRepository.validateToken(requestValues.token) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(e.toString()) - } - - override fun onNext(accessToken: AccessToken) { - useCaseCallback.onSuccess(ResponseValue(accessToken)) - } - }, - ) - } -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/user/AuthenticateUser.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/user/AuthenticateUser.kt deleted file mode 100644 index c849b1261..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/user/AuthenticateUser.kt +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.user - -import com.mifospay.core.model.domain.user.User -import com.mifospay.core.model.entity.authentication.AuthenticationPayload -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.repository.FineractRepository -import org.mifospay.core.data.util.Constants - -class AuthenticateUser( - private val apiRepository: FineractRepository, -) : UseCase() { - - override fun executeUseCase(requestValues: RequestValues) { - CoroutineScope(Dispatchers.IO).launch { - try { - val user = apiRepository.loginSelf( - AuthenticationPayload(requestValues.username, requestValues.password), - ) - withContext(Dispatchers.Main) { - useCaseCallback.onSuccess(ResponseValue(user)) - } - } catch (e: Exception) { - withContext(Dispatchers.Main) { - useCaseCallback.onError(Constants.ERROR_LOGGING_IN) - } - } - } - } - - data class RequestValues(val username: String, val password: String) : UseCase.RequestValues - data class ResponseValue(val user: User) : UseCase.ResponseValue -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/user/CreateUser.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/user/CreateUser.kt deleted file mode 100644 index 79f056b70..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/user/CreateUser.kt +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.user - -import com.mifospay.core.model.domain.user.NewUser -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.repository.FineractRepository -import org.mifospay.core.data.util.ErrorJsonMessageHelper.getUserMessage -import retrofit2.HttpException -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers - -class CreateUser(private val apiRepository: FineractRepository) : - UseCase() { - override fun executeUseCase(requestValues: RequestValues) { - apiRepository.createUser(requestValues.user) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - getUserMessage(e) - var message: String - try { - message = (e as HttpException).response()!!.errorBody()!!.string() - message = getUserMessage(message) - } catch (e1: Exception) { - message = e1.message.toString() - } - useCaseCallback.onError(message) - } - - override fun onNext(genericResponse: ResponseValue) { - useCaseCallback.onSuccess(genericResponse) - } - }, - ) - } - - class RequestValues(val user: NewUser) : UseCase.RequestValues - class ResponseValue(val userId: Int) : UseCase.ResponseValue -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/user/DeleteUser.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/user/DeleteUser.kt deleted file mode 100644 index 2a537345f..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/user/DeleteUser.kt +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.user - -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.repository.FineractRepository -import org.mifospay.core.network.GenericResponse -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers - -class DeleteUser( - private val mFineractRepository: FineractRepository, -) : UseCase() { - override fun executeUseCase(requestValues: RequestValues) { - mFineractRepository.deleteUser(requestValues.userId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - e.message?.let { useCaseCallback.onError(it) } - } - - override fun onNext(genericResponse: GenericResponse) { - useCaseCallback.onSuccess(ResponseValue()) - } - }, - ) - } - - class RequestValues(val userId: Int) : UseCase.RequestValues - class ResponseValue : UseCase.ResponseValue -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/user/FetchUserDetails.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/user/FetchUserDetails.kt deleted file mode 100644 index 153e46ee0..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/user/FetchUserDetails.kt +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.user - -import com.mifospay.core.model.entity.UserWithRole -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.repository.FineractRepository -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers - -class FetchUserDetails( - private val mFineractRepository: FineractRepository, -) : UseCase() { - override fun executeUseCase(requestValues: RequestValues) { - mFineractRepository.getUser() - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - e.message?.let { useCaseCallback.onError(it) } - } - - override fun onNext(userWithRole: UserWithRole) { - useCaseCallback.onSuccess(ResponseValue(userWithRole)) - } - }, - ) - } - - class RequestValues(val userId: Long) : UseCase.RequestValues - class ResponseValue(val userWithRole: UserWithRole) : UseCase.ResponseValue -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/user/FetchUsers.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/user/FetchUsers.kt deleted file mode 100644 index 61340673a..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/user/FetchUsers.kt +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.user - -import com.mifospay.core.model.entity.UserWithRole -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.repository.FineractRepository -import org.mifospay.core.data.util.Constants -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers - -class FetchUsers( - private val mFineractRepository: FineractRepository, -) : UseCase() { - - override fun executeUseCase(requestValues: RequestValues) { - mFineractRepository.users - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber>() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(e.toString()) - } - - override fun onNext(userWithRoles: List) { - val tbp: MutableList = ArrayList() - for (userWithRole in userWithRoles) { - for ((_, name) in userWithRole.selectedRoles!!) { - if (name == Constants.MERCHANT) { - tbp.add(userWithRole) - break - } - } - } - useCaseCallback.onSuccess(ResponseValue(tbp)) - } - }) - } - - class RequestValues : UseCase.RequestValues - data class ResponseValue(val userWithRoleList: List) : UseCase.ResponseValue -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/user/RegisterUser.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/user/RegisterUser.kt deleted file mode 100644 index f37d1df98..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/user/RegisterUser.kt +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.user - -import com.mifospay.core.model.entity.register.RegisterPayload -import okhttp3.ResponseBody -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.repository.FineractRepository -import org.mifospay.core.data.util.Constants -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers - -class RegisterUser( - private val apiRepository: FineractRepository, -) : UseCase() { - - override fun executeUseCase(requestValues: RequestValues) { - apiRepository.registerUser(requestValues.registerPayload) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.ERROR_REGISTERING_USER) - } - - override fun onNext(t: ResponseBody?) { - useCaseCallback.onSuccess(ResponseValue()) - } - }, - ) - } - - data class RequestValues(val registerPayload: RegisterPayload) : UseCase.RequestValues - class ResponseValue : UseCase.ResponseValue -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/user/UpdateUser.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/user/UpdateUser.kt deleted file mode 100644 index 9fac23150..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/user/UpdateUser.kt +++ /dev/null @@ -1,52 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.user - -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.repository.FineractRepository -import org.mifospay.core.data.util.ErrorJsonMessageHelper.getUserMessage -import org.mifospay.core.network.GenericResponse -import retrofit2.HttpException -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers - -class UpdateUser( - private val mFineractRepository: FineractRepository, -) : UseCase() { - override fun executeUseCase(requestValues: RequestValues) { - mFineractRepository.updateUser(requestValues.updateUserEntity, requestValues.userId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - var message: String - try { - message = (e as HttpException).response()!!.errorBody()!!.string() - message = getUserMessage(message) - } catch (e1: Exception) { - message = e1.message.toString() - } - useCaseCallback.onError(message) - } - - override fun onNext(genericResponse: GenericResponse?) { - useCaseCallback.onSuccess(ResponseValue()) - } - }, - ) - } - - class RequestValues(val updateUserEntity: Any, val userId: Int) : UseCase.RequestValues - - class ResponseValue : UseCase.ResponseValue -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/user/VerifyUser.kt b/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/user/VerifyUser.kt deleted file mode 100644 index d946eff90..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/user/VerifyUser.kt +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.domain.usecase.user - -import com.mifospay.core.model.entity.register.UserVerify -import okhttp3.ResponseBody -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.repository.FineractRepository -import org.mifospay.core.data.util.Constants -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers - -class VerifyUser( - private val apiRepository: FineractRepository, -) : UseCase() { - override fun executeUseCase(requestValues: RequestValues) { - apiRepository.verifyUser(requestValues.userVerify) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe( - object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.ERROR_VERIFYING_USER) - } - - override fun onNext(t: ResponseBody?) { - useCaseCallback.onSuccess(ResponseValue()) - } - }, - ) - } - - class RequestValues(val userVerify: UserVerify) : UseCase.RequestValues - class ResponseValue : UseCase.ResponseValue -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/fineract/entity/mapper/AccountMapper.kt b/core/data/src/androidMain/java/org/mifospay/core/data/fineract/entity/mapper/AccountMapper.kt deleted file mode 100644 index 672f1a393..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/fineract/entity/mapper/AccountMapper.kt +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.fineract.entity.mapper - -import com.mifospay.core.model.domain.Account -import com.mifospay.core.model.entity.client.ClientAccounts - -class AccountMapper( - private val currencyMapper: CurrencyMapper, -) { - - fun transform(clientAccounts: ClientAccounts?): List { - val accountList = mutableListOf() - - clientAccounts?.savingsAccounts?.forEach { savingAccount -> - val account = Account( - name = savingAccount.productName, - number = savingAccount.accountNo, - id = savingAccount.id, - balance = savingAccount.accountBalance, - currency = currencyMapper.transform(savingAccount.currency), - productId = savingAccount.productId.toLong(), - ) - accountList.add(account) - } - return accountList - } -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/fineract/entity/mapper/ClientDetailsMapper.kt b/core/data/src/androidMain/java/org/mifospay/core/data/fineract/entity/mapper/ClientDetailsMapper.kt deleted file mode 100644 index eccd4a613..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/fineract/entity/mapper/ClientDetailsMapper.kt +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.fineract.entity.mapper - -import com.mifospay.core.model.entity.client.Client -import com.mifospay.core.model.domain.client.Client as DomainClient - -class ClientDetailsMapper { - fun transformList(clients: List?): List { - val clientList: MutableList = ArrayList() - clients?.forEach { client -> - clientList.add(transform(client)) - } - return clientList - } - - fun transform(client: Client?): DomainClient { - val clientDetails = DomainClient() - if (client != null) { - clientDetails.name = client.displayName - clientDetails.clientId = client.id.toLong() - clientDetails.externalId = client.externalId - clientDetails.mobileNo = client.mobileNo - } - return clientDetails - } -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/fineract/entity/mapper/CurrencyMapper.kt b/core/data/src/androidMain/java/org/mifospay/core/data/fineract/entity/mapper/CurrencyMapper.kt deleted file mode 100644 index 21270ee2d..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/fineract/entity/mapper/CurrencyMapper.kt +++ /dev/null @@ -1,23 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.fineract.entity.mapper - -import com.mifospay.core.model.entity.accounts.savings.Currency -import com.mifospay.core.model.domain.Currency as DomainCurrency - -class CurrencyMapper { - fun transform(savingsCurrency: Currency): DomainCurrency { - val currency = DomainCurrency() - currency.code = savingsCurrency.code - currency.displayLabel = savingsCurrency.displayLabel - currency.displaySymbol = savingsCurrency.displaySymbol - return currency - } -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/fineract/entity/mapper/FetchAccount.kt b/core/data/src/androidMain/java/org/mifospay/core/data/fineract/entity/mapper/FetchAccount.kt deleted file mode 100644 index d21aa0b8e..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/fineract/entity/mapper/FetchAccount.kt +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.fineract.entity.mapper - -import com.mifospay.core.model.domain.Account -import com.mifospay.core.model.entity.client.ClientAccounts -import org.mifospay.core.data.base.UseCase -import org.mifospay.core.data.fineract.repository.FineractRepository -import org.mifospay.core.data.util.Constants -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers - -class FetchAccount( - private val fineractRepository: FineractRepository, - private val accountMapper: AccountMapper, -) : UseCase() { - - override fun executeUseCase(requestValues: RequestValues) { - fineractRepository.getSelfAccounts(requestValues.clientId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() {} - - override fun onError(e: Throwable) { - useCaseCallback.onError(Constants.ERROR_FETCHING_ACCOUNTS) - } - - override fun onNext(clientAccounts: ClientAccounts) { - val accounts: List = accountMapper.transform(clientAccounts) - if (accounts.isNotEmpty()) { - var walletAccount: Account? = null - for (account in accounts) { - if (account.productId.toInt() == Constants.WALLET_ACCOUNT_SAVINGS_PRODUCT_ID) { - walletAccount = account - break - } - } - if (walletAccount != null) { - useCaseCallback.onSuccess(ResponseValue(walletAccount)) - } else { - useCaseCallback.onError(Constants.NO_ACCOUNT_FOUND) - } - } else { - useCaseCallback.onError(Constants.NO_ACCOUNTS_FOUND) - } - } - }) - } - - data class RequestValues(val clientId: Long) : UseCase.RequestValues - - data class ResponseValue(val account: Account) : UseCase.ResponseValue -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/fineract/entity/mapper/SearchedEntitiesMapper.kt b/core/data/src/androidMain/java/org/mifospay/core/data/fineract/entity/mapper/SearchedEntitiesMapper.kt deleted file mode 100644 index affc21632..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/fineract/entity/mapper/SearchedEntitiesMapper.kt +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.fineract.entity.mapper - -import com.mifospay.core.model.domain.SearchResult -import com.mifospay.core.model.entity.SearchedEntity - -class SearchedEntitiesMapper { - fun transformList(searchedEntities: List?): List { - val searchResults: MutableList = ArrayList() - - searchedEntities?.forEach { entity -> - searchResults.add(transform(entity)) - } - - return searchResults - } - - fun transform(searchedEntity: SearchedEntity): SearchResult { - val searchResult = SearchResult() - searchResult.resultId = searchedEntity.entityId - searchResult.resultName = searchedEntity.entityName - searchResult.resultType = searchedEntity.entityType - return searchResult - } -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/fineract/entity/mapper/TransactionMapper.kt b/core/data/src/androidMain/java/org/mifospay/core/data/fineract/entity/mapper/TransactionMapper.kt deleted file mode 100644 index 340298508..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/fineract/entity/mapper/TransactionMapper.kt +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.fineract.entity.mapper - -import com.mifospay.core.model.domain.Transaction -import com.mifospay.core.model.domain.TransactionType -import com.mifospay.core.model.entity.accounts.savings.SavingsWithAssociations -import com.mifospay.core.model.entity.accounts.savings.Transactions -import com.mifospay.core.model.utils.DateHelper - -class TransactionMapper( - private val currencyMapper: CurrencyMapper, -) { - - fun transformTransactionList(savingsWithAssociations: SavingsWithAssociations?): List { - val transactionList = ArrayList() - - savingsWithAssociations?.transactions?.forEach { transaction -> - transactionList.add(transformInvoice(transaction)) - } - return transactionList - } - - fun transformInvoice(transactions: Transactions?): Transaction { - val transaction = Transaction() - - if (transactions != null) { - transaction.transactionId = transactions.id.toString() - transactions.paymentDetailData?.let { - transaction.receiptId = it.receiptNumber - } - transaction.amount = transactions.amount - transactions.submittedOnDate.let { - transaction.date = DateHelper.getDateAsString(it) - } - transaction.currency = currencyMapper.transform(transactions.currency) - transaction.transactionType = TransactionType.OTHER - - if (transactions.transactionType.deposit) { - transaction.transactionType = TransactionType.CREDIT - } - - if (transactions.transactionType.withdrawal) { - transaction.transactionType = TransactionType.DEBIT - } - - transactions.transfer.let { - transaction.transferId = it.id - } - } - return transaction - } -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/fineract/repository/FineractRepository.kt b/core/data/src/androidMain/java/org/mifospay/core/data/fineract/repository/FineractRepository.kt deleted file mode 100644 index 80e0be3ea..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/fineract/repository/FineractRepository.kt +++ /dev/null @@ -1,320 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.fineract.repository - -import com.mifospay.core.model.domain.NewAccount -import com.mifospay.core.model.domain.NotificationPayload -import com.mifospay.core.model.domain.client.NewClient -import com.mifospay.core.model.domain.twofactor.AccessToken -import com.mifospay.core.model.domain.twofactor.DeliveryMethod -import com.mifospay.core.model.domain.user.NewUser -import com.mifospay.core.model.domain.user.User -import com.mifospay.core.model.entity.Invoice -import com.mifospay.core.model.entity.Page -import com.mifospay.core.model.entity.SearchedEntity -import com.mifospay.core.model.entity.TPTResponse -import com.mifospay.core.model.entity.UserWithRole -import com.mifospay.core.model.entity.accounts.savings.SavingsWithAssociations -import com.mifospay.core.model.entity.accounts.savings.Transactions -import com.mifospay.core.model.entity.accounts.savings.TransferDetail -import com.mifospay.core.model.entity.authentication.AuthenticationPayload -import com.mifospay.core.model.entity.beneficary.Beneficiary -import com.mifospay.core.model.entity.beneficary.BeneficiaryPayload -import com.mifospay.core.model.entity.beneficary.BeneficiaryUpdatePayload -import com.mifospay.core.model.entity.client.Client -import com.mifospay.core.model.entity.client.ClientAccounts -import com.mifospay.core.model.entity.kyc.KYCLevel1Details -import com.mifospay.core.model.entity.payload.StandingInstructionPayload -import com.mifospay.core.model.entity.payload.TransferPayload -import com.mifospay.core.model.entity.register.RegisterPayload -import com.mifospay.core.model.entity.register.UserVerify -import com.mifospay.core.model.entity.savedcards.Card -import com.mifospay.core.model.entity.standinginstruction.SDIResponse -import com.mifospay.core.model.entity.standinginstruction.StandingInstruction -import okhttp3.MultipartBody -import okhttp3.ResponseBody -import org.mifos.core.network.services.KtorAuthenticationService -import org.mifospay.core.data.domain.usecase.client.CreateClient -import org.mifospay.core.data.domain.usecase.user.CreateUser -import org.mifospay.core.data.util.Constants -import org.mifospay.core.network.FineractApiManager -import org.mifospay.core.network.GenericResponse -import org.mifospay.core.network.SelfServiceApiManager -import rx.Observable - -@Suppress("TooManyFunctions") -class FineractRepository( - private val fineractApiManager: FineractApiManager, - private val selfApiManager: SelfServiceApiManager, - private val ktorAuthenticationService: KtorAuthenticationService, -) { - fun createClient(newClient: NewClient): Observable { - return fineractApiManager.clientsApi.createClient(newClient) - } - - fun createUser(user: NewUser): Observable { - return fineractApiManager.userApi.createUser(user) - } - - fun updateUser(updateUserEntity: Any, userId: Int): Observable { - return fineractApiManager.userApi.updateUser(userId, updateUserEntity) - } - - fun registerUser(registerPayload: RegisterPayload): Observable { - return fineractApiManager.registrationAPi.registerUser(registerPayload) - } - - fun deleteUser(userId: Int): Observable { - return fineractApiManager.userApi.deleteUser(userId) - } - - fun verifyUser(userVerify: UserVerify): Observable { - return fineractApiManager.registrationAPi.verifyUser(userVerify) - } - - fun searchResources( - query: String, - resources: String, - exactMatch: Boolean, - ): Observable> { - return fineractApiManager.searchApi.searchResources(query, resources, exactMatch) - } - - fun updateClient(clientId: Long, payload: Any): Observable { - return fineractApiManager.clientsApi.updateClient(clientId, payload) - .map { responseBody -> responseBody } - } - - fun createSavingsAccount(newAccount: NewAccount?): Observable { - return fineractApiManager.clientsApi.createAccount(newAccount) - } - - fun getAccounts(clientId: Long): Observable { - return fineractApiManager.clientsApi.getAccounts(clientId, Constants.SAVINGS) - } - - suspend fun savingsAccounts(): Page = - fineractApiManager.ktorSavingsAccountApi.getSavingsAccounts(-1) - - suspend fun blockUnblockAccount(accountId: Long, command: String?): GenericResponse { - return fineractApiManager.ktorSavingsAccountApi.blockUnblockAccount( - accountId, - command, - ) - } - - fun getClientDetails(clientId: Long): Observable { - return fineractApiManager.clientsApi.getClientForId(clientId) - } - - fun getClientImage(clientId: Long): Observable { - return fineractApiManager.clientsApi.getClientImage(clientId) - } - - fun addSavedCards( - clientId: Long, - card: Card, - ): Observable { - return fineractApiManager.savedCardApi.addSavedCard(clientId.toInt(), card) - } - - fun fetchSavedCards(clientId: Long): Observable> { - return fineractApiManager.savedCardApi.getSavedCards(clientId.toInt()) - } - - fun editSavedCard(clientId: Int, card: Card): Observable { - return fineractApiManager.savedCardApi.updateCard(clientId, card.id, card) - } - - fun deleteSavedCard(clientId: Int, cardId: Int): Observable { - return fineractApiManager.savedCardApi.deleteCard(clientId, cardId) - } - - fun uploadKYCDocs( - entityType: String, - entityId: Long, - name: String, - desc: String, - file: MultipartBody.Part, - ): Observable { - return fineractApiManager.documentApi.createDocument( - entityType, - entityId, - name, - desc, - file, - ) - } - - fun getAccountTransfer(transferId: Long): Observable { - return fineractApiManager.accountTransfersApi.getAccountTransfer(transferId) - } - - fun uploadKYCLevel1Details( - clientId: Int, - kycLevel1Details: KYCLevel1Details, - ): Observable { - return fineractApiManager.kycLevel1Api.addKYCLevel1Details( - clientId, - kycLevel1Details, - ) - } - - fun fetchKYCLevel1Details(clientId: Int): Observable> { - return fineractApiManager.kycLevel1Api.fetchKYCLevel1Details(clientId) - } - - fun updateKYCLevel1Details( - clientId: Int, - kycLevel1Details: KYCLevel1Details, - ): Observable { - return fineractApiManager.kycLevel1Api.updateKYCLevel1Details( - clientId, - kycLevel1Details, - ) - } - - fun fetchNotifications(clientId: Long): Observable> { - return fineractApiManager.notificationApi.fetchNotifications(clientId) - } - - val deliveryMethods: Observable> - get() = fineractApiManager.twoFactorAuthApi.deliveryMethods - - fun requestOTP(deliveryMethod: String): Observable { - return fineractApiManager.twoFactorAuthApi.requestOTP(deliveryMethod) - } - - fun validateToken(token: String): Observable { - return fineractApiManager.twoFactorAuthApi.validateToken(token) - } - - fun getTransactionReceipt( - outputType: String, - transactionId: String, - ): Observable { - return fineractApiManager.runReportApi.getTransactionReceipt( - outputType, - transactionId, - ) - } - - fun addInvoice(clientId: String, invoice: Invoice?): Observable { - return fineractApiManager.invoiceApi.addInvoice(clientId, invoice) - } - - fun fetchInvoices(clientId: String): Observable> { - return fineractApiManager.invoiceApi.getInvoices(clientId) - } - - fun fetchInvoice(clientId: String, invoiceId: String): Observable> { - return fineractApiManager.invoiceApi.getInvoice(clientId, invoiceId) - } - - fun editInvoice(clientId: String, invoice: Invoice): Observable { - return fineractApiManager.invoiceApi.updateInvoice(clientId, invoice.id, invoice) - } - - fun deleteInvoice(clientId: String, invoiceId: Int): Observable { - return fineractApiManager.invoiceApi.deleteInvoice(clientId, invoiceId) - } - - val users: Observable> - get() = fineractApiManager.userApi.users - - fun getUser(): Observable { - return fineractApiManager.userApi.getUser() - } - - fun makeThirdPartyTransfer(transferPayload: TransferPayload): Observable { - return fineractApiManager.thirdPartyTransferApi.makeTransfer(transferPayload) - } - - fun createStandingInstruction( - standingInstructionPayload: StandingInstructionPayload, - ): Observable { - return fineractApiManager.standingInstructionApi - .createStandingInstruction(standingInstructionPayload) - } - - fun getAllStandingInstructions(clientId: Long): Observable> { - return fineractApiManager.standingInstructionApi.getAllStandingInstructions(clientId) - } - - fun getStandingInstruction(standingInstructionId: Long): Observable { - return fineractApiManager.standingInstructionApi - .getStandingInstruction(standingInstructionId) - } - - fun updateStandingInstruction( - standingInstructionId: Long, - data: StandingInstructionPayload, - ): Observable { - return fineractApiManager.standingInstructionApi.updateStandingInstruction( - standingInstructionId, - data, - "update", - ) - } - - fun deleteStandingInstruction(standingInstruction: Long): Observable { - return fineractApiManager.standingInstructionApi.deleteStandingInstruction( - standingInstruction, - "delete", - ) - } - - // self user apis - suspend fun loginSelf(payload: AuthenticationPayload): User { - return ktorAuthenticationService.authenticate(payload) - } - - fun getSelfClientDetails(clientId: Long): Observable { - return selfApiManager.clientsApi.getClientForId(clientId) - } - - val selfClientDetails: Observable> - get() = selfApiManager.clientsApi.clients - - suspend fun getSelfAccountTransactions(accountId: Long): SavingsWithAssociations { - return selfApiManager.ktorSavingsAccountApi.getSavingsWithAssociations( - accountId, - Constants.TRANSACTIONS, - ) - } - - suspend fun getSelfAccountTransactionFromId( - accountId: Long, - transactionId: Long, - ): Transactions { - return selfApiManager.ktorSavingsAccountApi.getSavingAccountTransaction( - accountId, - transactionId, - ) - } - - fun getSelfAccounts(clientId: Long): Observable { - return selfApiManager.clientsApi.getAccounts(clientId, Constants.SAVINGS) - } - - val beneficiaryList: Observable> - get() = selfApiManager.beneficiaryApi.beneficiaryList - - fun createBeneficiary(beneficiaryPayload: BeneficiaryPayload): Observable { - return selfApiManager.beneficiaryApi.createBeneficiary(beneficiaryPayload) - } - - fun updateBeneficiary( - beneficiaryId: Long, - payload: BeneficiaryUpdatePayload, - ): Observable { - return selfApiManager.beneficiaryApi.updateBeneficiary(beneficiaryId, payload) - } -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/repository/auth/AuthenticationUserRepository.kt b/core/data/src/androidMain/java/org/mifospay/core/data/repository/auth/AuthenticationUserRepository.kt deleted file mode 100644 index 70cc1a2c3..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/repository/auth/AuthenticationUserRepository.kt +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.repository.auth - -import com.mifospay.core.model.UserData -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.flow -import org.mifospay.core.datastore.PreferencesHelper - -class AuthenticationUserRepository( - private val preferencesHelper: PreferencesHelper, -) : UserDataRepository { - - override val userData: Flow = flow { - emit( - UserData( - isAuthenticated = !preferencesHelper.token.isNullOrEmpty(), - userName = preferencesHelper.username, - // user = preferencesHelper.user, - clientId = preferencesHelper.clientId, - ), - ) - } - - override fun logOut() { - preferencesHelper.clear() - } -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/repository/local/LocalRepository.kt b/core/data/src/androidMain/java/org/mifospay/core/data/repository/local/LocalRepository.kt deleted file mode 100644 index de55915ed..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/repository/local/LocalRepository.kt +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.repository.local - -import com.mifospay.core.model.domain.client.Client -import org.mifospay.core.datastore.PreferencesHelper - -class LocalRepository( - val preferencesHelper: PreferencesHelper, -) { - - val clientDetails: Client - get() { - val details = Client() - details.name = preferencesHelper.fullName - details.clientId = preferencesHelper.clientId - details.externalId = preferencesHelper.clientVpa - return details - } - - fun saveClientData(client: Client) { - preferencesHelper.saveFullName(client.name) - preferencesHelper.clientId = client.clientId - preferencesHelper.clientVpa = client.externalId - } -} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/repository/local/MifosLocalAssetRepository.kt b/core/data/src/androidMain/java/org/mifospay/core/data/repository/local/MifosLocalAssetRepository.kt deleted file mode 100644 index c93b060fa..000000000 --- a/core/data/src/androidMain/java/org/mifospay/core/data/repository/local/MifosLocalAssetRepository.kt +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.data.repository.local - -import com.mifospay.core.model.City -import com.mifospay.core.model.Country -import com.mifospay.core.model.State -import kotlinx.coroutines.CoroutineDispatcher -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.flow -import kotlinx.coroutines.flow.flowOn -import org.mifos.core.network.localAssets.LocalAssetDataSource - -/** - * Local implementation of the [LocalAssetRepository] that retrieves the countries, banks, cities - * and state list from a JSON String. - * - */ - -class MifosLocalAssetRepository( - private val ioDispatcher: CoroutineDispatcher, - private val datasource: LocalAssetDataSource, -) : LocalAssetRepository { - - override fun getCountries(): Flow> = flow { - emit(datasource.getCountries()) - }.flowOn(ioDispatcher) - - override fun getStateList(): Flow> = flow { - emit(datasource.getStateList()) - }.flowOn(ioDispatcher) - - override fun getBanks(): Flow> = flow { - emit(datasource.getBanks()) - }.flowOn(ioDispatcher) - - override fun getCities(): Flow> = flow { - emit(datasource.getCities()) - }.flowOn(ioDispatcher) -} diff --git a/core/data/src/androidMain/kotlin/org/mifospay/core/data/di/AndroidPlatformDependentDataModule.kt b/core/data/src/androidMain/kotlin/org/mifospay/core/data/di/AndroidPlatformDependentDataModule.kt new file mode 100644 index 000000000..8d825d28b --- /dev/null +++ b/core/data/src/androidMain/kotlin/org/mifospay/core/data/di/AndroidPlatformDependentDataModule.kt @@ -0,0 +1,32 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.di + +import android.content.Context +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.CoroutineScope +import org.mifospay.core.data.util.ConnectivityManagerNetworkMonitor +import org.mifospay.core.data.util.NetworkMonitor +import org.mifospay.core.data.util.TimeZoneBroadcastMonitor +import org.mifospay.core.data.util.TimeZoneMonitor + +class AndroidPlatformDependentDataModule( + private val context: Context, + private val dispatcher: CoroutineDispatcher, + private val scope: CoroutineScope, +) : PlatformDependentDataModule() { + override fun bindsNetworkMonitor(): NetworkMonitor { + return ConnectivityManagerNetworkMonitor(context, dispatcher) + } + + override fun bindsTimeZoneMonitor(): TimeZoneMonitor { + return TimeZoneBroadcastMonitor(context, scope, dispatcher) + } +} diff --git a/core/data/src/androidMain/kotlin/org/mifospay/core/data/di/AndroidPlatformModule.kt b/core/data/src/androidMain/kotlin/org/mifospay/core/data/di/AndroidPlatformModule.kt new file mode 100644 index 000000000..f975f2d91 --- /dev/null +++ b/core/data/src/androidMain/kotlin/org/mifospay/core/data/di/AndroidPlatformModule.kt @@ -0,0 +1,41 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.di + +import org.koin.android.ext.koin.androidContext +import org.koin.core.qualifier.named +import org.koin.dsl.module +import org.mifospay.core.common.MifosDispatchers +import org.mifospay.core.data.util.ConnectivityManagerNetworkMonitor +import org.mifospay.core.data.util.NetworkMonitor +import org.mifospay.core.data.util.TimeZoneBroadcastMonitor +import org.mifospay.core.data.util.TimeZoneMonitor + +val androidDataModule = module { + single { + ConnectivityManagerNetworkMonitor(androidContext(), get(named(MifosDispatchers.IO.name))) + } + + single { + TimeZoneBroadcastMonitor( + context = androidContext(), + appScope = get(named("ApplicationScope")), + ioDispatcher = get(named(MifosDispatchers.IO.name)), + ) + } + + single { + AndroidPlatformDependentDataModule( + context = androidContext(), + dispatcher = get(named(MifosDispatchers.IO.name)), + scope = get(named("ApplicationScope")), + ) + } +} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/util/ConnectivityManagerNetworkMonitor.kt b/core/data/src/androidMain/kotlin/org/mifospay/core/data/util/ConnectivityManagerNetworkMonitor.kt similarity index 84% rename from core/data/src/androidMain/java/org/mifospay/core/data/util/ConnectivityManagerNetworkMonitor.kt rename to core/data/src/androidMain/kotlin/org/mifospay/core/data/util/ConnectivityManagerNetworkMonitor.kt index 8e0986c79..5d1e606e9 100644 --- a/core/data/src/androidMain/java/org/mifospay/core/data/util/ConnectivityManagerNetworkMonitor.kt +++ b/core/data/src/androidMain/kotlin/org/mifospay/core/data/util/ConnectivityManagerNetworkMonitor.kt @@ -16,16 +16,17 @@ import android.net.Network import android.net.NetworkCapabilities import android.net.NetworkRequest import android.net.NetworkRequest.Builder -import android.os.Build.VERSION -import android.os.Build.VERSION_CODES import androidx.core.content.getSystemService +import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.channels.awaitClose import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.callbackFlow import kotlinx.coroutines.flow.conflate +import kotlinx.coroutines.flow.flowOn internal class ConnectivityManagerNetworkMonitor( private val context: Context, + ioDispatcher: CoroutineDispatcher, ) : NetworkMonitor { override val isOnline: Flow = callbackFlow { val connectivityManager = context.getSystemService() @@ -53,12 +54,10 @@ internal class ConnectivityManagerNetworkMonitor( channel.trySend(networks.isNotEmpty()) } } - val request = Builder() .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) .build() connectivityManager.registerNetworkCallback(request, callback) - /** * Sends the latest connectivity status to the underlying channel. */ @@ -68,15 +67,10 @@ internal class ConnectivityManagerNetworkMonitor( connectivityManager.unregisterNetworkCallback(callback) } } + .flowOn(ioDispatcher) .conflate() - @Suppress("DEPRECATION") - private fun ConnectivityManager.isCurrentlyConnected() = when { - VERSION.SDK_INT >= VERSION_CODES.M -> - activeNetwork - ?.let(::getNetworkCapabilities) - ?.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) - - else -> activeNetworkInfo?.isConnected - } ?: false + private fun ConnectivityManager.isCurrentlyConnected() = activeNetwork + ?.let(::getNetworkCapabilities) + ?.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) ?: false } diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/util/ErrorJsonMessageHelper.kt b/core/data/src/androidMain/kotlin/org/mifospay/core/data/util/ErrorJsonMessageHelper.kt similarity index 100% rename from core/data/src/androidMain/java/org/mifospay/core/data/util/ErrorJsonMessageHelper.kt rename to core/data/src/androidMain/kotlin/org/mifospay/core/data/util/ErrorJsonMessageHelper.kt diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/util/TimeZoneMonitor.kt b/core/data/src/androidMain/kotlin/org/mifospay/core/data/util/TimeZoneBroadcastMonitor.kt similarity index 91% rename from core/data/src/androidMain/java/org/mifospay/core/data/util/TimeZoneMonitor.kt rename to core/data/src/androidMain/kotlin/org/mifospay/core/data/util/TimeZoneBroadcastMonitor.kt index bd92230cd..012bd5376 100644 --- a/core/data/src/androidMain/java/org/mifospay/core/data/util/TimeZoneMonitor.kt +++ b/core/data/src/androidMain/kotlin/org/mifospay/core/data/util/TimeZoneBroadcastMonitor.kt @@ -19,7 +19,6 @@ import androidx.tracing.trace import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.channels.awaitClose -import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.SharedFlow import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.callbackFlow @@ -31,19 +30,10 @@ import kotlinx.datetime.TimeZone import kotlinx.datetime.toKotlinTimeZone import java.time.ZoneId -/** - * Utility for reporting current timezone the device has set. - * It always emits at least once with default setting and then for each TZ change. - */ - -interface TimeZoneMonitor { - val currentTimeZone: Flow -} - internal class TimeZoneBroadcastMonitor( private val context: Context, appScope: CoroutineScope, - private val ioDispatcher: CoroutineDispatcher, + ioDispatcher: CoroutineDispatcher, ) : TimeZoneMonitor { override val currentTimeZone: SharedFlow = diff --git a/core/data/src/androidMain/assets/banks.json b/core/data/src/commonMain/assets/banks.json similarity index 100% rename from core/data/src/androidMain/assets/banks.json rename to core/data/src/commonMain/assets/banks.json diff --git a/core/data/src/androidMain/assets/cities.json b/core/data/src/commonMain/assets/cities.json similarity index 100% rename from core/data/src/androidMain/assets/cities.json rename to core/data/src/commonMain/assets/cities.json diff --git a/core/data/src/androidMain/assets/countriesToCities.json b/core/data/src/commonMain/assets/countriesToCities.json similarity index 100% rename from core/data/src/androidMain/assets/countriesToCities.json rename to core/data/src/commonMain/assets/countriesToCities.json diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/di/LocalDataModule.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/di/PlatformDependentDataModule.kt similarity index 58% rename from core/data/src/androidMain/java/org/mifospay/core/data/di/LocalDataModule.kt rename to core/data/src/commonMain/kotlin/org/mifospay/core/data/di/PlatformDependentDataModule.kt index 87be810d2..0a635a1f7 100644 --- a/core/data/src/androidMain/java/org/mifospay/core/data/di/LocalDataModule.kt +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/di/PlatformDependentDataModule.kt @@ -9,11 +9,11 @@ */ package org.mifospay.core.data.di -import androidx.lifecycle.SavedStateHandle -import org.koin.dsl.module +import org.mifospay.core.data.util.NetworkMonitor +import org.mifospay.core.data.util.TimeZoneMonitor -val LocalDataModule = module { - factory { - SavedStateHandle() - } +abstract class PlatformDependentDataModule { + abstract fun bindsNetworkMonitor(): NetworkMonitor + + abstract fun bindsTimeZoneMonitor(): TimeZoneMonitor } diff --git a/core/data/src/commonMain/kotlin/org/mifospay/core/data/di/RepositoryModule.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/di/RepositoryModule.kt new file mode 100644 index 000000000..c551d41d4 --- /dev/null +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/di/RepositoryModule.kt @@ -0,0 +1,77 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.di + +import org.koin.core.qualifier.named +import org.koin.dsl.module +import org.mifospay.core.common.MifosDispatchers +import org.mifospay.core.data.repository.AccountRepository +import org.mifospay.core.data.repository.AuthenticationRepository +import org.mifospay.core.data.repository.BeneficiaryRepository +import org.mifospay.core.data.repository.ClientRepository +import org.mifospay.core.data.repository.DocumentRepository +import org.mifospay.core.data.repository.InvoiceRepository +import org.mifospay.core.data.repository.KycLevelRepository +import org.mifospay.core.data.repository.NotificationRepository +import org.mifospay.core.data.repository.RegistrationRepository +import org.mifospay.core.data.repository.RunReportRepository +import org.mifospay.core.data.repository.SavedCardRepository +import org.mifospay.core.data.repository.SavingsAccountRepository +import org.mifospay.core.data.repository.SearchRepository +import org.mifospay.core.data.repository.SelfServiceRepository +import org.mifospay.core.data.repository.StandingInstructionRepository +import org.mifospay.core.data.repository.ThirdPartyTransferRepository +import org.mifospay.core.data.repository.TwoFactorAuthRepository +import org.mifospay.core.data.repository.UserRepository +import org.mifospay.core.data.repositoryImp.AccountRepositoryImpl +import org.mifospay.core.data.repositoryImp.AuthenticationRepositoryImpl +import org.mifospay.core.data.repositoryImp.BeneficiaryRepositoryImpl +import org.mifospay.core.data.repositoryImp.ClientRepositoryImpl +import org.mifospay.core.data.repositoryImp.DocumentRepositoryImpl +import org.mifospay.core.data.repositoryImp.InvoiceRepositoryImpl +import org.mifospay.core.data.repositoryImp.KycLevelRepositoryImpl +import org.mifospay.core.data.repositoryImp.NotificationRepositoryImpl +import org.mifospay.core.data.repositoryImp.RegistrationRepositoryImpl +import org.mifospay.core.data.repositoryImp.RunReportRepositoryImpl +import org.mifospay.core.data.repositoryImp.SavedCardRepositoryImpl +import org.mifospay.core.data.repositoryImp.SavingsAccountRepositoryImpl +import org.mifospay.core.data.repositoryImp.SearchRepositoryImpl +import org.mifospay.core.data.repositoryImp.SelfServiceRepositoryImpl +import org.mifospay.core.data.repositoryImp.StandingInstructionRepositoryImpl +import org.mifospay.core.data.repositoryImp.ThirdPartyTransferRepositoryImpl +import org.mifospay.core.data.repositoryImp.TwoFactorAuthRepositoryImpl +import org.mifospay.core.data.repositoryImp.UserRepositoryImpl + +private val ioDispatcher = named(MifosDispatchers.IO.name) + +val repositoryModule = module { + single { AccountRepositoryImpl(get(), get(ioDispatcher)) } + single { AuthenticationRepositoryImpl(get(), get(ioDispatcher)) } + single { BeneficiaryRepositoryImpl(get(), get(ioDispatcher)) } + single { ClientRepositoryImpl(get(), get(ioDispatcher)) } + single { DocumentRepositoryImpl(get(), get(ioDispatcher)) } + single { InvoiceRepositoryImpl(get(), get(ioDispatcher)) } + single { KycLevelRepositoryImpl(get(), get(ioDispatcher)) } + single { NotificationRepositoryImpl(get(), get(ioDispatcher)) } + single { RegistrationRepositoryImpl(get(), get(ioDispatcher)) } + single { RunReportRepositoryImpl(get(), get(ioDispatcher)) } + single { SavedCardRepositoryImpl(get(), get(ioDispatcher)) } + single { SavingsAccountRepositoryImpl(get(), get(ioDispatcher)) } + single { SearchRepositoryImpl(get(), get(ioDispatcher)) } + single { SelfServiceRepositoryImpl(get(), get(ioDispatcher)) } + single { + StandingInstructionRepositoryImpl(get(), get(ioDispatcher)) + } + single { + ThirdPartyTransferRepositoryImpl(get(), get(ioDispatcher)) + } + single { TwoFactorAuthRepositoryImpl(get(), get(ioDispatcher)) } + single { UserRepositoryImpl(get(), get(ioDispatcher)) } +} diff --git a/core/data/src/commonMain/kotlin/org/mifospay/core/data/mapper/AccountMapper.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/mapper/AccountMapper.kt new file mode 100644 index 000000000..e4aca8873 --- /dev/null +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/mapper/AccountMapper.kt @@ -0,0 +1,26 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.mapper + +import org.mifospay.core.model.domain.Account +import org.mifospay.core.model.entity.client.ClientAccounts + +fun ClientAccounts.toAccount(): List { + return this.savingsAccounts.map { + Account( + name = it.productName, + number = it.accountNo, + id = it.id, + balance = it.accountBalance, + currency = it.currency.toModel(), + productId = it.productId.toLong(), + ) + } +} diff --git a/core/data/src/commonMain/kotlin/org/mifospay/core/data/mapper/ClientDetailsMapper.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/mapper/ClientDetailsMapper.kt new file mode 100644 index 000000000..727d28a4f --- /dev/null +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/mapper/ClientDetailsMapper.kt @@ -0,0 +1,34 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.mapper + +import org.mifospay.core.model.domain.client.Client +import org.mifospay.core.model.entity.Page +import org.mifospay.core.model.entity.client.ClientEntity + +fun ClientEntity.toModel(): Client { + return Client( + name = this.displayName, + clientId = this.id.toLong(), + externalId = this.externalId, + mobileNo = this.mobileNo, + displayName = this.displayName ?: "", + image = this.imageId.toString(), + ) +} + +fun List.toModel(): List = map { it.toModel() } + +fun Page.toModel(): Page { + return Page( + totalFilteredRecords = this.totalFilteredRecords, + pageItems = this.pageItems.map { it.toModel() }.toMutableList(), + ) +} diff --git a/core/data/src/commonMain/kotlin/org/mifospay/core/data/mapper/CurrencyMapper.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/mapper/CurrencyMapper.kt new file mode 100644 index 000000000..c70c2c882 --- /dev/null +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/mapper/CurrencyMapper.kt @@ -0,0 +1,21 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.mapper + +import org.mifospay.core.model.entity.accounts.savings.Currency +import org.mifospay.core.model.domain.Currency as DomainCurrency + +fun Currency.toModel(): DomainCurrency { + return DomainCurrency( + code = this.code, + displayLabel = this.displayLabel, + displaySymbol = this.displaySymbol, + ) +} diff --git a/core/data/src/commonMain/kotlin/org/mifospay/core/data/mapper/SearchedEntitiesMapper.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/mapper/SearchedEntitiesMapper.kt new file mode 100644 index 000000000..4208aed4a --- /dev/null +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/mapper/SearchedEntitiesMapper.kt @@ -0,0 +1,23 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.mapper + +import org.mifospay.core.model.domain.SearchResult +import org.mifospay.core.model.entity.SearchedEntity + +fun SearchedEntity.toSearchResult(): SearchResult { + return SearchResult( + resultId = this.entityId, + resultName = this.entityName, + resultType = this.entityType, + ) +} + +fun List.toSearchResult(): List = map { it.toSearchResult() } diff --git a/core/data/src/commonMain/kotlin/org/mifospay/core/data/mapper/TransactionMapper.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/mapper/TransactionMapper.kt new file mode 100644 index 000000000..41c4820b3 --- /dev/null +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/mapper/TransactionMapper.kt @@ -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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.mapper + +import org.mifospay.core.model.domain.Transaction +import org.mifospay.core.model.domain.TransactionType +import org.mifospay.core.model.entity.accounts.savings.SavingsWithAssociationsEntity +import org.mifospay.core.model.entity.accounts.savings.TransactionsEntity +import org.mifospay.core.model.utils.DateHelper + +fun SavingsWithAssociationsEntity.toTransactionList(): List { + return this.transactions.map { it.toModel() } +} + +fun TransactionsEntity.toModel(): Transaction { + return Transaction( + transactionId = this.id.toString(), + receiptId = this.paymentDetailData?.receiptNumber, + amount = this.amount, + date = DateHelper.getDateAsString(this.submittedOnDate), + currency = this.currency.toModel(), + transactionType = when { + this.transactionType.deposit -> TransactionType.CREDIT + this.transactionType.withdrawal -> TransactionType.DEBIT + else -> TransactionType.OTHER + }, + transferId = this.originalTransactionId ?: 0, + ) +} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/repository/auth/UserDataRepository.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/AccountRepository.kt similarity index 57% rename from core/data/src/androidMain/java/org/mifospay/core/data/repository/auth/UserDataRepository.kt rename to core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/AccountRepository.kt index 5241ba9ab..246d77517 100644 --- a/core/data/src/androidMain/java/org/mifospay/core/data/repository/auth/UserDataRepository.kt +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/AccountRepository.kt @@ -7,16 +7,12 @@ * * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md */ -package org.mifospay.core.data.repository.auth +package org.mifospay.core.data.repository -import com.mifospay.core.model.UserData import kotlinx.coroutines.flow.Flow +import org.mifospay.core.common.Result +import org.mifospay.core.model.entity.accounts.savings.TransferDetail -interface UserDataRepository { - /** - * Stream of [UserData] - */ - val userData: Flow - - fun logOut(): Unit +interface AccountRepository { + suspend fun getAccountTransfer(transferId: Long): Flow> } diff --git a/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/AuthenticationRepository.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/AuthenticationRepository.kt new file mode 100644 index 000000000..a8102a1db --- /dev/null +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/AuthenticationRepository.kt @@ -0,0 +1,19 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.repository + +import kotlinx.coroutines.flow.Flow +import org.mifospay.core.common.Result +import org.mifospay.core.model.domain.user.User +import org.mifospay.core.model.entity.authentication.AuthenticationPayload + +interface AuthenticationRepository { + suspend fun authenticate(payload: AuthenticationPayload): Flow> +} diff --git a/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/BeneficiaryRepository.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/BeneficiaryRepository.kt new file mode 100644 index 000000000..d21675c7b --- /dev/null +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/BeneficiaryRepository.kt @@ -0,0 +1,33 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.repository + +import kotlinx.coroutines.flow.Flow +import org.mifospay.core.common.Result +import org.mifospay.core.model.entity.beneficary.Beneficiary +import org.mifospay.core.model.entity.beneficary.BeneficiaryPayload +import org.mifospay.core.model.entity.beneficary.BeneficiaryUpdatePayload +import org.mifospay.core.model.entity.templates.beneficiary.BeneficiaryTemplate +import org.mifospay.core.network.model.CommonResponse + +interface BeneficiaryRepository { + fun getBeneficiaryList(): Flow>> + + fun getBeneficiaryTemplate(): Flow> + + fun createBeneficiary(beneficiaryPayload: BeneficiaryPayload): Flow> + + fun updateBeneficiary( + beneficiaryId: Long, + payload: BeneficiaryUpdatePayload, + ): Flow> + + fun deleteBeneficiary(beneficiaryId: Long): Flow> +} diff --git a/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/ClientRepository.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/ClientRepository.kt new file mode 100644 index 000000000..a9657874e --- /dev/null +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/ClientRepository.kt @@ -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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.repository + +import kotlinx.coroutines.flow.Flow +import org.mifospay.core.common.Result +import org.mifospay.core.model.domain.client.Client +import org.mifospay.core.model.domain.client.NewClient +import org.mifospay.core.model.entity.Page +import org.mifospay.core.model.entity.client.ClientAccounts + +interface ClientRepository { + + suspend fun getClients(): Flow>> + + suspend fun getClient(clientId: Long): Flow> + + suspend fun updateClient(clientId: Long, client: Client): Flow> + + suspend fun getClientImage(clientId: Long): Flow> + + suspend fun updateClientImage(clientId: Long, image: String): Flow> + + suspend fun getClientAccounts(clientId: Long): Flow> + + suspend fun getAccounts(clientId: Long, accountType: String): Flow> + + suspend fun createClient(newClient: NewClient): Flow> +} diff --git a/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/DocumentRepository.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/DocumentRepository.kt new file mode 100644 index 000000000..ec54d64b6 --- /dev/null +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/DocumentRepository.kt @@ -0,0 +1,40 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.repository + +import io.ktor.http.content.PartData +import kotlinx.coroutines.flow.Flow +import org.mifospay.core.common.Result +import org.mifospay.core.model.entity.noncore.Document + +interface DocumentRepository { + fun getDocuments(entityType: String, entityId: Int): Flow>> + + fun createDocument( + entityType: String, + entityId: Int, + name: String, + description: String, + fileName: PartData.FileItem, + ): Flow> + + fun downloadDocument(entityType: String, entityId: Int, documentId: Int): Flow> + + fun deleteDocument(entityType: String, entityId: Int, documentId: Int): Flow> + + fun updateDocument( + entityType: String, + entityId: Int, + documentId: Int, + name: String, + description: String, + fileName: PartData.FileItem, + ): Flow> +} diff --git a/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/InvoiceRepository.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/InvoiceRepository.kt new file mode 100644 index 000000000..63d5affb5 --- /dev/null +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/InvoiceRepository.kt @@ -0,0 +1,31 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.repository + +import kotlinx.coroutines.flow.Flow +import org.mifospay.core.common.Result +import org.mifospay.core.model.entity.Invoice +import org.mifospay.core.network.model.GenericResponse + +interface InvoiceRepository { + suspend fun getInvoice(clientId: Int, invoiceId: Int): Flow> + + suspend fun getInvoices(clientId: Int): Flow>> + + suspend fun createInvoice(clientId: Int, invoice: Invoice): Result + + suspend fun updateInvoice( + clientId: Int, + invoiceId: Int, + invoice: Invoice, + ): Flow> + + suspend fun deleteInvoice(clientId: Int, invoiceId: Int): Flow> +} diff --git a/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/KycLevelRepository.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/KycLevelRepository.kt new file mode 100644 index 000000000..0326045ff --- /dev/null +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/KycLevelRepository.kt @@ -0,0 +1,29 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.repository + +import kotlinx.coroutines.flow.Flow +import org.mifospay.core.common.Result +import org.mifospay.core.model.entity.kyc.KYCLevel1Details +import org.mifospay.core.network.model.GenericResponse + +interface KycLevelRepository { + suspend fun fetchKYCLevel1Details(clientId: Int): Flow>> + + suspend fun addKYCLevel1Details( + clientId: Int, + kycLevel1Details: KYCLevel1Details, + ): Flow> + + suspend fun updateKYCLevel1Details( + clientId: Int, + kycLevel1Details: KYCLevel1Details, + ): Flow> +} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/history/HistoryContract.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/NotificationRepository.kt similarity index 51% rename from core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/history/HistoryContract.kt rename to core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/NotificationRepository.kt index 7d59304ab..30d10ddad 100644 --- a/core/data/src/androidMain/java/org/mifospay/core/data/domain/usecase/history/HistoryContract.kt +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/NotificationRepository.kt @@ -7,12 +7,12 @@ * * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md */ -package org.mifospay.core.data.domain.usecase.history +package org.mifospay.core.data.repository -import com.mifospay.core.model.domain.Transaction +import kotlinx.coroutines.flow.Flow +import org.mifospay.core.common.Result +import org.mifospay.core.model.domain.NotificationPayload -interface HistoryContract { - interface TransactionsHistoryAsync { - fun onTransactionsFetchCompleted(transactions: List?) - } +interface NotificationRepository { + suspend fun fetchNotifications(clientId: Long): Flow>> } diff --git a/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/RegistrationRepository.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/RegistrationRepository.kt new file mode 100644 index 000000000..9cc290d42 --- /dev/null +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/RegistrationRepository.kt @@ -0,0 +1,20 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.repository + +import org.mifospay.core.common.Result +import org.mifospay.core.model.entity.register.RegisterPayload +import org.mifospay.core.model.entity.register.UserVerify + +interface RegistrationRepository { + suspend fun registerUser(registerPayload: RegisterPayload): Result + + suspend fun verifyUser(userVerify: UserVerify): Result +} diff --git a/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/RunReportRepository.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/RunReportRepository.kt new file mode 100644 index 000000000..e2eb96968 --- /dev/null +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/RunReportRepository.kt @@ -0,0 +1,21 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.repository + +import kotlinx.coroutines.flow.Flow +import org.mifospay.core.common.Result +import org.mifospay.core.model.domain.Transaction + +interface RunReportRepository { + suspend fun getTransactionReceipt( + outputType: String, + transactionId: String, + ): Flow> +} diff --git a/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/SavedCardRepository.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/SavedCardRepository.kt new file mode 100644 index 000000000..e2feb9514 --- /dev/null +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/SavedCardRepository.kt @@ -0,0 +1,25 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.repository + +import kotlinx.coroutines.flow.Flow +import org.mifospay.core.common.Result +import org.mifospay.core.model.entity.savedcards.Card +import org.mifospay.core.network.model.GenericResponse + +interface SavedCardRepository { + suspend fun getSavedCards(clientId: Int): Flow>> + + suspend fun addSavedCard(clientId: Int, card: Card): Flow> + + suspend fun deleteCard(clientId: Int, cardId: Int): Flow> + + suspend fun updateCard(clientId: Int, cardId: Int, card: Card): Flow> +} diff --git a/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/SavingsAccountRepository.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/SavingsAccountRepository.kt new file mode 100644 index 000000000..f3a3b70ba --- /dev/null +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/SavingsAccountRepository.kt @@ -0,0 +1,38 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.repository + +import kotlinx.coroutines.flow.Flow +import org.mifospay.core.common.Result +import org.mifospay.core.model.domain.Transaction +import org.mifospay.core.model.entity.Page +import org.mifospay.core.model.entity.accounts.savings.SavingAccount +import org.mifospay.core.model.entity.accounts.savings.SavingsWithAssociationsEntity +import org.mifospay.core.network.model.GenericResponse + +interface SavingsAccountRepository { + suspend fun getSavingsAccounts(limit: Int): Flow>> + + suspend fun getSavingsWithAssociations( + accountId: Long, + associationType: String, + ): Flow> + + suspend fun createSavingsAccount(savingAccount: SavingAccount): Flow> + + suspend fun blockUnblockAccount(accountId: Long, command: String?): Flow> + + suspend fun getSavingAccountTransaction( + accountId: Long, + transactionId: Long, + ): Flow> + + suspend fun payViaMobile(accountId: Long): Flow> +} diff --git a/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/SearchRepository.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/SearchRepository.kt new file mode 100644 index 000000000..bd7ee0656 --- /dev/null +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/SearchRepository.kt @@ -0,0 +1,22 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.repository + +import kotlinx.coroutines.flow.Flow +import org.mifospay.core.common.Result +import org.mifospay.core.model.entity.SearchedEntity + +interface SearchRepository { + suspend fun searchResources( + query: String, + resources: String, + exactMatch: Boolean, + ): Flow>> +} diff --git a/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/SelfServiceRepository.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/SelfServiceRepository.kt new file mode 100644 index 000000000..307bfad04 --- /dev/null +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/SelfServiceRepository.kt @@ -0,0 +1,52 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.repository + +import kotlinx.coroutines.flow.Flow +import org.mifospay.core.common.Result +import org.mifospay.core.model.domain.client.Client +import org.mifospay.core.model.domain.user.User +import org.mifospay.core.model.entity.Page +import org.mifospay.core.model.entity.accounts.savings.SavingsWithAssociationsEntity +import org.mifospay.core.model.entity.accounts.savings.TransactionsEntity +import org.mifospay.core.model.entity.authentication.AuthenticationPayload +import org.mifospay.core.model.entity.beneficary.Beneficiary +import org.mifospay.core.model.entity.beneficary.BeneficiaryPayload +import org.mifospay.core.model.entity.beneficary.BeneficiaryUpdatePayload +import org.mifospay.core.model.entity.client.ClientAccounts +import org.mifospay.core.network.model.CommonResponse + +interface SelfServiceRepository { + suspend fun loginSelf(payload: AuthenticationPayload): Flow> + + suspend fun getSelfClientDetails(clientId: Long): Flow> + + suspend fun getSelfClientDetails(): Flow>> + + suspend fun getSelfAccountTransactions( + accountId: Long, + ): Flow> + + suspend fun getSelfAccountTransactionFromId( + accountId: Long, + transactionId: Long, + ): Flow> + + suspend fun getSelfAccounts(clientId: Long): Flow> + + suspend fun getBeneficiaryList(): Flow>> + + suspend fun createBeneficiary(beneficiaryPayload: BeneficiaryPayload): Flow> + + suspend fun updateBeneficiary( + beneficiaryId: Long, + payload: BeneficiaryUpdatePayload, + ): Flow> +} diff --git a/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/StandingInstructionRepository.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/StandingInstructionRepository.kt new file mode 100644 index 000000000..747e46a88 --- /dev/null +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/StandingInstructionRepository.kt @@ -0,0 +1,37 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.repository + +import kotlinx.coroutines.flow.Flow +import org.mifospay.core.common.Result +import org.mifospay.core.model.entity.Page +import org.mifospay.core.model.entity.payload.StandingInstructionPayload +import org.mifospay.core.model.entity.standinginstruction.SDIResponse +import org.mifospay.core.model.entity.standinginstruction.StandingInstruction +import org.mifospay.core.network.model.GenericResponse + +interface StandingInstructionRepository { + suspend fun getAllStandingInstructions( + clientId: Long, + ): Flow>> + + suspend fun getStandingInstruction(instructionId: Long): Flow> + + suspend fun createStandingInstruction( + payload: StandingInstructionPayload, + ): Flow> + + suspend fun updateStandingInstruction( + instructionId: Long, + payload: StandingInstructionPayload, + ): Flow> + + suspend fun deleteStandingInstruction(instructionId: Long): Flow> +} diff --git a/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/ThirdPartyTransferRepository.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/ThirdPartyTransferRepository.kt new file mode 100644 index 000000000..c7cadf08b --- /dev/null +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/ThirdPartyTransferRepository.kt @@ -0,0 +1,22 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.repository + +import kotlinx.coroutines.flow.Flow +import org.mifospay.core.common.Result +import org.mifospay.core.model.entity.TPTResponse +import org.mifospay.core.model.entity.payload.TransferPayload +import org.mifospay.core.model.entity.templates.account.AccountOptionsTemplate + +interface ThirdPartyTransferRepository { + suspend fun getTransferTemplate(): Flow> + + suspend fun makeTransfer(payload: TransferPayload): Flow> +} diff --git a/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/TwoFactorAuthRepository.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/TwoFactorAuthRepository.kt new file mode 100644 index 000000000..267560b3e --- /dev/null +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/TwoFactorAuthRepository.kt @@ -0,0 +1,23 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.repository + +import kotlinx.coroutines.flow.Flow +import org.mifospay.core.common.Result +import org.mifospay.core.model.domain.twofactor.AccessToken +import org.mifospay.core.model.domain.twofactor.DeliveryMethod + +interface TwoFactorAuthRepository { + suspend fun deliveryMethods(): Flow>> + + suspend fun requestOTP(deliveryMethod: String): Flow> + + suspend fun validateToken(token: String): Flow> +} diff --git a/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/UserRepository.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/UserRepository.kt new file mode 100644 index 000000000..6367b63b2 --- /dev/null +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repository/UserRepository.kt @@ -0,0 +1,29 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.repository + +import kotlinx.coroutines.flow.Flow +import org.mifospay.core.common.Result +import org.mifospay.core.model.domain.user.NewUser +import org.mifospay.core.model.entity.UserWithRole +import org.mifospay.core.network.model.CommonResponse +import org.mifospay.core.network.model.GenericResponse + +interface UserRepository { + fun getUsers(): Flow>> + + fun getUser(): Flow> + + fun createUser(newUser: NewUser): Flow> + + fun updateUser(userId: Int, updatedUser: NewUser): Flow> + + fun deleteUser(userId: Int): Flow> +} diff --git a/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/AccountRepositoryImpl.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/AccountRepositoryImpl.kt new file mode 100644 index 000000000..13230bb62 --- /dev/null +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/AccountRepositoryImpl.kt @@ -0,0 +1,32 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.repositoryImp + +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flowOn +import org.mifospay.core.common.Result +import org.mifospay.core.common.asResult +import org.mifospay.core.data.repository.AccountRepository +import org.mifospay.core.model.entity.accounts.savings.TransferDetail +import org.mifospay.core.network.FineractApiManager + +class AccountRepositoryImpl( + private val apiManager: FineractApiManager, + private val ioDispatcher: CoroutineDispatcher, +) : AccountRepository { + override suspend fun getAccountTransfer(transferId: Long): Flow> { + return apiManager + .accountTransfersApi + .getAccountTransfer(transferId) + .asResult() + .flowOn(ioDispatcher) + } +} diff --git a/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/AuthenticationRepositoryImpl.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/AuthenticationRepositoryImpl.kt new file mode 100644 index 000000000..ee6a28d0a --- /dev/null +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/AuthenticationRepositoryImpl.kt @@ -0,0 +1,29 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.repositoryImp + +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flowOn +import org.mifospay.core.common.Result +import org.mifospay.core.common.asResult +import org.mifospay.core.data.repository.AuthenticationRepository +import org.mifospay.core.model.domain.user.User +import org.mifospay.core.model.entity.authentication.AuthenticationPayload +import org.mifospay.core.network.SelfServiceApiManager + +class AuthenticationRepositoryImpl( + private val apiManager: SelfServiceApiManager, + private val ioDispatcher: CoroutineDispatcher, +) : AuthenticationRepository { + override suspend fun authenticate(payload: AuthenticationPayload): Flow> { + return apiManager.authenticationApi.authenticate(payload).asResult().flowOn(ioDispatcher) + } +} diff --git a/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/BeneficiaryRepositoryImpl.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/BeneficiaryRepositoryImpl.kt new file mode 100644 index 000000000..66f88ba01 --- /dev/null +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/BeneficiaryRepositoryImpl.kt @@ -0,0 +1,60 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.repositoryImp + +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flowOn +import org.mifospay.core.common.Result +import org.mifospay.core.common.asResult +import org.mifospay.core.data.repository.BeneficiaryRepository +import org.mifospay.core.model.entity.beneficary.Beneficiary +import org.mifospay.core.model.entity.beneficary.BeneficiaryPayload +import org.mifospay.core.model.entity.beneficary.BeneficiaryUpdatePayload +import org.mifospay.core.model.entity.templates.beneficiary.BeneficiaryTemplate +import org.mifospay.core.network.SelfServiceApiManager +import org.mifospay.core.network.model.CommonResponse + +class BeneficiaryRepositoryImpl( + private val apiManager: SelfServiceApiManager, + private val ioDispatcher: CoroutineDispatcher, +) : BeneficiaryRepository { + override fun getBeneficiaryList(): Flow>> { + return apiManager.beneficiaryApi.beneficiaryList().asResult().flowOn(ioDispatcher) + } + + override fun getBeneficiaryTemplate(): Flow> { + return apiManager.beneficiaryApi.beneficiaryTemplate().asResult().flowOn(ioDispatcher) + } + + override fun createBeneficiary( + beneficiaryPayload: BeneficiaryPayload, + ): Flow> { + return apiManager + .beneficiaryApi + .createBeneficiary(beneficiaryPayload) + .asResult().flowOn(ioDispatcher) + } + + override fun updateBeneficiary( + beneficiaryId: Long, + payload: BeneficiaryUpdatePayload, + ): Flow> { + return apiManager.beneficiaryApi + .updateBeneficiary(beneficiaryId, payload) + .asResult().flowOn(ioDispatcher) + } + + override fun deleteBeneficiary(beneficiaryId: Long): Flow> { + return apiManager.beneficiaryApi + .deleteBeneficiary(beneficiaryId) + .asResult().flowOn(ioDispatcher) + } +} diff --git a/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/ClientRepositoryImpl.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/ClientRepositoryImpl.kt new file mode 100644 index 000000000..c463bc478 --- /dev/null +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/ClientRepositoryImpl.kt @@ -0,0 +1,78 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.repositoryImp + +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flowOn +import kotlinx.coroutines.flow.map +import org.mifospay.core.common.Result +import org.mifospay.core.common.asResult +import org.mifospay.core.data.mapper.toModel +import org.mifospay.core.data.repository.ClientRepository +import org.mifospay.core.model.domain.client.Client +import org.mifospay.core.model.domain.client.NewClient +import org.mifospay.core.model.entity.Page +import org.mifospay.core.model.entity.client.ClientAccounts +import org.mifospay.core.network.FineractApiManager + +class ClientRepositoryImpl( + private val apiManager: FineractApiManager, + private val ioDispatcher: CoroutineDispatcher, +) : ClientRepository { + override suspend fun getClients(): Flow>> { + return apiManager.clientsApi.clients().map { it.toModel() }.asResult().flowOn(ioDispatcher) + } + + override suspend fun getClient(clientId: Long): Flow> { + return apiManager.clientsApi + .getClientForId(clientId) + .map { it.toModel() } + .asResult().flowOn(ioDispatcher) + } + + override suspend fun updateClient(clientId: Long, client: Client): Flow> { + return apiManager.clientsApi + .updateClient(clientId, client) + .asResult().flowOn(ioDispatcher) + } + + override suspend fun getClientImage(clientId: Long): Flow> { + return apiManager.clientsApi.getClientImage(clientId).asResult().flowOn(ioDispatcher) + } + + override suspend fun updateClientImage(clientId: Long, image: String): Flow> { + return apiManager.clientsApi + .updateClientImage(clientId, image) + .asResult().flowOn(ioDispatcher) + } + + override suspend fun getClientAccounts(clientId: Long): Flow> { + return apiManager.clientsApi + .getClientAccounts(clientId) + .asResult().flowOn(ioDispatcher) + } + + override suspend fun getAccounts( + clientId: Long, + accountType: String, + ): Flow> { + return apiManager.clientsApi + .getAccounts(clientId, accountType) + .asResult().flowOn(ioDispatcher) + } + + override suspend fun createClient(newClient: NewClient): Flow> { + return apiManager.clientsApi + .createClient(newClient) + .map { it.toModel() } + .asResult().flowOn(ioDispatcher) + } +} diff --git a/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/DocumentRepositoryImpl.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/DocumentRepositoryImpl.kt new file mode 100644 index 000000000..38a51d15a --- /dev/null +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/DocumentRepositoryImpl.kt @@ -0,0 +1,77 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.repositoryImp + +import io.ktor.http.content.PartData +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flowOn +import org.mifospay.core.common.Result +import org.mifospay.core.common.asResult +import org.mifospay.core.data.repository.DocumentRepository +import org.mifospay.core.model.entity.noncore.Document +import org.mifospay.core.network.FineractApiManager + +class DocumentRepositoryImpl( + private val apiManager: FineractApiManager, + private val ioDispatcher: CoroutineDispatcher, +) : DocumentRepository { + override fun getDocuments(entityType: String, entityId: Int): Flow>> { + return apiManager.documentApi + .getDocuments(entityType, entityId) + .asResult().flowOn(ioDispatcher) + } + + override fun createDocument( + entityType: String, + entityId: Int, + name: String, + description: String, + fileName: PartData.FileItem, + ): Flow> { + return apiManager.documentApi + .createDocument(entityType, entityId, name, description, fileName) + .asResult().flowOn(ioDispatcher) + } + + override fun downloadDocument( + entityType: String, + entityId: Int, + documentId: Int, + ): Flow> { + return apiManager.documentApi + .downloadDocument(entityType, entityId, documentId) + .asResult().flowOn(ioDispatcher) + } + + override fun deleteDocument( + entityType: String, + entityId: Int, + documentId: Int, + ): Flow> { + return apiManager.documentApi + .removeDocument(entityType, entityId, documentId) + .asResult().flowOn(ioDispatcher) + } + + override fun updateDocument( + entityType: String, + entityId: Int, + documentId: Int, + name: String, + description: String, + fileName: PartData.FileItem, + ): Flow> { + return apiManager.documentApi + .updateDocument(entityType, entityId, documentId, name, description, fileName) + .asResult() + .flowOn(ioDispatcher) + } +} diff --git a/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/InvoiceRepositoryImpl.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/InvoiceRepositoryImpl.kt new file mode 100644 index 000000000..c41461773 --- /dev/null +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/InvoiceRepositoryImpl.kt @@ -0,0 +1,57 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.repositoryImp + +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flowOn +import org.mifospay.core.common.Result +import org.mifospay.core.common.asResult +import org.mifospay.core.data.repository.InvoiceRepository +import org.mifospay.core.model.entity.Invoice +import org.mifospay.core.network.FineractApiManager +import org.mifospay.core.network.model.GenericResponse + +class InvoiceRepositoryImpl( + private val apiManager: FineractApiManager, + private val ioDispatcher: CoroutineDispatcher, +) : InvoiceRepository { + override suspend fun getInvoice(clientId: Int, invoiceId: Int): Flow> { + return apiManager.invoiceApi.getInvoice(clientId, invoiceId).asResult().flowOn(ioDispatcher) + } + + override suspend fun getInvoices(clientId: Int): Flow>> { + return apiManager.invoiceApi.getInvoices(clientId).asResult().flowOn(ioDispatcher) + } + + override suspend fun createInvoice(clientId: Int, invoice: Invoice): Result { + return try { + Result.Success(apiManager.invoiceApi.addInvoice(clientId, invoice)) + } catch (e: Exception) { + Result.Error(e) + } + } + + override suspend fun updateInvoice( + clientId: Int, + invoiceId: Int, + invoice: Invoice, + ): Flow> { + return apiManager.invoiceApi + .updateInvoice(clientId, invoiceId, invoice).asResult() + .flowOn(ioDispatcher) + } + + override suspend fun deleteInvoice(clientId: Int, invoiceId: Int): Flow> { + return apiManager.invoiceApi + .deleteInvoice(clientId, invoiceId).asResult() + .flowOn(ioDispatcher) + } +} diff --git a/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/KycLevelRepositoryImpl.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/KycLevelRepositoryImpl.kt new file mode 100644 index 000000000..32d5ca277 --- /dev/null +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/KycLevelRepositoryImpl.kt @@ -0,0 +1,49 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.repositoryImp + +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flowOn +import org.mifospay.core.common.Result +import org.mifospay.core.common.asResult +import org.mifospay.core.data.repository.KycLevelRepository +import org.mifospay.core.model.entity.kyc.KYCLevel1Details +import org.mifospay.core.network.FineractApiManager +import org.mifospay.core.network.model.GenericResponse + +class KycLevelRepositoryImpl( + private val apiManager: FineractApiManager, + private val ioDispatcher: CoroutineDispatcher, +) : KycLevelRepository { + override suspend fun fetchKYCLevel1Details(clientId: Int): Flow>> { + return apiManager.kycLevel1Api + .fetchKYCLevel1Details(clientId) + .asResult().flowOn(ioDispatcher) + } + + override suspend fun addKYCLevel1Details( + clientId: Int, + kycLevel1Details: KYCLevel1Details, + ): Flow> { + return apiManager.kycLevel1Api + .addKYCLevel1Details(clientId, kycLevel1Details) + .asResult().flowOn(ioDispatcher) + } + + override suspend fun updateKYCLevel1Details( + clientId: Int, + kycLevel1Details: KYCLevel1Details, + ): Flow> { + return apiManager.kycLevel1Api + .updateKYCLevel1Details(clientId, kycLevel1Details) + .asResult().flowOn(ioDispatcher) + } +} diff --git a/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/NotificationRepositoryImpl.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/NotificationRepositoryImpl.kt new file mode 100644 index 000000000..209a3008a --- /dev/null +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/NotificationRepositoryImpl.kt @@ -0,0 +1,32 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.repositoryImp + +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flowOn +import org.mifospay.core.common.Result +import org.mifospay.core.common.asResult +import org.mifospay.core.data.repository.NotificationRepository +import org.mifospay.core.model.domain.NotificationPayload +import org.mifospay.core.network.FineractApiManager + +class NotificationRepositoryImpl( + private val apiManager: FineractApiManager, + private val ioDispatcher: CoroutineDispatcher, +) : NotificationRepository { + override suspend fun fetchNotifications( + clientId: Long, + ): Flow>> { + return apiManager.notificationApi + .fetchNotifications(clientId) + .asResult().flowOn(ioDispatcher) + } +} diff --git a/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/RegistrationRepositoryImpl.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/RegistrationRepositoryImpl.kt new file mode 100644 index 000000000..34c4d11ee --- /dev/null +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/RegistrationRepositoryImpl.kt @@ -0,0 +1,45 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.repositoryImp + +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.withContext +import org.mifospay.core.common.Result +import org.mifospay.core.data.repository.RegistrationRepository +import org.mifospay.core.model.entity.register.RegisterPayload +import org.mifospay.core.model.entity.register.UserVerify +import org.mifospay.core.network.FineractApiManager + +class RegistrationRepositoryImpl( + private val apiManager: FineractApiManager, + private val ioDispatcher: CoroutineDispatcher, +) : RegistrationRepository { + override suspend fun registerUser(registerPayload: RegisterPayload): Result { + return try { + val result = withContext(ioDispatcher) { + apiManager.registrationAPi.registerUser(registerPayload) + } + Result.Success(result) + } catch (e: Exception) { + Result.Error(e) + } + } + + override suspend fun verifyUser(userVerify: UserVerify): Result { + return try { + val result = withContext(ioDispatcher) { + apiManager.registrationAPi.verifyUser(userVerify) + } + Result.Success(result) + } catch (e: Exception) { + Result.Error(e) + } + } +} diff --git a/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/RunReportRepositoryImpl.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/RunReportRepositoryImpl.kt new file mode 100644 index 000000000..f24187988 --- /dev/null +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/RunReportRepositoryImpl.kt @@ -0,0 +1,37 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.repositoryImp + +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flowOn +import kotlinx.coroutines.flow.map +import org.mifospay.core.common.Result +import org.mifospay.core.common.asResult +import org.mifospay.core.data.mapper.toModel +import org.mifospay.core.data.repository.RunReportRepository +import org.mifospay.core.model.domain.Transaction +import org.mifospay.core.network.FineractApiManager + +class RunReportRepositoryImpl( + private val apiManager: FineractApiManager, + private val ioDispatcher: CoroutineDispatcher, +) : RunReportRepository { + override suspend fun getTransactionReceipt( + outputType: String, + transactionId: String, + ): Flow> { + return apiManager.runReportApi + .getTransactionReceipt(outputType, transactionId) + .map { it.toModel() } + .asResult() + .flowOn(ioDispatcher) + } +} diff --git a/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/SavedCardRepositoryImpl.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/SavedCardRepositoryImpl.kt new file mode 100644 index 000000000..3bf8bd19b --- /dev/null +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/SavedCardRepositoryImpl.kt @@ -0,0 +1,47 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.repositoryImp + +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flowOn +import org.mifospay.core.common.Result +import org.mifospay.core.common.asResult +import org.mifospay.core.data.repository.SavedCardRepository +import org.mifospay.core.model.entity.savedcards.Card +import org.mifospay.core.network.FineractApiManager +import org.mifospay.core.network.model.GenericResponse + +class SavedCardRepositoryImpl( + private val apiManager: FineractApiManager, + private val ioDispatcher: CoroutineDispatcher, +) : SavedCardRepository { + override suspend fun getSavedCards(clientId: Int): Flow>> { + return apiManager.savedCardApi.getSavedCards(clientId).asResult().flowOn(ioDispatcher) + } + + override suspend fun addSavedCard(clientId: Int, card: Card): Flow> { + return apiManager.savedCardApi.addSavedCard(clientId, card).asResult().flowOn(ioDispatcher) + } + + override suspend fun deleteCard(clientId: Int, cardId: Int): Flow> { + return apiManager.savedCardApi.deleteCard(clientId, cardId).asResult().flowOn(ioDispatcher) + } + + override suspend fun updateCard( + clientId: Int, + cardId: Int, + card: Card, + ): Flow> { + return apiManager.savedCardApi + .updateCard(clientId, cardId, card) + .asResult().flowOn(ioDispatcher) + } +} diff --git a/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/SavingsAccountRepositoryImpl.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/SavingsAccountRepositoryImpl.kt new file mode 100644 index 000000000..0e450c251 --- /dev/null +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/SavingsAccountRepositoryImpl.kt @@ -0,0 +1,83 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.repositoryImp + +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flowOn +import kotlinx.coroutines.flow.map +import org.mifospay.core.common.Result +import org.mifospay.core.common.asResult +import org.mifospay.core.data.mapper.toModel +import org.mifospay.core.data.repository.SavingsAccountRepository +import org.mifospay.core.model.domain.Transaction +import org.mifospay.core.model.entity.Page +import org.mifospay.core.model.entity.accounts.savings.SavingAccount +import org.mifospay.core.model.entity.accounts.savings.SavingsWithAssociationsEntity +import org.mifospay.core.model.entity.accounts.savings.TransactionsEntity +import org.mifospay.core.network.FineractApiManager +import org.mifospay.core.network.model.GenericResponse + +class SavingsAccountRepositoryImpl( + private val apiManager: FineractApiManager, + private val ioDispatcher: CoroutineDispatcher, +) : SavingsAccountRepository { + override suspend fun getSavingsAccounts( + limit: Int, + ): Flow>> { + return apiManager.savingsAccountsApi + .getSavingsAccounts(limit) + .asResult().flowOn(ioDispatcher) + } + + override suspend fun getSavingsWithAssociations( + accountId: Long, + associationType: String, + ): Flow> { + return apiManager.savingsAccountsApi + .getSavingsWithAssociations(accountId, associationType) + .asResult().flowOn(ioDispatcher) + } + + override suspend fun createSavingsAccount( + savingAccount: SavingAccount, + ): Flow> { + return apiManager.savingsAccountsApi + .createSavingsAccount(savingAccount) + .asResult().flowOn(ioDispatcher) + } + + override suspend fun blockUnblockAccount( + accountId: Long, + command: String?, + ): Flow> { + return apiManager.savingsAccountsApi + .blockUnblockAccount(accountId, command) + .asResult().flowOn(ioDispatcher) + } + + override suspend fun getSavingAccountTransaction( + accountId: Long, + transactionId: Long, + ): Flow> { + return apiManager.savingsAccountsApi + .getSavingAccountTransaction(accountId, transactionId) + .map(TransactionsEntity::toModel) + .asResult() + .flowOn(ioDispatcher) + } + + override suspend fun payViaMobile(accountId: Long): Flow> { + return apiManager.savingsAccountsApi + .payViaMobile(accountId) + .map(TransactionsEntity::toModel) + .asResult().flowOn(ioDispatcher) + } +} diff --git a/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/SearchRepositoryImpl.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/SearchRepositoryImpl.kt new file mode 100644 index 000000000..fc2aa0571 --- /dev/null +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/SearchRepositoryImpl.kt @@ -0,0 +1,34 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.repositoryImp + +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flowOn +import org.mifospay.core.common.Result +import org.mifospay.core.common.asResult +import org.mifospay.core.data.repository.SearchRepository +import org.mifospay.core.model.entity.SearchedEntity +import org.mifospay.core.network.FineractApiManager + +class SearchRepositoryImpl( + private val apiManager: FineractApiManager, + private val ioDispatcher: CoroutineDispatcher, +) : SearchRepository { + override suspend fun searchResources( + query: String, + resources: String, + exactMatch: Boolean, + ): Flow>> { + return apiManager.searchApi + .searchResources(query, resources, exactMatch) + .asResult().flowOn(ioDispatcher) + } +} diff --git a/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/SelfServiceRepositoryImpl.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/SelfServiceRepositoryImpl.kt new file mode 100644 index 000000000..32d33bac5 --- /dev/null +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/SelfServiceRepositoryImpl.kt @@ -0,0 +1,95 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.repositoryImp + +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flowOn +import kotlinx.coroutines.flow.map +import org.mifospay.core.common.Result +import org.mifospay.core.common.asResult +import org.mifospay.core.data.mapper.toModel +import org.mifospay.core.data.repository.SelfServiceRepository +import org.mifospay.core.data.util.Constants +import org.mifospay.core.model.domain.client.Client +import org.mifospay.core.model.domain.user.User +import org.mifospay.core.model.entity.Page +import org.mifospay.core.model.entity.accounts.savings.SavingsWithAssociationsEntity +import org.mifospay.core.model.entity.accounts.savings.TransactionsEntity +import org.mifospay.core.model.entity.authentication.AuthenticationPayload +import org.mifospay.core.model.entity.beneficary.Beneficiary +import org.mifospay.core.model.entity.beneficary.BeneficiaryPayload +import org.mifospay.core.model.entity.beneficary.BeneficiaryUpdatePayload +import org.mifospay.core.model.entity.client.ClientAccounts +import org.mifospay.core.network.SelfServiceApiManager +import org.mifospay.core.network.model.CommonResponse + +class SelfServiceRepositoryImpl( + private val apiManager: SelfServiceApiManager, + private val dispatcher: CoroutineDispatcher, +) : SelfServiceRepository { + + override suspend fun loginSelf(payload: AuthenticationPayload): Flow> { + return apiManager.authenticationApi.authenticate(payload).asResult().flowOn(dispatcher) + } + + override suspend fun getSelfClientDetails(clientId: Long): Flow> { + return apiManager.clientsApi + .getClientForId(clientId) + .map { it.toModel() } + .asResult().flowOn(dispatcher) + } + + override suspend fun getSelfClientDetails(): Flow>> { + return apiManager.clientsApi.clients().map { it.toModel() }.asResult().flowOn(dispatcher) + } + + override suspend fun getSelfAccountTransactions( + accountId: Long, + ): Flow> { + return apiManager.savingAccountsListApi + .getSavingsWithAssociations(accountId, Constants.TRANSACTIONS) + .asResult().flowOn(dispatcher) + } + + override suspend fun getSelfAccountTransactionFromId( + accountId: Long, + transactionId: Long, + ): Flow> { + return apiManager.savingAccountsListApi + .getSavingAccountTransaction(accountId, transactionId) + .asResult().flowOn(dispatcher) + } + + override suspend fun getSelfAccounts(clientId: Long): Flow> { + return apiManager.clientsApi + .getAccounts(clientId, Constants.SAVINGS) + .asResult().flowOn(dispatcher) + } + + override suspend fun getBeneficiaryList(): Flow>> { + return apiManager.beneficiaryApi.beneficiaryList().asResult().flowOn(dispatcher) + } + + override suspend fun createBeneficiary(beneficiaryPayload: BeneficiaryPayload): Flow> { + return apiManager.beneficiaryApi + .createBeneficiary(beneficiaryPayload) + .asResult().flowOn(dispatcher) + } + + override suspend fun updateBeneficiary( + beneficiaryId: Long, + payload: BeneficiaryUpdatePayload, + ): Flow> { + return apiManager.beneficiaryApi + .updateBeneficiary(beneficiaryId, payload) + .asResult().flowOn(dispatcher) + } +} diff --git a/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/StandingInstructionRepositoryImpl.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/StandingInstructionRepositoryImpl.kt new file mode 100644 index 000000000..5693df4c1 --- /dev/null +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/StandingInstructionRepositoryImpl.kt @@ -0,0 +1,69 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.repositoryImp + +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flowOn +import org.mifospay.core.common.Result +import org.mifospay.core.common.asResult +import org.mifospay.core.data.repository.StandingInstructionRepository +import org.mifospay.core.model.entity.Page +import org.mifospay.core.model.entity.payload.StandingInstructionPayload +import org.mifospay.core.model.entity.standinginstruction.SDIResponse +import org.mifospay.core.model.entity.standinginstruction.StandingInstruction +import org.mifospay.core.network.FineractApiManager +import org.mifospay.core.network.model.GenericResponse + +class StandingInstructionRepositoryImpl( + private val apiManager: FineractApiManager, + private val ioDispatcher: CoroutineDispatcher, +) : StandingInstructionRepository { + override suspend fun getAllStandingInstructions( + clientId: Long, + ): Flow>> { + return apiManager.standingInstructionApi + .getAllStandingInstructions(clientId) + .asResult().flowOn(ioDispatcher) + } + + override suspend fun getStandingInstruction( + instructionId: Long, + ): Flow> { + return apiManager.standingInstructionApi + .getStandingInstruction(instructionId) + .asResult().flowOn(ioDispatcher) + } + + override suspend fun createStandingInstruction( + payload: StandingInstructionPayload, + ): Flow> { + return apiManager.standingInstructionApi + .createStandingInstruction(payload) + .asResult().flowOn(ioDispatcher) + } + + override suspend fun updateStandingInstruction( + instructionId: Long, + payload: StandingInstructionPayload, + ): Flow> { + return apiManager.standingInstructionApi + .updateStandingInstruction(instructionId, payload, "update") + .asResult().flowOn(ioDispatcher) + } + + override suspend fun deleteStandingInstruction( + instructionId: Long, + ): Flow> { + return apiManager.standingInstructionApi + .deleteStandingInstruction(instructionId, "delete") + .asResult().flowOn(ioDispatcher) + } +} diff --git a/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/ThirdPartyTransferRepositoryImpl.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/ThirdPartyTransferRepositoryImpl.kt new file mode 100644 index 000000000..8a4b466ce --- /dev/null +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/ThirdPartyTransferRepositoryImpl.kt @@ -0,0 +1,38 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.repositoryImp + +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flowOn +import org.mifospay.core.common.Result +import org.mifospay.core.common.asResult +import org.mifospay.core.data.repository.ThirdPartyTransferRepository +import org.mifospay.core.model.entity.TPTResponse +import org.mifospay.core.model.entity.payload.TransferPayload +import org.mifospay.core.model.entity.templates.account.AccountOptionsTemplate +import org.mifospay.core.network.FineractApiManager + +class ThirdPartyTransferRepositoryImpl( + private val apiManager: FineractApiManager, + private val ioDispatcher: CoroutineDispatcher, +) : ThirdPartyTransferRepository { + override suspend fun getTransferTemplate(): Flow> { + return apiManager.thirdPartyTransferApi + .accountTransferTemplate() + .asResult().flowOn(ioDispatcher) + } + + override suspend fun makeTransfer(payload: TransferPayload): Flow> { + return apiManager.thirdPartyTransferApi + .makeTransfer(payload) + .asResult().flowOn(ioDispatcher) + } +} diff --git a/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/TwoFactorAuthRepositoryImpl.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/TwoFactorAuthRepositoryImpl.kt new file mode 100644 index 000000000..d2342495e --- /dev/null +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/TwoFactorAuthRepositoryImpl.kt @@ -0,0 +1,39 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.repositoryImp + +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flowOn +import org.mifospay.core.common.Result +import org.mifospay.core.common.asResult +import org.mifospay.core.data.repository.TwoFactorAuthRepository +import org.mifospay.core.model.domain.twofactor.AccessToken +import org.mifospay.core.model.domain.twofactor.DeliveryMethod +import org.mifospay.core.network.FineractApiManager + +class TwoFactorAuthRepositoryImpl( + private val apiManager: FineractApiManager, + private val ioDispatcher: CoroutineDispatcher, +) : TwoFactorAuthRepository { + override suspend fun deliveryMethods(): Flow>> { + return apiManager.twoFactorAuthApi.deliveryMethods().asResult().flowOn(ioDispatcher) + } + + override suspend fun requestOTP(deliveryMethod: String): Flow> { + return apiManager.twoFactorAuthApi + .requestOTP(deliveryMethod) + .asResult().flowOn(ioDispatcher) + } + + override suspend fun validateToken(token: String): Flow> { + return apiManager.twoFactorAuthApi.validateToken(token).asResult().flowOn(ioDispatcher) + } +} diff --git a/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/UserRepositoryImpl.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/UserRepositoryImpl.kt new file mode 100644 index 000000000..7cac96cd9 --- /dev/null +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/repositoryImp/UserRepositoryImpl.kt @@ -0,0 +1,47 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data.repositoryImp + +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flowOn +import org.mifospay.core.common.Result +import org.mifospay.core.common.asResult +import org.mifospay.core.data.repository.UserRepository +import org.mifospay.core.model.domain.user.NewUser +import org.mifospay.core.model.entity.UserWithRole +import org.mifospay.core.network.FineractApiManager +import org.mifospay.core.network.model.CommonResponse +import org.mifospay.core.network.model.GenericResponse + +class UserRepositoryImpl( + private val apiManager: FineractApiManager, + private val ioDispatcher: CoroutineDispatcher, +) : UserRepository { + override fun getUsers(): Flow>> { + return apiManager.userApi.users().asResult().flowOn(ioDispatcher) + } + + override fun getUser(): Flow> { + return apiManager.userApi.getUser().asResult().flowOn(ioDispatcher) + } + + override fun createUser(newUser: NewUser): Flow> { + return apiManager.userApi.createUser(newUser).asResult().flowOn(ioDispatcher) + } + + override fun updateUser(userId: Int, updatedUser: NewUser): Flow> { + return apiManager.userApi.updateUser(userId, updatedUser).asResult().flowOn(ioDispatcher) + } + + override fun deleteUser(userId: Int): Flow> { + return apiManager.userApi.deleteUser(userId).asResult().flowOn(ioDispatcher) + } +} diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/util/Constants.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/util/Constants.kt similarity index 92% rename from core/data/src/androidMain/java/org/mifospay/core/data/util/Constants.kt rename to core/data/src/commonMain/kotlin/org/mifospay/core/data/util/Constants.kt index 758c1fb23..669234b76 100644 --- a/core/data/src/androidMain/java/org/mifospay/core/data/util/Constants.kt +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/util/Constants.kt @@ -9,9 +9,6 @@ */ package org.mifospay.core.data.util -import java.util.Arrays -import java.util.Collections - object Constants { const val BASIC = "Basic " const val SAVINGS = "savingsAccounts" @@ -22,10 +19,7 @@ object Constants { private const val MOBILE_WALLET_ROLE_ID = 471 private const val SUPER_USER_ROLE_ID = 1 - @JvmField - val NEW_USER_ROLE_IDS: Collection = Collections.unmodifiableList( - Arrays.asList(MOBILE_WALLET_ROLE_ID, SUPER_USER_ROLE_ID), - ) + val NEW_USER_ROLE_IDS: List = listOf(MOBILE_WALLET_ROLE_ID, SUPER_USER_ROLE_ID) const val ENTITY_TYPE_CLIENTS = "clients" const val FETCH_ACCOUNT_TRANSFER_USECASE = "FetchAccountTransfer" const val NO_SAVED_CARDS = "No saved cards." diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/util/NetworkMonitor.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/util/NetworkMonitor.kt similarity index 100% rename from core/data/src/androidMain/java/org/mifospay/core/data/util/NetworkMonitor.kt rename to core/data/src/commonMain/kotlin/org/mifospay/core/data/util/NetworkMonitor.kt diff --git a/core/data/src/androidMain/java/org/mifospay/core/data/repository/local/LocalAssetRepository.kt b/core/data/src/commonMain/kotlin/org/mifospay/core/data/util/TimeZoneMonitor.kt similarity index 50% rename from core/data/src/androidMain/java/org/mifospay/core/data/repository/local/LocalAssetRepository.kt rename to core/data/src/commonMain/kotlin/org/mifospay/core/data/util/TimeZoneMonitor.kt index 4ed5c49d0..bea88a147 100644 --- a/core/data/src/androidMain/java/org/mifospay/core/data/repository/local/LocalAssetRepository.kt +++ b/core/data/src/commonMain/kotlin/org/mifospay/core/data/util/TimeZoneMonitor.kt @@ -7,20 +7,16 @@ * * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md */ -package org.mifospay.core.data.repository.local +package org.mifospay.core.data.util -import com.mifospay.core.model.City -import com.mifospay.core.model.Country -import com.mifospay.core.model.State import kotlinx.coroutines.flow.Flow +import kotlinx.datetime.TimeZone -interface LocalAssetRepository { - - fun getCountries(): Flow> - - fun getStateList(): Flow> - - fun getBanks(): Flow> +/** + * Utility for reporting current timezone the device has set. + * It always emits at least once with default setting and then for each TZ change. + */ - fun getCities(): Flow> +interface TimeZoneMonitor { + val currentTimeZone: Flow } diff --git a/core/data/src/jvmMain/kotlin/org/mifospay/core/data/JvmPlatformDependentDataModule.kt b/core/data/src/jvmMain/kotlin/org/mifospay/core/data/JvmPlatformDependentDataModule.kt new file mode 100644 index 000000000..ba5672f7e --- /dev/null +++ b/core/data/src/jvmMain/kotlin/org/mifospay/core/data/JvmPlatformDependentDataModule.kt @@ -0,0 +1,33 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data + +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flowOf +import kotlinx.datetime.TimeZone +import org.mifospay.core.data.di.PlatformDependentDataModule +import org.mifospay.core.data.util.NetworkMonitor +import org.mifospay.core.data.util.TimeZoneMonitor + +class JvmPlatformDependentDataModule : PlatformDependentDataModule() { + override fun bindsNetworkMonitor(): NetworkMonitor { + return object : NetworkMonitor { + override val isOnline: Flow + get() = flowOf(true) + } + } + + override fun bindsTimeZoneMonitor(): TimeZoneMonitor { + return object : TimeZoneMonitor { + override val currentTimeZone: Flow + get() = flowOf(TimeZone.currentSystemDefault()) + } + } +} diff --git a/core/data/src/nativeMain/kotlin/org/mifospay/core/data/NativePlatformDependentDataModule.kt b/core/data/src/nativeMain/kotlin/org/mifospay/core/data/NativePlatformDependentDataModule.kt new file mode 100644 index 000000000..e02565f39 --- /dev/null +++ b/core/data/src/nativeMain/kotlin/org/mifospay/core/data/NativePlatformDependentDataModule.kt @@ -0,0 +1,33 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.data + +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flowOf +import kotlinx.datetime.TimeZone +import org.mifospay.core.data.di.PlatformDependentDataModule +import org.mifospay.core.data.util.NetworkMonitor +import org.mifospay.core.data.util.TimeZoneMonitor + +class NativePlatformDependentDataModule : PlatformDependentDataModule() { + override fun bindsNetworkMonitor(): NetworkMonitor { + return object : NetworkMonitor { + override val isOnline: Flow + get() = flowOf(true) + } + } + + override fun bindsTimeZoneMonitor(): TimeZoneMonitor { + return object : TimeZoneMonitor { + override val currentTimeZone: Flow + get() = flowOf(TimeZone.currentSystemDefault()) + } + } +} diff --git a/core/datastore-proto/src/commonMain/kotlin/org/mifospay/core/datastore/proto/ClientPreferences.kt b/core/datastore-proto/src/commonMain/kotlin/org/mifospay/core/datastore/proto/ClientPreferences.kt index f3d4a9bf3..4d5edcf1b 100644 --- a/core/datastore-proto/src/commonMain/kotlin/org/mifospay/core/datastore/proto/ClientPreferences.kt +++ b/core/datastore-proto/src/commonMain/kotlin/org/mifospay/core/datastore/proto/ClientPreferences.kt @@ -1,3 +1,12 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.datastore.proto import kotlinx.serialization.Serializable @@ -21,4 +30,4 @@ data class ClientPreferences( mobileNo = "", ) } -} \ No newline at end of file +} diff --git a/core/datastore-proto/src/commonMain/kotlin/org/mifospay/core/datastore/proto/RolePreferences.kt b/core/datastore-proto/src/commonMain/kotlin/org/mifospay/core/datastore/proto/RolePreferences.kt index 5568d8e46..17269b376 100644 --- a/core/datastore-proto/src/commonMain/kotlin/org/mifospay/core/datastore/proto/RolePreferences.kt +++ b/core/datastore-proto/src/commonMain/kotlin/org/mifospay/core/datastore/proto/RolePreferences.kt @@ -1,3 +1,12 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.datastore.proto import kotlinx.serialization.Serializable @@ -7,14 +16,14 @@ data class RolePreferences( val id: String, val name: String, val description: String, - val disabled: Boolean + val disabled: Boolean, ) { companion object { val DEFAULT = RolePreferences( id = "", name = "", description = "", - disabled = false + disabled = false, ) } } diff --git a/core/datastore-proto/src/commonMain/kotlin/org/mifospay/core/datastore/proto/UserInfoPreferences.kt b/core/datastore-proto/src/commonMain/kotlin/org/mifospay/core/datastore/proto/UserInfoPreferences.kt index 179ca3c3b..af951f03b 100644 --- a/core/datastore-proto/src/commonMain/kotlin/org/mifospay/core/datastore/proto/UserInfoPreferences.kt +++ b/core/datastore-proto/src/commonMain/kotlin/org/mifospay/core/datastore/proto/UserInfoPreferences.kt @@ -1,3 +1,12 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.datastore.proto import kotlinx.serialization.Serializable @@ -14,7 +23,7 @@ data class UserInfoPreferences( val permissions: List, val clients: List, val shouldRenewPassword: Boolean, - val isTwoFactorAuthenticationRequired: Boolean + val isTwoFactorAuthenticationRequired: Boolean, ) { companion object { val DEFAULT = UserInfoPreferences( @@ -28,7 +37,7 @@ data class UserInfoPreferences( permissions = emptyList(), clients = emptyList(), shouldRenewPassword = false, - isTwoFactorAuthenticationRequired = false + isTwoFactorAuthenticationRequired = false, ) } } diff --git a/core/datastore-proto/src/commonMain/kotlin/org/mifospay/core/datastore/proto/UserPreferences.kt b/core/datastore-proto/src/commonMain/kotlin/org/mifospay/core/datastore/proto/UserPreferences.kt index 07113fc78..91d76ef11 100644 --- a/core/datastore-proto/src/commonMain/kotlin/org/mifospay/core/datastore/proto/UserPreferences.kt +++ b/core/datastore-proto/src/commonMain/kotlin/org/mifospay/core/datastore/proto/UserPreferences.kt @@ -1,3 +1,12 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ package org.mifospay.core.datastore.proto import kotlinx.serialization.Serializable diff --git a/core/model/src/commonMain/kotlin/org/mifospay/core/model/domain/client/Client.kt b/core/model/src/commonMain/kotlin/org/mifospay/core/model/domain/client/Client.kt index 01e0c5e2e..00eb538fe 100644 --- a/core/model/src/commonMain/kotlin/org/mifospay/core/model/domain/client/Client.kt +++ b/core/model/src/commonMain/kotlin/org/mifospay/core/model/domain/client/Client.kt @@ -14,18 +14,9 @@ import kotlinx.serialization.Serializable @Serializable data class Client( val name: String? = null, - val image: String, + val image: String? = null, val externalId: String? = null, val clientId: Long = 0L, - val displayName: String, - val mobileNo: String, -) { - constructor() : this( - name = "", - image = "", - externalId = "", - clientId = 0L, - displayName = "", - mobileNo = "", - ) -} + val displayName: String? = null, + val mobileNo: String? = null, +) \ No newline at end of file diff --git a/core/model/src/commonMain/kotlin/org/mifospay/core/model/entity/accounts/savings/PaymentType.kt b/core/model/src/commonMain/kotlin/org/mifospay/core/model/entity/accounts/savings/PaymentType.kt index cd19f5e89..3318b0fb9 100644 --- a/core/model/src/commonMain/kotlin/org/mifospay/core/model/entity/accounts/savings/PaymentType.kt +++ b/core/model/src/commonMain/kotlin/org/mifospay/core/model/entity/accounts/savings/PaymentType.kt @@ -15,4 +15,5 @@ import kotlinx.serialization.Serializable data class PaymentType( val id: Int? = null, val name: String? = null, + val isSystemDefined: Boolean, ) diff --git a/core/model/src/commonMain/kotlin/org/mifospay/core/model/entity/accounts/savings/SavingsWithAssociations.kt b/core/model/src/commonMain/kotlin/org/mifospay/core/model/entity/accounts/savings/SavingsWithAssociationsEntity.kt similarity index 64% rename from core/model/src/commonMain/kotlin/org/mifospay/core/model/entity/accounts/savings/SavingsWithAssociations.kt rename to core/model/src/commonMain/kotlin/org/mifospay/core/model/entity/accounts/savings/SavingsWithAssociationsEntity.kt index ae8e2b0fc..5e4f55c7c 100644 --- a/core/model/src/commonMain/kotlin/org/mifospay/core/model/entity/accounts/savings/SavingsWithAssociations.kt +++ b/core/model/src/commonMain/kotlin/org/mifospay/core/model/entity/accounts/savings/SavingsWithAssociationsEntity.kt @@ -14,7 +14,7 @@ import kotlinx.serialization.Serializable import org.mifospay.core.model.entity.client.DepositType @Serializable -data class SavingsWithAssociations( +data class SavingsWithAssociationsEntity( val id: Long = 0L, val accountNo: String? = null, val depositType: DepositType? = null, @@ -38,30 +38,5 @@ data class SavingsWithAssociations( @SerialName("isDormancyTrackingActive") val dormancyTrackingActive: Boolean? = null, val summary: Summary? = null, - val transactions: List = ArrayList(), -) { - constructor() : this( - id = 0L, - accountNo = null, - depositType = null, - externalId = "", - clientId = 0, - clientName = "", - savingsProductId = null, - savingsProductName = null, - fieldOfficerId = 0, - status = null, - timeline = null, - currency = null, - nominalAnnualInterestRate = null, - minRequiredOpeningBalance = null, - lockinPeriodFrequency = 0.0, - withdrawalFeeForTransfers = false, - allowOverdraft = false, - enforceMinRequiredBalance = false, - withHoldTax = null, - lastActiveTransactionDate = listOf(), - dormancyTrackingActive = null, - summary = null, - ) -} + val transactions: List = ArrayList(), +) diff --git a/core/model/src/commonMain/kotlin/org/mifospay/core/model/entity/accounts/savings/TransactionType.kt b/core/model/src/commonMain/kotlin/org/mifospay/core/model/entity/accounts/savings/TransactionType.kt index 532a91c42..baed86912 100644 --- a/core/model/src/commonMain/kotlin/org/mifospay/core/model/entity/accounts/savings/TransactionType.kt +++ b/core/model/src/commonMain/kotlin/org/mifospay/core/model/entity/accounts/savings/TransactionType.kt @@ -30,4 +30,6 @@ data class TransactionType( val overdraftFee: Boolean = false, val withholdTax: Boolean = false, val escheat: Boolean? = null, -) + val amountHold: Boolean = false, + val amountRelease: Boolean = false, +) \ No newline at end of file diff --git a/core/model/src/commonMain/kotlin/org/mifospay/core/model/entity/accounts/savings/Transactions.kt b/core/model/src/commonMain/kotlin/org/mifospay/core/model/entity/accounts/savings/TransactionsEntity.kt similarity index 64% rename from core/model/src/commonMain/kotlin/org/mifospay/core/model/entity/accounts/savings/Transactions.kt rename to core/model/src/commonMain/kotlin/org/mifospay/core/model/entity/accounts/savings/TransactionsEntity.kt index 00db6abea..45c081985 100644 --- a/core/model/src/commonMain/kotlin/org/mifospay/core/model/entity/accounts/savings/Transactions.kt +++ b/core/model/src/commonMain/kotlin/org/mifospay/core/model/entity/accounts/savings/TransactionsEntity.kt @@ -12,8 +12,9 @@ package org.mifospay.core.model.entity.accounts.savings import kotlinx.serialization.Serializable @Serializable -data class Transactions( +data class TransactionsEntity( val id: Int? = null, + val entryType: String? = null, val transactionType: TransactionType = TransactionType(), val accountId: Int? = null, val accountNo: String? = null, @@ -21,25 +22,14 @@ data class Transactions( val currency: Currency = Currency(), val paymentDetailData: PaymentDetailData? = null, val amount: Double = 0.0, - val transfer: Transfer = Transfer(), val runningBalance: Double? = null, val reversed: Boolean? = null, val submittedOnDate: List = ArrayList(), val interestedPostedAsOn: Boolean? = null, -) { - constructor() : this( - id = 0, - transactionType = TransactionType(), - accountId = 0, - accountNo = "", - date = ArrayList(), - currency = Currency(), - paymentDetailData = PaymentDetailData(), - amount = 0.0, - transfer = Transfer(), - runningBalance = 0.0, - reversed = false, - submittedOnDate = ArrayList(), - interestedPostedAsOn = false, - ) -} + val submittedByUsername: String? = null, + val isManualTransaction: Boolean = false, + val isReversal: Boolean = false, + val originalTransactionId: Long? = null, + val lienTransaction: Boolean = false, + val releaseTransactionId: Long? = null, +) \ No newline at end of file diff --git a/core/model/src/commonMain/kotlin/org/mifospay/core/model/entity/client/Client.kt b/core/model/src/commonMain/kotlin/org/mifospay/core/model/entity/client/ClientEntity.kt similarity index 68% rename from core/model/src/commonMain/kotlin/org/mifospay/core/model/entity/client/Client.kt rename to core/model/src/commonMain/kotlin/org/mifospay/core/model/entity/client/ClientEntity.kt index 5d5cd3922..a0e9915b2 100644 --- a/core/model/src/commonMain/kotlin/org/mifospay/core/model/entity/client/Client.kt +++ b/core/model/src/commonMain/kotlin/org/mifospay/core/model/entity/client/ClientEntity.kt @@ -14,7 +14,7 @@ import kotlinx.serialization.Serializable import org.mifospay.core.model.entity.Timeline @Serializable -data class Client( +data class ClientEntity( val id: Int = 0, val accountNo: String? = null, val status: Status? = null, @@ -36,27 +36,4 @@ data class Client( val isImagePresent: Boolean = false, val externalId: String = "", val mobileNo: String = "", -) { - constructor() : this( - id = 0, - accountNo = "", - status = Status(), - active = false, - activationDate = ArrayList(), - dobDate = ArrayList(), - firstname = "", - middlename = "", - lastname = "", - displayName = "", - fullname = "", - officeId = 0, - officeName = "", - staffId = 0, - staffName = "", - timeline = Timeline(), - imageId = 0, - isImagePresent = false, - externalId = "", - mobileNo = "", - ) -} +) diff --git a/core/model/src/commonMain/kotlin/org/mifospay/core/model/entity/standinginstruction/StandingInstruction.kt b/core/model/src/commonMain/kotlin/org/mifospay/core/model/entity/standinginstruction/StandingInstruction.kt index 6d9edad60..874762bcd 100644 --- a/core/model/src/commonMain/kotlin/org/mifospay/core/model/entity/standinginstruction/StandingInstruction.kt +++ b/core/model/src/commonMain/kotlin/org/mifospay/core/model/entity/standinginstruction/StandingInstruction.kt @@ -11,16 +11,16 @@ package org.mifospay.core.model.entity.standinginstruction import kotlinx.serialization.Serializable import org.mifospay.core.model.entity.accounts.savings.SavingAccount -import org.mifospay.core.model.entity.client.Client +import org.mifospay.core.model.entity.client.ClientEntity import org.mifospay.core.model.entity.client.Status @Serializable data class StandingInstruction( val id: Long, val name: String, - val fromClient: Client, + val fromClient: ClientEntity, val fromAccount: SavingAccount, - val toClient: Client, + val toClient: ClientEntity, val toAccount: SavingAccount, val status: Status, val amount: Double, diff --git a/core/network/build.gradle.kts b/core/network/build.gradle.kts index f4f2243dd..68ba5e7bb 100644 --- a/core/network/build.gradle.kts +++ b/core/network/build.gradle.kts @@ -19,6 +19,7 @@ */ plugins { alias(libs.plugins.mifospay.kmp.library) + alias(libs.plugins.mifospay.kotlin.inject) alias(libs.plugins.ktrofit) id("kotlinx-serialization") id("com.google.devtools.ksp") @@ -49,10 +50,13 @@ kotlin { implementation(libs.ktor.client.logging) implementation(libs.ktor.client.serialization) implementation(libs.ktor.client.content.negotiation) + implementation(libs.ktor.client.auth) + implementation(libs.ktor.client.cio) implementation(libs.ktor.serialization.kotlinx.json) implementation(libs.ktorfit.lib) implementation(libs.ktorfit.converters.call) implementation(libs.ktorfit.converters.flow) + implementation(libs.squareup.okio) } androidMain.dependencies { implementation(libs.ktor.client.android) diff --git a/core/network/src/androidMain/kotlin/org/mifospay/core/network/ApiInterceptor.kt b/core/network/src/androidMain/kotlin/org/mifospay/core/network/ApiInterceptor.kt deleted file mode 100644 index 26d2511d6..000000000 --- a/core/network/src/androidMain/kotlin/org/mifospay/core/network/ApiInterceptor.kt +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.network - -import okhttp3.Interceptor -import okhttp3.Response -import org.mifospay.core.datastore.PreferencesHelper -import java.io.IOException - -class ApiInterceptor(private val preferencesHelper: PreferencesHelper) : Interceptor { - - @Throws(IOException::class) - override fun intercept(chain: Interceptor.Chain): Response { - val chainRequest = chain.request() - val builder = chainRequest.newBuilder().header( - HEADER_TENANT, - DEFAULT, - ) - val authToken = preferencesHelper.token - if (!authToken.isNullOrEmpty()) { - builder.header(HEADER_AUTH, authToken) - } - val request = builder.build() - return chain.proceed(request) - } - - companion object { - const val HEADER_TENANT = "Fineract-Platform-TenantId" - const val HEADER_AUTH = "Authorization" - const val DEFAULT = "venus" - } -} diff --git a/core/network/src/androidMain/kotlin/org/mifospay/core/network/JvmLocalAssetManager.kt b/core/network/src/androidMain/kotlin/org/mifospay/core/network/JvmLocalAssetManager.kt deleted file mode 100644 index 37cc92891..000000000 --- a/core/network/src/androidMain/kotlin/org/mifospay/core/network/JvmLocalAssetManager.kt +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.network - -import androidx.annotation.VisibleForTesting -import org.mifospay.core.network.localAssets.LocalAssetManager -import java.io.File -import java.io.InputStream - -/** - * This class helps with loading Android `/assets` files, especially when running JVM unit tests. - * It must remain on the root package for an easier [Class.getResource] with relative paths. - * @see https://developer.android.com/reference/tools/gradle-api/7.3/com/android/build/api/dsl/UnitTestOptions - */ - -@VisibleForTesting -internal object JvmLocalAssetManager : LocalAssetManager { -// private val config = -// requireNotNull(javaClass.getResource("com/android/tools/test_config.properties")) { -// """ -// Missing Android resources properties file. -// Did you forget to enable the feature in the gradle build file? -// android.testOptions.unitTests.isIncludeAndroidResources = true -// """.trimIndent() -// } -// private val properties = Properties().apply { config.openStream().use(::load) } -// private val assets = File(properties["android_merged_assets"].toString()) - - override fun open(fileName: String): InputStream = File(fileName).inputStream() -} diff --git a/core/network/src/androidMain/kotlin/org/mifospay/core/network/KtorInterceptor.kt b/core/network/src/androidMain/kotlin/org/mifospay/core/network/KtorInterceptor.kt deleted file mode 100644 index 5a5fd156f..000000000 --- a/core/network/src/androidMain/kotlin/org/mifospay/core/network/KtorInterceptor.kt +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.network - -import io.ktor.client.HttpClient -import io.ktor.client.plugins.HttpClientPlugin -import io.ktor.client.request.HttpRequestPipeline -import io.ktor.client.request.header -import io.ktor.util.AttributeKey -import org.mifospay.core.datastore.PreferencesHelper - -class KtorInterceptor( - private val preferencesHelper: PreferencesHelper, -) { - class Config { - lateinit var preferencesHelper: PreferencesHelper - } - - companion object Plugin : HttpClientPlugin { - const val HEADER_TENANT = "Fineract-Platform-TenantId" - const val HEADER_AUTH = "Authorization" - const val DEFAULT = "venus" - - override val key: AttributeKey = AttributeKey("KtorInterceptor") - - override fun install(plugin: KtorInterceptor, scope: HttpClient) { - scope.requestPipeline.intercept(HttpRequestPipeline.State) { - val authToken = plugin.preferencesHelper.token - context.header(HEADER_TENANT, DEFAULT) - if (!authToken.isNullOrEmpty()) { - context.header(HEADER_AUTH, authToken) - } - } - } - - override fun prepare(block: Config.() -> Unit): KtorInterceptor { - val config = Config().apply(block) - return KtorInterceptor(config.preferencesHelper) - } - } -} diff --git a/core/network/src/androidMain/kotlin/org/mifospay/core/network/MifosWalletOkHttpClient.kt b/core/network/src/androidMain/kotlin/org/mifospay/core/network/MifosWalletOkHttpClient.kt deleted file mode 100644 index b2fd7bafd..000000000 --- a/core/network/src/androidMain/kotlin/org/mifospay/core/network/MifosWalletOkHttpClient.kt +++ /dev/null @@ -1,84 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.network - -import okhttp3.OkHttpClient -import okhttp3.logging.HttpLoggingInterceptor -import org.mifospay.core.datastore.PreferencesHelper -import java.security.SecureRandom -import java.security.cert.CertificateException -import java.security.cert.X509Certificate -import java.util.concurrent.TimeUnit -import javax.net.ssl.SSLContext -import javax.net.ssl.TrustManager -import javax.net.ssl.X509TrustManager - -class MifosWalletOkHttpClient(private val preferences: PreferencesHelper) { - // Create a trust manager that does not validate certificate chains - val mifosOkHttpClient: OkHttpClient - // Interceptor :> Full Body Logger and ApiRequest Header - get() { - val builder = OkHttpClient.Builder() - try { - // Create a trust manager that does not validate certificate chains - val trustAllCerts = arrayOf( - object : X509TrustManager { - @Throws(CertificateException::class) - override fun checkClientTrusted( - chain: Array, - authType: String, - ) { - } - - @Throws(CertificateException::class) - override fun checkServerTrusted( - chain: Array, - authType: String, - ) { - } - - override fun getAcceptedIssuers(): Array { - return emptyArray() - } - }, - ) - - // Install the all-trusting trust manager - val sslContext = SSLContext.getInstance("SSL") - sslContext.init(null, trustAllCerts, SecureRandom()) - // Create an ssl socket factory with our all-trusting manager - val sslSocketFactory = sslContext.socketFactory - - // Enable Full Body Logging - val logger = HttpLoggingInterceptor() - logger.level = HttpLoggingInterceptor.Level.BODY - - // Set SSL certificate to OkHttpClient Builder -// builder.sslSocketFactory(sslSocketFactory) - builder.sslSocketFactory(sslSocketFactory, trustAllCerts[0] as X509TrustManager) - builder.hostnameVerifier { _, _ -> true } - } catch (e: Exception) { - throw RuntimeException(e) - } - - // Enable Full Body Logging - val logger = HttpLoggingInterceptor() - logger.level = HttpLoggingInterceptor.Level.BODY - - // Setting Timeout 30 Seconds - builder.connectTimeout(60, TimeUnit.SECONDS) - builder.readTimeout(60, TimeUnit.SECONDS) - - // Interceptor :> Full Body Logger and ApiRequest Header - builder.addInterceptor(logger) - builder.addInterceptor(ApiInterceptor(preferences)) - return builder.build() - } -} diff --git a/core/network/src/androidMain/kotlin/org/mifospay/core/network/di/NetworkModule.kt b/core/network/src/androidMain/kotlin/org/mifospay/core/network/di/NetworkModule.kt deleted file mode 100644 index 639d5623c..000000000 --- a/core/network/src/androidMain/kotlin/org/mifospay/core/network/di/NetworkModule.kt +++ /dev/null @@ -1,233 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.network.di - -import io.ktor.client.HttpClient -import io.ktor.client.engine.android.Android -import io.ktor.client.plugins.HttpTimeout -import io.ktor.client.plugins.contentnegotiation.ContentNegotiation -import io.ktor.client.plugins.logging.LogLevel -import io.ktor.client.plugins.logging.Logging -import io.ktor.client.plugins.websocket.WebSockets -import io.ktor.serialization.kotlinx.json.json -import kotlinx.serialization.json.Json -import org.koin.dsl.module -import org.mifospay.core.datastore.PreferencesHelper -import org.mifospay.core.network.BaseURL -import org.mifospay.core.network.FineractApiManager -import org.mifospay.core.network.KtorInterceptor -import org.mifospay.core.network.MifosWalletOkHttpClient -import org.mifospay.core.network.SelfServiceApiManager -import org.mifospay.core.network.services.AccountTransfersService -import org.mifospay.core.network.services.AuthenticationService -import org.mifospay.core.network.services.BeneficiaryService -import org.mifospay.core.network.services.ClientService -import org.mifospay.core.network.services.DocumentService -import org.mifospay.core.network.services.InvoiceService -import org.mifospay.core.network.services.KYCLevel1Service -import org.mifospay.core.network.services.KtorAuthenticationService -import org.mifospay.core.network.services.KtorSavingsAccountService -import org.mifospay.core.network.services.NotificationService -import org.mifospay.core.network.services.RegistrationService -import org.mifospay.core.network.services.RunReportService -import org.mifospay.core.network.services.SavedCardService -import org.mifospay.core.network.services.SavingsAccountsService -import org.mifospay.core.network.services.SearchService -import org.mifospay.core.network.services.StandingInstructionService -import org.mifospay.core.network.services.ThirdPartyTransferService -import org.mifospay.core.network.services.TwoFactorAuthService -import org.mifospay.core.network.services.UserService -import retrofit2.Retrofit -import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory -import retrofit2.converter.gson.GsonConverterFactory - -@Suppress("TooManyFunctions") -val NetworkModule = module { - - single { - Json { - ignoreUnknownKeys = true - } - } - - single(SelfServiceApi) { - val preferencesHelper: PreferencesHelper = get() - Retrofit.Builder() - .baseUrl(BaseURL().selfServiceUrl) - .addConverterFactory(GsonConverterFactory.create()) - .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) - .client(MifosWalletOkHttpClient(preferencesHelper).mifosOkHttpClient) - .build() - } - - single(FineractApi) { - val preferencesHelper: PreferencesHelper = get() - Retrofit.Builder() - .baseUrl(BaseURL().url) - .addConverterFactory(GsonConverterFactory.create()) - .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) - .client(MifosWalletOkHttpClient(preferencesHelper).mifosOkHttpClient) - .build() - } - - single { - FineractApiManager( - authenticationService = get(FineractAuthenticationService), - clientService = get(FineractClientService), - savingsAccountsService = get(FineractSavingsAccountsService), - registrationService = get(FineractRegistrationService), - searchService = get(), - documentService = get(), - runReportService = get(), - twoFactorAuthService = get(), - accountTransfersService = get(), - savedCardService = get(), - kYCLevel1Service = get(), - invoiceService = get(), - userService = get(), - thirdPartyTransferService = get(FineractThirdPartyTransferService), - standingInstructionService = get(), - notificationService = get(), - ktorSavingsAccountService = get(), - ) - } - - single { - SelfServiceApiManager( - authenticationService = get(SelfServiceAuthenticationService), - clientService = get(SelfServiceClientService), - savingsAccountsService = get(SelfServiceSavingsAccountsService), - registrationService = get(SelfServiceRegistrationService), - beneficiaryService = get(), - thirdPartyTransferService = get(SelfServiceThirdPartyTransferService), - ktorSavingsAccountService = get(), - ) - } - -// Http client for Ktor - - single { - HttpClient(Android) { - install(WebSockets) - install(KtorInterceptor) { - this.preferencesHelper = get() - } - install(ContentNegotiation) { - json( - Json { - ignoreUnknownKeys = true - isLenient = true - }, - ) - } - install(HttpTimeout) { - requestTimeoutMillis = 15000 - } - install(Logging) { - level = LogLevel.ALL - } - } - } - - single { KtorAuthenticationService(client = get()) } - single { KtorSavingsAccountService(client = get()) } - - // -----Fineract API Service---------// - - single(FineractAuthenticationService) { - get(FineractApi).create(AuthenticationService::class.java) - } - - single(FineractClientService) { - get(FineractApi).create(ClientService::class.java) - } - - single(FineractSavingsAccountsService) { - get(FineractApi).create(SavingsAccountsService::class.java) - } - - single(FineractRegistrationService) { - get(FineractApi).create(RegistrationService::class.java) - } - - single { - get(FineractApi).create(SearchService::class.java) - } - - single { - get(FineractApi).create(SavedCardService::class.java) - } - - single { - get(FineractApi).create(DocumentService::class.java) - } - - single { - get(FineractApi).create(TwoFactorAuthService::class.java) - } - - single { - get(FineractApi).create(AccountTransfersService::class.java) - } - - single { - get(FineractApi).create(RunReportService::class.java) - } - - single { - get(FineractApi).create(KYCLevel1Service::class.java) - } - - single { - get(FineractApi).create(InvoiceService::class.java) - } - - single { - get(FineractApi).create(UserService::class.java) - } - - single(FineractThirdPartyTransferService) { - get(FineractApi).create(ThirdPartyTransferService::class.java) - } - - single { - get(FineractApi).create(NotificationService::class.java) - } - - single { - get(FineractApi).create(StandingInstructionService::class.java) - } - - // -------SelfService API Service-------// - - single(SelfServiceAuthenticationService) { - get(SelfServiceApi).create(AuthenticationService::class.java) - } - - single(SelfServiceClientService) { - get(SelfServiceApi).create(ClientService::class.java) - } - - single(SelfServiceSavingsAccountsService) { - get(SelfServiceApi).create(SavingsAccountsService::class.java) - } - - single(SelfServiceRegistrationService) { - get(SelfServiceApi).create(RegistrationService::class.java) - } - - single { - get(SelfServiceApi).create(BeneficiaryService::class.java) - } - - single(SelfServiceThirdPartyTransferService) { - get(SelfServiceApi).create(ThirdPartyTransferService::class.java) - } -} diff --git a/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/ClientService.kt b/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/ClientService.kt deleted file mode 100644 index 02f7511f3..000000000 --- a/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/ClientService.kt +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.network.services - -import com.mifospay.core.model.domain.NewAccount -import com.mifospay.core.model.entity.Page -import com.mifospay.core.model.entity.client.Client -import com.mifospay.core.model.entity.client.ClientAccounts -import okhttp3.MultipartBody -import okhttp3.ResponseBody -import org.mifospay.core.network.ApiEndPoints -import org.mifospay.core.network.GenericResponse -import retrofit2.http.Body -import retrofit2.http.GET -import retrofit2.http.POST -import retrofit2.http.PUT -import retrofit2.http.Part -import retrofit2.http.Path -import retrofit2.http.Query -import rx.Observable - -interface ClientService { - @get:GET(ApiEndPoints.CLIENTS) - val clients: Observable> - - @GET(ApiEndPoints.CLIENTS + "/{clientId}") - fun getClientForId(@Path("clientId") clientId: Long): Observable - - @PUT(ApiEndPoints.CLIENTS + "/{clientId}") - fun updateClient( - @Path("clientId") clientId: Long, - @Body payload: Any, - ): Observable - - @GET(ApiEndPoints.CLIENTS + "/{clientId}/images") - fun getClientImage(@Path("clientId") clientId: Long): Observable - - @PUT(ApiEndPoints.CLIENTS + "/{clientId}/images") - fun updateClientImage( - @Path("clientId") clientId: Long, - @Part typedFile: MultipartBody.Part?, - ): Observable - - @GET(ApiEndPoints.CLIENTS + "/{clientId}/accounts") - fun getClientAccounts(@Path("clientId") clientId: Long): Observable - - @GET(ApiEndPoints.CLIENTS + "/{clientId}/accounts") - fun getAccounts( - @Path("clientId") clientId: Long, - @Query("fields") accountType: String, - ): Observable - - @POST(ApiEndPoints.CLIENTS) - fun createClient(@Body newClient: com.mifospay.core.model.domain.client.NewClient): Observable - - @POST - fun createAccount(@Body newAccount: NewAccount?): Observable -} diff --git a/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/KtorAuthenticationService.kt b/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/KtorAuthenticationService.kt deleted file mode 100644 index 4df4b550c..000000000 --- a/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/KtorAuthenticationService.kt +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.network.services - -import com.mifospay.core.model.domain.user.User -import com.mifospay.core.model.entity.authentication.AuthenticationPayload -import io.ktor.client.HttpClient -import io.ktor.client.call.body -import io.ktor.client.request.post -import io.ktor.client.request.setBody -import io.ktor.http.ContentType -import io.ktor.http.contentType -import org.mifospay.core.network.BaseURL - -class KtorAuthenticationService( - private val client: HttpClient, -) { - - suspend fun authenticate(authPayload: AuthenticationPayload): User { - return client.post("${BaseURL().selfServiceUrl}authentication") { - contentType(ContentType.Application.Json) - setBody(authPayload) - }.body() - } -} diff --git a/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/KtorSavingsAccountService.kt b/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/KtorSavingsAccountService.kt deleted file mode 100644 index 141088cd7..000000000 --- a/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/KtorSavingsAccountService.kt +++ /dev/null @@ -1,81 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.network.services - -import com.mifospay.core.model.entity.Page -import com.mifospay.core.model.entity.accounts.savings.SavingAccount -import com.mifospay.core.model.entity.accounts.savings.SavingsWithAssociations -import com.mifospay.core.model.entity.accounts.savings.Transactions -import io.ktor.client.HttpClient -import io.ktor.client.call.body -import io.ktor.client.request.get -import io.ktor.client.request.post -import io.ktor.client.request.setBody -import io.ktor.http.ContentType -import io.ktor.http.contentType -import org.mifospay.core.network.ApiEndPoints.SAVINGS_ACCOUNTS -import org.mifospay.core.network.ApiEndPoints.TRANSACTIONS -import org.mifospay.core.network.BaseURL -import org.mifospay.core.network.GenericResponse - -class KtorSavingsAccountService( - private val client: HttpClient, -) { - suspend fun getSavingsWithAssociations( - accountId: Long, - associationType: String, - ): SavingsWithAssociations { - return client.get("${BaseURL().selfServiceUrl}$SAVINGS_ACCOUNTS/$accountId") { - url { - parameters.append("associations", associationType) - } - }.body() - } - - suspend fun getSavingsAccounts(limit: Int): Page { - return client.get("${BaseURL().selfServiceUrl}$SAVINGS_ACCOUNTS") { - url { - parameters.append("limit", limit.toString()) - } - }.body() - } - - suspend fun createSavingsAccount(savingAccount: SavingAccount): GenericResponse { - return client.post("${BaseURL().selfServiceUrl}$SAVINGS_ACCOUNTS") { - contentType(ContentType.Application.Json) - setBody(savingAccount) - }.body() - } - - suspend fun blockUnblockAccount(accountId: Long, command: String?): GenericResponse { - return client.post("${BaseURL().selfServiceUrl}$SAVINGS_ACCOUNTS/$accountId") { - url { - parameters.append("command", command ?: "") - } - }.body() - } - - suspend fun getSavingAccountTransaction(accountId: Long, transactionId: Long): Transactions { - return client.get( - urlString = "${BaseURL().selfServiceUrl}$SAVINGS_ACCOUNTS/" + - "$accountId/$TRANSACTIONS/$transactionId", - ).body() - } - - suspend fun payViaMobile(accountId: Long): Transactions { - return client.post( - urlString = "${BaseURL().selfServiceUrl}$SAVINGS_ACCOUNTS/$accountId/$TRANSACTIONS", - ) { - url { - parameters.append("command", "deposit") - } - }.body() - } -} diff --git a/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/ThirdPartyTransferService.kt b/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/ThirdPartyTransferService.kt deleted file mode 100644 index a05074da1..000000000 --- a/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/ThirdPartyTransferService.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.network.services - -import com.mifospay.core.model.entity.TPTResponse -import com.mifospay.core.model.entity.payload.TransferPayload -import org.mifospay.core.model.entity.templates.account.AccountOptionsTemplate -import org.mifospay.core.network.ApiEndPoints -import retrofit2.http.Body -import retrofit2.http.GET -import retrofit2.http.POST -import rx.Observable - -/** - * Created by dilpreet on 21/6/17. - */ -interface ThirdPartyTransferService { - @get:GET(ApiEndPoints.ACCOUNT_TRANSFER + "/template?type=tpt") - val accountTransferTemplate: Observable - - @POST(ApiEndPoints.ACCOUNT_TRANSFER + "?type=\"tpt\"") - fun makeTransfer(@Body transferPayload: TransferPayload): Observable -} diff --git a/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/UserService.kt b/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/UserService.kt deleted file mode 100644 index b2c65fba7..000000000 --- a/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/UserService.kt +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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/mobile-wallet/blob/master/LICENSE.md - */ -package org.mifospay.core.network.services - -import com.mifospay.core.model.domain.user.NewUser -import com.mifospay.core.model.entity.UserWithRole -import org.mifospay.core.network.ApiEndPoints -import org.mifospay.core.network.GenericResponse -import retrofit2.http.Body -import retrofit2.http.DELETE -import retrofit2.http.GET -import retrofit2.http.POST -import retrofit2.http.PUT -import retrofit2.http.Path -import rx.Observable - -/** - * Created by ankur on 11/June/2018 - */ -interface UserService { - @get:GET(ApiEndPoints.USER) - val users: Observable> - - @POST(ApiEndPoints.USER) - fun createUser(@Body user: NewUser): Observable - - @PUT(ApiEndPoints.USER + "/{userId}") - fun updateUser( - @Path("userId") userId: Int, - @Body updateUserEntity: Any, - ): Observable - - @DELETE(ApiEndPoints.USER + "/{userId}") - fun deleteUser( - @Path("userId") userId: Int, - ): Observable - - @GET("self/userdetails") - fun getUser(): Observable -} diff --git a/core/network/src/androidMain/assets/banks.json b/core/network/src/commonMain/assets/banks.json similarity index 100% rename from core/network/src/androidMain/assets/banks.json rename to core/network/src/commonMain/assets/banks.json diff --git a/core/network/src/androidMain/assets/cities.json b/core/network/src/commonMain/assets/cities.json similarity index 100% rename from core/network/src/androidMain/assets/cities.json rename to core/network/src/commonMain/assets/cities.json diff --git a/core/network/src/androidMain/assets/countries.json b/core/network/src/commonMain/assets/countries.json similarity index 100% rename from core/network/src/androidMain/assets/countries.json rename to core/network/src/commonMain/assets/countries.json diff --git a/core/network/src/androidMain/assets/countriesToCities.json b/core/network/src/commonMain/assets/countriesToCities.json similarity index 100% rename from core/network/src/androidMain/assets/countriesToCities.json rename to core/network/src/commonMain/assets/countriesToCities.json diff --git a/core/network/src/androidMain/assets/states.json b/core/network/src/commonMain/assets/states.json similarity index 100% rename from core/network/src/androidMain/assets/states.json rename to core/network/src/commonMain/assets/states.json diff --git a/core/network/src/androidMain/kotlin/org/mifospay/core/network/ApiEndPoints.kt b/core/network/src/commonMain/kotlin/org/mifospay/core/network/ApiEndPoints.kt similarity index 100% rename from core/network/src/androidMain/kotlin/org/mifospay/core/network/ApiEndPoints.kt rename to core/network/src/commonMain/kotlin/org/mifospay/core/network/ApiEndPoints.kt diff --git a/core/network/src/androidMain/kotlin/org/mifospay/core/network/BaseURL.kt b/core/network/src/commonMain/kotlin/org/mifospay/core/network/BaseURL.kt similarity index 52% rename from core/network/src/androidMain/kotlin/org/mifospay/core/network/BaseURL.kt rename to core/network/src/commonMain/kotlin/org/mifospay/core/network/BaseURL.kt index 1359b7e8c..ed472d2e0 100644 --- a/core/network/src/androidMain/kotlin/org/mifospay/core/network/BaseURL.kt +++ b/core/network/src/commonMain/kotlin/org/mifospay/core/network/BaseURL.kt @@ -9,19 +9,22 @@ */ package org.mifospay.core.network -class BaseURL { +object BaseURL { + private const val PROTOCOL_HTTPS = "https://" + private const val API_ENDPOINT = "venus.mifos.community" + private const val API_PATH = "/fineract-provider/api/v1/" + + // self service url + private const val API_ENDPOINT_SELF = "venus.mifos.community" + private const val API_PATH_SELF = "/fineract-provider/api/v1/self/" + + const val HEADER_TENANT = "Fineract-Platform-TenantId" + const val HEADER_AUTH = "Authorization" + const val DEFAULT = "venus" + val url: String get() = PROTOCOL_HTTPS + API_ENDPOINT + API_PATH + val selfServiceUrl: String get() = PROTOCOL_HTTPS + API_ENDPOINT_SELF + API_PATH_SELF - - companion object { - const val PROTOCOL_HTTPS = "https://" - const val API_ENDPOINT = "venus.mifos.community" - const val API_PATH = "/fineract-provider/api/v1/" - - // self service url - const val API_ENDPOINT_SELF = "venus.mifos.community" - const val API_PATH_SELF = "/fineract-provider/api/v1/self/" - } } diff --git a/core/network/src/androidMain/kotlin/org/mifospay/core/network/FineractApiManager.kt b/core/network/src/commonMain/kotlin/org/mifospay/core/network/FineractApiManager.kt similarity index 54% rename from core/network/src/androidMain/kotlin/org/mifospay/core/network/FineractApiManager.kt rename to core/network/src/commonMain/kotlin/org/mifospay/core/network/FineractApiManager.kt index b42a185f4..8c89cdc72 100644 --- a/core/network/src/androidMain/kotlin/org/mifospay/core/network/FineractApiManager.kt +++ b/core/network/src/commonMain/kotlin/org/mifospay/core/network/FineractApiManager.kt @@ -15,7 +15,6 @@ import org.mifospay.core.network.services.ClientService import org.mifospay.core.network.services.DocumentService import org.mifospay.core.network.services.InvoiceService import org.mifospay.core.network.services.KYCLevel1Service -import org.mifospay.core.network.services.KtorSavingsAccountService import org.mifospay.core.network.services.NotificationService import org.mifospay.core.network.services.RegistrationService import org.mifospay.core.network.services.RunReportService @@ -28,73 +27,54 @@ import org.mifospay.core.network.services.TwoFactorAuthService import org.mifospay.core.network.services.UserService class FineractApiManager( - private val authenticationService: AuthenticationService, - private val clientService: ClientService, - private val savingsAccountsService: SavingsAccountsService, - private val registrationService: RegistrationService, - private val searchService: SearchService, - private val documentService: DocumentService, - private val runReportService: RunReportService, - private val twoFactorAuthService: TwoFactorAuthService, - private val accountTransfersService: AccountTransfersService, - private val savedCardService: SavedCardService, - private val kYCLevel1Service: KYCLevel1Service, - private val invoiceService: InvoiceService, - private val userService: UserService, - private val thirdPartyTransferService: ThirdPartyTransferService, - private val standingInstructionService: StandingInstructionService, - private val notificationService: NotificationService, - private val ktorSavingsAccountService: KtorSavingsAccountService, + private val ktorfitClient: KtorfitClient, ) { val authenticationApi: AuthenticationService - get() = authenticationService + get() = ktorfitClient.authenticationApi val clientsApi: ClientService - get() = clientService + get() = ktorfitClient.clientsApi val registrationAPi: RegistrationService - get() = registrationService + get() = ktorfitClient.registrationAPi val searchApi: SearchService - get() = searchService + get() = ktorfitClient.searchApi val documentApi: DocumentService - get() = documentService + get() = ktorfitClient.documentApi val runReportApi: RunReportService - get() = runReportService + get() = ktorfitClient.runReportApi val twoFactorAuthApi: TwoFactorAuthService - get() = twoFactorAuthService + get() = ktorfitClient.twoFactorAuthApi val accountTransfersApi: AccountTransfersService - get() = accountTransfersService + get() = ktorfitClient.accountTransfersApi val savedCardApi: SavedCardService - get() = savedCardService + get() = ktorfitClient.savedCardApi val kycLevel1Api: KYCLevel1Service - get() = kYCLevel1Service + get() = ktorfitClient.kycLevel1Api val invoiceApi: InvoiceService - get() = invoiceService + get() = ktorfitClient.invoiceApi val userApi: UserService - get() = userService + get() = ktorfitClient.userApi val thirdPartyTransferApi: ThirdPartyTransferService - get() = thirdPartyTransferService + get() = ktorfitClient.thirdPartyTransferApi val notificationApi: NotificationService - get() = notificationService + get() = ktorfitClient.notificationApi val savingsAccountsApi: SavingsAccountsService - get() = savingsAccountsService + get() = ktorfitClient.savingsAccountsApi val standingInstructionApi: StandingInstructionService - get() = standingInstructionService - - val ktorSavingsAccountApi: KtorSavingsAccountService - get() = ktorSavingsAccountService + get() = ktorfitClient.standingInstructionApi } diff --git a/core/network/src/commonMain/kotlin/org/mifospay/core/network/KtorfitClient.kt b/core/network/src/commonMain/kotlin/org/mifospay/core/network/KtorfitClient.kt new file mode 100644 index 000000000..86e5e5afa --- /dev/null +++ b/core/network/src/commonMain/kotlin/org/mifospay/core/network/KtorfitClient.kt @@ -0,0 +1,187 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.network + +import de.jensklingenberg.ktorfit.Ktorfit +import de.jensklingenberg.ktorfit.converter.CallConverterFactory +import de.jensklingenberg.ktorfit.converter.FlowConverterFactory +import io.ktor.client.HttpClient +import io.ktor.client.engine.cio.CIO +import io.ktor.client.plugins.DefaultRequest +import io.ktor.client.plugins.contentnegotiation.ContentNegotiation +import io.ktor.client.plugins.defaultRequest +import io.ktor.client.plugins.logging.DEFAULT +import io.ktor.client.plugins.logging.LogLevel +import io.ktor.client.plugins.logging.Logger +import io.ktor.client.plugins.logging.Logging +import io.ktor.http.ContentType +import io.ktor.http.contentType +import io.ktor.http.headers +import io.ktor.serialization.kotlinx.json.json +import kotlinx.serialization.json.Json +import org.mifospay.core.network.services.AccountTransfersService +import org.mifospay.core.network.services.AuthenticationService +import org.mifospay.core.network.services.BeneficiaryService +import org.mifospay.core.network.services.ClientService +import org.mifospay.core.network.services.DocumentService +import org.mifospay.core.network.services.InvoiceService +import org.mifospay.core.network.services.KYCLevel1Service +import org.mifospay.core.network.services.NotificationService +import org.mifospay.core.network.services.RegistrationService +import org.mifospay.core.network.services.RunReportService +import org.mifospay.core.network.services.SavedCardService +import org.mifospay.core.network.services.SavingsAccountsService +import org.mifospay.core.network.services.SearchService +import org.mifospay.core.network.services.StandingInstructionService +import org.mifospay.core.network.services.ThirdPartyTransferService +import org.mifospay.core.network.services.TwoFactorAuthService +import org.mifospay.core.network.services.UserService +import org.mifospay.core.network.services.createAccountTransfersService +import org.mifospay.core.network.services.createAuthenticationService +import org.mifospay.core.network.services.createBeneficiaryService +import org.mifospay.core.network.services.createClientService +import org.mifospay.core.network.services.createDocumentService +import org.mifospay.core.network.services.createInvoiceService +import org.mifospay.core.network.services.createKYCLevel1Service +import org.mifospay.core.network.services.createNotificationService +import org.mifospay.core.network.services.createRegistrationService +import org.mifospay.core.network.services.createRunReportService +import org.mifospay.core.network.services.createSavedCardService +import org.mifospay.core.network.services.createSavingsAccountsService +import org.mifospay.core.network.services.createSearchService +import org.mifospay.core.network.services.createStandingInstructionService +import org.mifospay.core.network.services.createThirdPartyTransferService +import org.mifospay.core.network.services.createTwoFactorAuthService +import org.mifospay.core.network.services.createUserService + +class KtorfitClient( + private val httpClient: HttpClient, + private val ktorfit: Ktorfit, +) { + internal val authenticationApi: AuthenticationService = ktorfit.createAuthenticationService() + + internal val clientsApi: ClientService = ktorfit.createClientService() + + internal val registrationAPi: RegistrationService = ktorfit.createRegistrationService() + + internal val searchApi: SearchService = ktorfit.createSearchService() + + internal val documentApi: DocumentService = ktorfit.createDocumentService() + + internal val runReportApi: RunReportService = ktorfit.createRunReportService() + + internal val twoFactorAuthApi: TwoFactorAuthService = ktorfit.createTwoFactorAuthService() + + internal val accountTransfersApi: AccountTransfersService = + ktorfit.createAccountTransfersService() + + internal val savedCardApi: SavedCardService = ktorfit.createSavedCardService() + + internal val kycLevel1Api: KYCLevel1Service = ktorfit.createKYCLevel1Service() + + internal val invoiceApi: InvoiceService = ktorfit.createInvoiceService() + + internal val userApi: UserService = ktorfit.createUserService() + + internal val thirdPartyTransferApi: ThirdPartyTransferService = + ktorfit.createThirdPartyTransferService() + + internal val notificationApi: NotificationService = ktorfit.createNotificationService() + + internal val savingsAccountsApi: SavingsAccountsService = ktorfit.createSavingsAccountsService() + + internal val standingInstructionApi: StandingInstructionService = + ktorfit.createStandingInstructionService() + + internal val beneficiaryApi: BeneficiaryService = ktorfit.createBeneficiaryService() + + class Builder internal constructor() { + private lateinit var baseURL: String + private var tenant: String? = BaseURL.DEFAULT + private var loginUsername: String? = null + private var loginPassword: String? = null + private var insecure: Boolean = false + private var token: String? = null + + fun baseURL(baseURL: String): Builder { + this.baseURL = baseURL + return this + } + + fun tenant(tenant: String?): Builder { + this.tenant = tenant + return this + } + + fun basicAuth(username: String?, password: String?): Builder { + this.loginUsername = username + this.loginPassword = password + return this + } + + fun inSecure(insecure: Boolean): Builder { + this.insecure = insecure + return this + } + + fun token(token: String?): Builder { + this.token = token + return this + } + + fun build(): KtorfitClient { + val ktorClient = HttpClient(CIO) { + install(ContentNegotiation) { + json( + Json { + isLenient = true + ignoreUnknownKeys = true + }, + ) + } + + install(DefaultRequest) + + install(Logging) { + logger = Logger.DEFAULT + level = LogLevel.INFO + } + + defaultRequest { + contentType(ContentType.Application.Json) + headers { + append("Accept", "application/json") + tenant?.let { + append(BaseURL.HEADER_TENANT, it) + } + token?.let { + append(BaseURL.HEADER_AUTH, it) + } + } + } + } + + val ktorfitBuilder = Ktorfit.Builder() + .httpClient(ktorClient) + .baseUrl(baseURL) + .converterFactories(CallConverterFactory()) + .converterFactories(FlowConverterFactory()) + .build() + + return KtorfitClient(ktorClient, ktorfitBuilder) + } + } + + companion object { + fun builder(): Builder { + return Builder() + } + } +} diff --git a/core/network/src/androidMain/kotlin/org/mifospay/core/network/SelfServiceApiManager.kt b/core/network/src/commonMain/kotlin/org/mifospay/core/network/SelfServiceApiManager.kt similarity index 56% rename from core/network/src/androidMain/kotlin/org/mifospay/core/network/SelfServiceApiManager.kt rename to core/network/src/commonMain/kotlin/org/mifospay/core/network/SelfServiceApiManager.kt index 54ea9d17d..a2349b14e 100644 --- a/core/network/src/androidMain/kotlin/org/mifospay/core/network/SelfServiceApiManager.kt +++ b/core/network/src/commonMain/kotlin/org/mifospay/core/network/SelfServiceApiManager.kt @@ -12,32 +12,23 @@ package org.mifospay.core.network import org.mifospay.core.network.services.AuthenticationService import org.mifospay.core.network.services.BeneficiaryService import org.mifospay.core.network.services.ClientService -import org.mifospay.core.network.services.KtorSavingsAccountService import org.mifospay.core.network.services.RegistrationService import org.mifospay.core.network.services.SavingsAccountsService import org.mifospay.core.network.services.ThirdPartyTransferService class SelfServiceApiManager( - private val authenticationService: AuthenticationService, - private val clientService: ClientService, - private val savingsAccountsService: SavingsAccountsService, - private val registrationService: RegistrationService, - private val beneficiaryService: BeneficiaryService, - private val thirdPartyTransferService: ThirdPartyTransferService, - private val ktorSavingsAccountService: KtorSavingsAccountService, + private val ktorfitClient: KtorfitClient, ) { val authenticationApi: AuthenticationService - get() = authenticationService + get() = ktorfitClient.authenticationApi val clientsApi: ClientService - get() = clientService + get() = ktorfitClient.clientsApi val savingAccountsListApi: SavingsAccountsService - get() = savingsAccountsService + get() = ktorfitClient.savingsAccountsApi val registrationAPi: RegistrationService - get() = registrationService + get() = ktorfitClient.registrationAPi val beneficiaryApi: BeneficiaryService - get() = beneficiaryService + get() = ktorfitClient.beneficiaryApi val thirdPartyTransferApi: ThirdPartyTransferService - get() = thirdPartyTransferService - val ktorSavingsAccountApi: KtorSavingsAccountService - get() = ktorSavingsAccountService + get() = ktorfitClient.thirdPartyTransferApi } diff --git a/core/network/src/androidMain/kotlin/org/mifospay/core/network/di/LocalModule.kt b/core/network/src/commonMain/kotlin/org/mifospay/core/network/di/LocalModule.kt similarity index 77% rename from core/network/src/androidMain/kotlin/org/mifospay/core/network/di/LocalModule.kt rename to core/network/src/commonMain/kotlin/org/mifospay/core/network/di/LocalModule.kt index 484d2effe..73ab48acb 100644 --- a/core/network/src/androidMain/kotlin/org/mifospay/core/network/di/LocalModule.kt +++ b/core/network/src/commonMain/kotlin/org/mifospay/core/network/di/LocalModule.kt @@ -9,12 +9,12 @@ */ package org.mifospay.core.network.di -import org.koin.android.ext.koin.androidContext import org.koin.dsl.module +import org.mifospay.core.network.localAssets.JvmLocalAssetManager import org.mifospay.core.network.localAssets.LocalAssetManager val LocalModule = module { - single { - LocalAssetManager { fileName -> androidContext().assets.open(fileName) } + single { + JvmLocalAssetManager } } diff --git a/core/network/src/commonMain/kotlin/org/mifospay/core/network/di/NetworkModule.kt b/core/network/src/commonMain/kotlin/org/mifospay/core/network/di/NetworkModule.kt new file mode 100644 index 000000000..a40f51b42 --- /dev/null +++ b/core/network/src/commonMain/kotlin/org/mifospay/core/network/di/NetworkModule.kt @@ -0,0 +1,50 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.network.di + +import kotlinx.serialization.json.Json +import org.koin.dsl.module +import org.mifospay.core.network.BaseURL +import org.mifospay.core.network.FineractApiManager +import org.mifospay.core.network.KtorfitClient +import org.mifospay.core.network.SelfServiceApiManager + +val NetworkModule = module { + + single { + Json { + ignoreUnknownKeys = true + } + } + + single(BaseClient) { + KtorfitClient.builder() + .baseURL(BaseURL.url) + .build() + } + + single(SelfClient) { + KtorfitClient.builder() + .baseURL(BaseURL.selfServiceUrl) + .build() + } + + single { + FineractApiManager( + ktorfitClient = get(BaseClient), + ) + } + + single { + SelfServiceApiManager( + ktorfitClient = get(SelfClient), + ) + } +} diff --git a/core/network/src/androidMain/kotlin/org/mifospay/core/network/di/Qualifier.kt b/core/network/src/commonMain/kotlin/org/mifospay/core/network/di/Qualifier.kt similarity index 93% rename from core/network/src/androidMain/kotlin/org/mifospay/core/network/di/Qualifier.kt rename to core/network/src/commonMain/kotlin/org/mifospay/core/network/di/Qualifier.kt index ae0471f29..ce5bbce78 100644 --- a/core/network/src/androidMain/kotlin/org/mifospay/core/network/di/Qualifier.kt +++ b/core/network/src/commonMain/kotlin/org/mifospay/core/network/di/Qualifier.kt @@ -11,8 +11,8 @@ package org.mifospay.core.network.di import org.koin.core.qualifier.named -val SelfServiceApi = named("SelfServiceApi") -val FineractApi = named("FineractApi") +val SelfClient = named("SelfClient") +val BaseClient = named("BaseClient") val FineractAuthenticationService = named("FineractAuthenticationService") val FineractClientService = named("FineractClientService") diff --git a/core/network/src/commonMain/kotlin/org/mifospay/core/network/localAssets/JvmLocalAssetManager.kt b/core/network/src/commonMain/kotlin/org/mifospay/core/network/localAssets/JvmLocalAssetManager.kt new file mode 100644 index 000000000..858c886f0 --- /dev/null +++ b/core/network/src/commonMain/kotlin/org/mifospay/core/network/localAssets/JvmLocalAssetManager.kt @@ -0,0 +1,22 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.network.localAssets + +import okio.FileHandle +import okio.FileSystem +import okio.Path.Companion.toPath +import okio.SYSTEM + +internal object JvmLocalAssetManager : LocalAssetManager { + override fun open(fileName: String): FileHandle { + val path = fileName.toPath() + return FileSystem.SYSTEM.openReadOnly(path) + } +} diff --git a/core/network/src/androidMain/kotlin/org/mifospay/core/network/localAssets/LocalAssetDataSource.kt b/core/network/src/commonMain/kotlin/org/mifospay/core/network/localAssets/LocalAssetDataSource.kt similarity index 100% rename from core/network/src/androidMain/kotlin/org/mifospay/core/network/localAssets/LocalAssetDataSource.kt rename to core/network/src/commonMain/kotlin/org/mifospay/core/network/localAssets/LocalAssetDataSource.kt diff --git a/core/network/src/androidMain/kotlin/org/mifospay/core/network/localAssets/LocalAssetManager.kt b/core/network/src/commonMain/kotlin/org/mifospay/core/network/localAssets/LocalAssetManager.kt similarity index 85% rename from core/network/src/androidMain/kotlin/org/mifospay/core/network/localAssets/LocalAssetManager.kt rename to core/network/src/commonMain/kotlin/org/mifospay/core/network/localAssets/LocalAssetManager.kt index 9930fbcf2..98f8b1138 100644 --- a/core/network/src/androidMain/kotlin/org/mifospay/core/network/localAssets/LocalAssetManager.kt +++ b/core/network/src/commonMain/kotlin/org/mifospay/core/network/localAssets/LocalAssetManager.kt @@ -9,8 +9,8 @@ */ package org.mifospay.core.network.localAssets -import java.io.InputStream +import okio.FileHandle fun interface LocalAssetManager { - fun open(fileName: String): InputStream + fun open(fileName: String): FileHandle } diff --git a/core/network/src/androidMain/kotlin/org/mifospay/core/network/localAssets/MifosLocalAssetDataSource.kt b/core/network/src/commonMain/kotlin/org/mifospay/core/network/localAssets/MifosLocalAssetDataSource.kt similarity index 61% rename from core/network/src/androidMain/kotlin/org/mifospay/core/network/localAssets/MifosLocalAssetDataSource.kt rename to core/network/src/commonMain/kotlin/org/mifospay/core/network/localAssets/MifosLocalAssetDataSource.kt index f14662124..78c4b9d60 100644 --- a/core/network/src/androidMain/kotlin/org/mifospay/core/network/localAssets/MifosLocalAssetDataSource.kt +++ b/core/network/src/commonMain/kotlin/org/mifospay/core/network/localAssets/MifosLocalAssetDataSource.kt @@ -9,14 +9,11 @@ */ package org.mifospay.core.network.localAssets +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.serialization.json.Json import org.mifospay.core.model.City import org.mifospay.core.model.Country import org.mifospay.core.model.State -import kotlinx.coroutines.CoroutineDispatcher -import kotlinx.coroutines.withContext -import kotlinx.serialization.ExperimentalSerializationApi -import kotlinx.serialization.json.Json -import kotlinx.serialization.json.decodeFromStream class MifosLocalAssetDataSource( private val ioDispatcher: CoroutineDispatcher, @@ -24,32 +21,20 @@ class MifosLocalAssetDataSource( private val assets: LocalAssetManager, ) : LocalAssetDataSource { - @OptIn(ExperimentalSerializationApi::class) override suspend fun getCountries(): List { - return withContext(ioDispatcher) { - assets.open(COUNTRIES_ASSET).use(networkJson::decodeFromStream) - } + return emptyList() } - @OptIn(ExperimentalSerializationApi::class) override suspend fun getStateList(): List { - return withContext(ioDispatcher) { - assets.open(STATES_ASSET).use(networkJson::decodeFromStream) - } + return emptyList() } - @OptIn(ExperimentalSerializationApi::class) override suspend fun getBanks(): List { - return withContext(ioDispatcher) { - assets.open(BANKS_ASSET).use(networkJson::decodeFromStream) - } + return emptyList() } - @OptIn(ExperimentalSerializationApi::class) override suspend fun getCities(): List { - return withContext(ioDispatcher) { - assets.open(CITIES_ASSET).use(networkJson::decodeFromStream) - } + return emptyList() } @Suppress("UnusedPrivateProperty") diff --git a/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/SavingsAccountsService.kt b/core/network/src/commonMain/kotlin/org/mifospay/core/network/model/CommonResponse.kt similarity index 68% rename from core/network/src/androidMain/kotlin/org/mifospay/core/network/services/SavingsAccountsService.kt rename to core/network/src/commonMain/kotlin/org/mifospay/core/network/model/CommonResponse.kt index 690658bce..2c2469a42 100644 --- a/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/SavingsAccountsService.kt +++ b/core/network/src/commonMain/kotlin/org/mifospay/core/network/model/CommonResponse.kt @@ -7,6 +7,11 @@ * * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md */ -package org.mifospay.core.network.services +package org.mifospay.core.network.model -interface SavingsAccountsService +import kotlinx.serialization.Serializable + +@Serializable +data class CommonResponse( + val resourceId: Int, +) diff --git a/core/network/src/androidMain/kotlin/org/mifospay/core/network/GenericResponse.kt b/core/network/src/commonMain/kotlin/org/mifospay/core/network/model/GenericResponse.kt similarity index 91% rename from core/network/src/androidMain/kotlin/org/mifospay/core/network/GenericResponse.kt rename to core/network/src/commonMain/kotlin/org/mifospay/core/network/model/GenericResponse.kt index 59c2772f4..7d1ee084f 100644 --- a/core/network/src/androidMain/kotlin/org/mifospay/core/network/GenericResponse.kt +++ b/core/network/src/commonMain/kotlin/org/mifospay/core/network/model/GenericResponse.kt @@ -7,7 +7,7 @@ * * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md */ -package org.mifospay.core.network +package org.mifospay.core.network.model data class GenericResponse( var responseFields: HashMap = hashMapOf(), diff --git a/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/AccountTransfersService.kt b/core/network/src/commonMain/kotlin/org/mifospay/core/network/services/AccountTransfersService.kt similarity index 74% rename from core/network/src/androidMain/kotlin/org/mifospay/core/network/services/AccountTransfersService.kt rename to core/network/src/commonMain/kotlin/org/mifospay/core/network/services/AccountTransfersService.kt index 731fb2795..16c31ed4d 100644 --- a/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/AccountTransfersService.kt +++ b/core/network/src/commonMain/kotlin/org/mifospay/core/network/services/AccountTransfersService.kt @@ -9,16 +9,16 @@ */ package org.mifospay.core.network.services -import com.mifospay.core.model.entity.accounts.savings.TransferDetail +import de.jensklingenberg.ktorfit.http.GET +import de.jensklingenberg.ktorfit.http.Path +import kotlinx.coroutines.flow.Flow +import org.mifospay.core.model.entity.accounts.savings.TransferDetail import org.mifospay.core.network.ApiEndPoints -import retrofit2.http.GET -import retrofit2.http.Path -import rx.Observable /** * Created by ankur on 05/June/2018 */ interface AccountTransfersService { @GET(ApiEndPoints.ACCOUNT_TRANSFER + "/{transferId}") - fun getAccountTransfer(@Path("transferId") transferId: Long): Observable + fun getAccountTransfer(@Path("transferId") transferId: Long): Flow } diff --git a/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/AuthenticationService.kt b/core/network/src/commonMain/kotlin/org/mifospay/core/network/services/AuthenticationService.kt similarity index 69% rename from core/network/src/androidMain/kotlin/org/mifospay/core/network/services/AuthenticationService.kt rename to core/network/src/commonMain/kotlin/org/mifospay/core/network/services/AuthenticationService.kt index c4706dc3c..61daeae86 100644 --- a/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/AuthenticationService.kt +++ b/core/network/src/commonMain/kotlin/org/mifospay/core/network/services/AuthenticationService.kt @@ -9,14 +9,14 @@ */ package org.mifospay.core.network.services -import com.mifospay.core.model.domain.user.User -import com.mifospay.core.model.entity.authentication.AuthenticationPayload +import de.jensklingenberg.ktorfit.http.Body +import de.jensklingenberg.ktorfit.http.POST +import kotlinx.coroutines.flow.Flow +import org.mifospay.core.model.domain.user.User +import org.mifospay.core.model.entity.authentication.AuthenticationPayload import org.mifospay.core.network.ApiEndPoints -import retrofit2.http.Body -import retrofit2.http.POST -import rx.Observable interface AuthenticationService { @POST(ApiEndPoints.AUTHENTICATION) - fun authenticate(@Body authPayload: AuthenticationPayload): Observable + fun authenticate(@Body authPayload: AuthenticationPayload): Flow } diff --git a/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/BeneficiaryService.kt b/core/network/src/commonMain/kotlin/org/mifospay/core/network/services/BeneficiaryService.kt similarity index 50% rename from core/network/src/androidMain/kotlin/org/mifospay/core/network/services/BeneficiaryService.kt rename to core/network/src/commonMain/kotlin/org/mifospay/core/network/services/BeneficiaryService.kt index 198e3bcd4..f3baaabcf 100644 --- a/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/BeneficiaryService.kt +++ b/core/network/src/commonMain/kotlin/org/mifospay/core/network/services/BeneficiaryService.kt @@ -9,39 +9,36 @@ */ package org.mifospay.core.network.services -import com.mifospay.core.model.entity.beneficary.Beneficiary +import de.jensklingenberg.ktorfit.http.Body +import de.jensklingenberg.ktorfit.http.DELETE +import de.jensklingenberg.ktorfit.http.GET +import de.jensklingenberg.ktorfit.http.POST +import de.jensklingenberg.ktorfit.http.PUT +import de.jensklingenberg.ktorfit.http.Path +import kotlinx.coroutines.flow.Flow +import org.mifospay.core.model.entity.beneficary.Beneficiary import org.mifospay.core.model.entity.beneficary.BeneficiaryPayload -import com.mifospay.core.model.entity.beneficary.BeneficiaryUpdatePayload -import com.mifospay.core.model.entity.templates.beneficiary.BeneficiaryTemplate -import okhttp3.ResponseBody +import org.mifospay.core.model.entity.beneficary.BeneficiaryUpdatePayload +import org.mifospay.core.model.entity.templates.beneficiary.BeneficiaryTemplate import org.mifospay.core.network.ApiEndPoints -import retrofit2.http.Body -import retrofit2.http.DELETE -import retrofit2.http.GET -import retrofit2.http.POST -import retrofit2.http.PUT -import retrofit2.http.Path -import rx.Observable +import org.mifospay.core.network.model.CommonResponse -/** - * Created by dilpreet on 14/6/17. - */ interface BeneficiaryService { - @get:GET(ApiEndPoints.BENEFICIARIES + "/tpt") - val beneficiaryList: Observable> + @GET(ApiEndPoints.BENEFICIARIES + "/tpt") + fun beneficiaryList(): Flow> - @get:GET(ApiEndPoints.BENEFICIARIES + "/tpt/template") - val beneficiaryTemplate: Observable + @GET(ApiEndPoints.BENEFICIARIES + "/tpt/template") + fun beneficiaryTemplate(): Flow @POST(ApiEndPoints.BENEFICIARIES + "/tpt") - fun createBeneficiary(@Body beneficiaryPayload: org.mifospay.core.model.entity.beneficary.BeneficiaryPayload): Observable + fun createBeneficiary(@Body beneficiaryPayload: BeneficiaryPayload): Flow @PUT(ApiEndPoints.BENEFICIARIES + "/tpt/{beneficiaryId}") fun updateBeneficiary( @Path("beneficiaryId") beneficiaryId: Long, @Body payload: BeneficiaryUpdatePayload, - ): Observable + ): Flow @DELETE(ApiEndPoints.BENEFICIARIES + "/tpt/{beneficiaryId}") - fun deleteBeneficiary(@Path("beneficiaryId") beneficiaryId: Long): Observable + fun deleteBeneficiary(@Path("beneficiaryId") beneficiaryId: Long): Flow } diff --git a/core/network/src/commonMain/kotlin/org/mifospay/core/network/services/ClientService.kt b/core/network/src/commonMain/kotlin/org/mifospay/core/network/services/ClientService.kt new file mode 100644 index 000000000..fc8dee419 --- /dev/null +++ b/core/network/src/commonMain/kotlin/org/mifospay/core/network/services/ClientService.kt @@ -0,0 +1,60 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.network.services + +import de.jensklingenberg.ktorfit.http.Body +import de.jensklingenberg.ktorfit.http.GET +import de.jensklingenberg.ktorfit.http.Headers +import de.jensklingenberg.ktorfit.http.POST +import de.jensklingenberg.ktorfit.http.PUT +import de.jensklingenberg.ktorfit.http.Path +import de.jensklingenberg.ktorfit.http.Query +import kotlinx.coroutines.flow.Flow +import org.mifospay.core.model.domain.client.NewClient +import org.mifospay.core.model.entity.Page +import org.mifospay.core.model.entity.client.ClientAccounts +import org.mifospay.core.model.entity.client.ClientEntity +import org.mifospay.core.network.ApiEndPoints + +interface ClientService { + @GET(ApiEndPoints.CLIENTS) + fun clients(): Flow> + + @GET(ApiEndPoints.CLIENTS + "/{clientId}") + fun getClientForId(@Path("clientId") clientId: Long): Flow + + @PUT(ApiEndPoints.CLIENTS + "/{clientId}") + fun updateClient( + @Path("clientId") clientId: Long, + @Body payload: Any, + ): Flow + + @GET(ApiEndPoints.CLIENTS + "/{clientId}/images") + @Headers("Accept: text/plain") + fun getClientImage(@Path("clientId") clientId: Long): Flow + + @PUT(ApiEndPoints.CLIENTS + "/{clientId}/images") + fun updateClientImage( + @Path("clientId") clientId: Long, + @Body typedFile: String?, + ): Flow + + @GET(ApiEndPoints.CLIENTS + "/{clientId}/accounts") + fun getClientAccounts(@Path("clientId") clientId: Long): Flow + + @GET(ApiEndPoints.CLIENTS + "/{clientId}/accounts") + fun getAccounts( + @Path("clientId") clientId: Long, + @Query("fields") accountType: String, + ): Flow + + @POST(ApiEndPoints.CLIENTS) + fun createClient(@Body newClient: NewClient): Flow +} diff --git a/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/DocumentService.kt b/core/network/src/commonMain/kotlin/org/mifospay/core/network/services/DocumentService.kt similarity index 82% rename from core/network/src/androidMain/kotlin/org/mifospay/core/network/services/DocumentService.kt rename to core/network/src/commonMain/kotlin/org/mifospay/core/network/services/DocumentService.kt index f02c64ed9..43df8a93b 100644 --- a/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/DocumentService.kt +++ b/core/network/src/commonMain/kotlin/org/mifospay/core/network/services/DocumentService.kt @@ -9,29 +9,24 @@ */ package org.mifospay.core.network.services -import com.mifospay.core.model.entity.noncore.Document -import okhttp3.MultipartBody -import okhttp3.ResponseBody +import de.jensklingenberg.ktorfit.http.DELETE +import de.jensklingenberg.ktorfit.http.GET +import de.jensklingenberg.ktorfit.http.Multipart +import de.jensklingenberg.ktorfit.http.POST +import de.jensklingenberg.ktorfit.http.PUT +import de.jensklingenberg.ktorfit.http.Part +import de.jensklingenberg.ktorfit.http.Path +import io.ktor.http.content.PartData +import kotlinx.coroutines.flow.Flow +import org.mifospay.core.model.entity.noncore.Document import org.mifospay.core.network.ApiEndPoints -import org.mifospay.core.network.GenericResponse -import retrofit2.http.DELETE -import retrofit2.http.GET -import retrofit2.http.Multipart -import retrofit2.http.POST -import retrofit2.http.PUT -import retrofit2.http.Part -import retrofit2.http.Path -import rx.Observable -/** - * @author fomenkoo - */ interface DocumentService { @GET("{entityType}/{entityId}/" + ApiEndPoints.DOCUMENTS) fun getDocuments( - @Path("entityType") entityType: String?, + @Path("entityType") entityType: String, @Path("entityId") entityId: Int, - ): Observable> + ): Flow> /** * @param entityType - Type for which document is being uploaded (Client, Loan @@ -45,11 +40,11 @@ interface DocumentService { @Multipart fun createDocument( @Path("entityType") entityType: String, - @Path("entityId") entityId: Long, + @Path("entityId") entityId: Int, @Part("name") nameOfDocument: String, @Part("description") description: String, - @Part typedFile: MultipartBody.Part, - ): Observable + @Part typedFile: PartData, + ): Flow /** * This Service is for downloading the Document with EntityType and EntityId and Document Id @@ -68,7 +63,7 @@ interface DocumentService { @Path("entityType") entityType: String, @Path("entityId") entityId: Int, @Path("documentId") documentId: Int, - ): Observable + ): Flow /** * This Service is for Deleting the Document with EntityType and EntityId and Document Id. @@ -86,7 +81,7 @@ interface DocumentService { @Path("entityType") entityType: String, @Path("entityId") entityId: Int, @Path("documentId") documentId: Int, - ): Observable + ): Flow /** * This Service for Updating the Document with EntityType and EntityId and Document Id. @@ -111,6 +106,6 @@ interface DocumentService { @Path("documentId") documentId: Int, @Part("name") nameOfDocument: String, @Part("description") description: String, - @Part typedFile: MultipartBody.Part, - ): Observable + @Part typedFile: PartData, + ): Flow } diff --git a/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/InvoiceService.kt b/core/network/src/commonMain/kotlin/org/mifospay/core/network/services/InvoiceService.kt similarity index 52% rename from core/network/src/androidMain/kotlin/org/mifospay/core/network/services/InvoiceService.kt rename to core/network/src/commonMain/kotlin/org/mifospay/core/network/services/InvoiceService.kt index 2a29470c0..7052adb17 100644 --- a/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/InvoiceService.kt +++ b/core/network/src/commonMain/kotlin/org/mifospay/core/network/services/InvoiceService.kt @@ -9,46 +9,44 @@ */ package org.mifospay.core.network.services -import com.mifospay.core.model.entity.Invoice +import de.jensklingenberg.ktorfit.http.Body +import de.jensklingenberg.ktorfit.http.DELETE +import de.jensklingenberg.ktorfit.http.GET +import de.jensklingenberg.ktorfit.http.POST +import de.jensklingenberg.ktorfit.http.PUT +import de.jensklingenberg.ktorfit.http.Path +import kotlinx.coroutines.flow.Flow +import org.mifospay.core.model.entity.Invoice import org.mifospay.core.network.ApiEndPoints -import org.mifospay.core.network.GenericResponse -import retrofit2.http.Body -import retrofit2.http.DELETE -import retrofit2.http.GET -import retrofit2.http.POST -import retrofit2.http.PUT -import retrofit2.http.Path -import rx.Observable +import org.mifospay.core.network.model.GenericResponse -/** - * Created by ankur on 07/June/2018 - */ +// TODO:: Fix this endpoints, there's no such endpoint for invoices interface InvoiceService { - @POST(ApiEndPoints.DATATABLES + "/invoices/{clientId}") - fun addInvoice( - @Path("clientId") clientId: String, - @Body invoice: Invoice?, - ): Observable - @GET(ApiEndPoints.DATATABLES + "/invoices/{clientId}") - fun getInvoices(@Path("clientId") clientId: String): Observable> + fun getInvoices(@Path("clientId") clientId: Int): Flow> @GET(ApiEndPoints.DATATABLES + "/invoices/{clientId}/{invoiceId}") fun getInvoice( - @Path("clientId") clientId: String, - @Path("invoiceId") invoiceId: String, - ): Observable> - - @DELETE(ApiEndPoints.DATATABLES + "/invoices/{clientId}/{invoiceId}") - fun deleteInvoice( - @Path("clientId") clientId: String, + @Path("clientId") clientId: Int, @Path("invoiceId") invoiceId: Int, - ): Observable + ): Flow + + @POST(ApiEndPoints.DATATABLES + "/invoices/{clientId}") + fun addInvoice( + @Path("clientId") clientId: Int, + @Body invoice: Invoice?, + ): Unit @PUT(ApiEndPoints.DATATABLES + "/invoices/{clientId}/{invoiceId}") fun updateInvoice( - @Path("clientId") clientId: String, - @Path("invoiceId") invoiceId: Long, + @Path("clientId") clientId: Int, + @Path("invoiceId") invoiceId: Int, @Body invoice: Invoice?, - ): Observable + ): Flow + + @DELETE(ApiEndPoints.DATATABLES + "/invoices/{clientId}/{invoiceId}") + fun deleteInvoice( + @Path("clientId") clientId: Int, + @Path("invoiceId") invoiceId: Int, + ): Flow } diff --git a/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/KYCLevel1Service.kt b/core/network/src/commonMain/kotlin/org/mifospay/core/network/services/KYCLevel1Service.kt similarity index 64% rename from core/network/src/androidMain/kotlin/org/mifospay/core/network/services/KYCLevel1Service.kt rename to core/network/src/commonMain/kotlin/org/mifospay/core/network/services/KYCLevel1Service.kt index 1066b8e7e..07e63bcb4 100644 --- a/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/KYCLevel1Service.kt +++ b/core/network/src/commonMain/kotlin/org/mifospay/core/network/services/KYCLevel1Service.kt @@ -9,29 +9,30 @@ */ package org.mifospay.core.network.services +import de.jensklingenberg.ktorfit.http.Body +import de.jensklingenberg.ktorfit.http.GET +import de.jensklingenberg.ktorfit.http.POST +import de.jensklingenberg.ktorfit.http.PUT +import de.jensklingenberg.ktorfit.http.Path +import kotlinx.coroutines.flow.Flow import org.mifospay.core.model.entity.kyc.KYCLevel1Details import org.mifospay.core.network.ApiEndPoints -import org.mifospay.core.network.GenericResponse -import retrofit2.http.Body -import retrofit2.http.GET -import retrofit2.http.POST -import retrofit2.http.PUT -import retrofit2.http.Path -import rx.Observable +import org.mifospay.core.network.model.GenericResponse interface KYCLevel1Service { + + @GET(ApiEndPoints.DATATABLES + "/kyc_level1_details/{clientId}") + fun fetchKYCLevel1Details(@Path("clientId") clientId: Int): Flow> + @POST(ApiEndPoints.DATATABLES + "/kyc_level1_details/{clientId}") fun addKYCLevel1Details( @Path("clientId") clientId: Int, - @Body kycLevel1Details: org.mifospay.core.model.entity.kyc.KYCLevel1Details, - ): Observable - - @GET(ApiEndPoints.DATATABLES + "/kyc_level1_details/{clientId}") - fun fetchKYCLevel1Details(@Path("clientId") clientId: Int): Observable> + @Body kycLevel1Details: KYCLevel1Details, + ): Flow @PUT(ApiEndPoints.DATATABLES + "/kyc_level1_details/{clientId}/") fun updateKYCLevel1Details( @Path("clientId") clientId: Int, - @Body kycLevel1Details: org.mifospay.core.model.entity.kyc.KYCLevel1Details, - ): Observable + @Body kycLevel1Details: KYCLevel1Details, + ): Flow } diff --git a/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/NotificationService.kt b/core/network/src/commonMain/kotlin/org/mifospay/core/network/services/NotificationService.kt similarity index 64% rename from core/network/src/androidMain/kotlin/org/mifospay/core/network/services/NotificationService.kt rename to core/network/src/commonMain/kotlin/org/mifospay/core/network/services/NotificationService.kt index 69528821d..33c1dc603 100644 --- a/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/NotificationService.kt +++ b/core/network/src/commonMain/kotlin/org/mifospay/core/network/services/NotificationService.kt @@ -9,16 +9,13 @@ */ package org.mifospay.core.network.services -import com.mifospay.core.model.domain.NotificationPayload +import de.jensklingenberg.ktorfit.http.GET +import de.jensklingenberg.ktorfit.http.Path +import kotlinx.coroutines.flow.Flow +import org.mifospay.core.model.domain.NotificationPayload import org.mifospay.core.network.ApiEndPoints -import retrofit2.http.GET -import retrofit2.http.Path -import rx.Observable -/** - * Created by ankur on 24/July/2018 - */ interface NotificationService { @GET(ApiEndPoints.DATATABLES + "/notifications/{clientId}") - fun fetchNotifications(@Path("clientId") clientId: Long): Observable> + fun fetchNotifications(@Path("clientId") clientId: Long): Flow> } diff --git a/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/RegistrationService.kt b/core/network/src/commonMain/kotlin/org/mifospay/core/network/services/RegistrationService.kt similarity index 57% rename from core/network/src/androidMain/kotlin/org/mifospay/core/network/services/RegistrationService.kt rename to core/network/src/commonMain/kotlin/org/mifospay/core/network/services/RegistrationService.kt index fa05bc240..d93401cf6 100644 --- a/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/RegistrationService.kt +++ b/core/network/src/commonMain/kotlin/org/mifospay/core/network/services/RegistrationService.kt @@ -9,18 +9,16 @@ */ package org.mifospay.core.network.services -import com.mifospay.core.model.entity.register.RegisterPayload -import com.mifospay.core.model.entity.register.UserVerify -import okhttp3.ResponseBody +import de.jensklingenberg.ktorfit.http.Body +import de.jensklingenberg.ktorfit.http.POST +import org.mifospay.core.model.entity.register.RegisterPayload +import org.mifospay.core.model.entity.register.UserVerify import org.mifospay.core.network.ApiEndPoints -import retrofit2.http.Body -import retrofit2.http.POST -import rx.Observable interface RegistrationService { @POST(ApiEndPoints.REGISTRATION) - fun registerUser(@Body registerPayload: RegisterPayload): Observable + fun registerUser(@Body registerPayload: RegisterPayload) @POST(ApiEndPoints.REGISTRATION + "/user") - fun verifyUser(@Body userVerify: UserVerify): Observable + fun verifyUser(@Body userVerify: UserVerify) } diff --git a/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/RunReportService.kt b/core/network/src/commonMain/kotlin/org/mifospay/core/network/services/RunReportService.kt similarity index 67% rename from core/network/src/androidMain/kotlin/org/mifospay/core/network/services/RunReportService.kt rename to core/network/src/commonMain/kotlin/org/mifospay/core/network/services/RunReportService.kt index 68c9d6d6e..c502d067f 100644 --- a/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/RunReportService.kt +++ b/core/network/src/commonMain/kotlin/org/mifospay/core/network/services/RunReportService.kt @@ -9,20 +9,16 @@ */ package org.mifospay.core.network.services -import okhttp3.ResponseBody +import de.jensklingenberg.ktorfit.http.GET +import de.jensklingenberg.ktorfit.http.Query +import kotlinx.coroutines.flow.Flow +import org.mifospay.core.model.entity.accounts.savings.TransactionsEntity import org.mifospay.core.network.ApiEndPoints -import retrofit2.http.GET -import retrofit2.http.Query -import rx.Observable -/** - * Created by ankur on 06/June/2018 - */ -@Suppress("FunctionParameterNaming") interface RunReportService { @GET(ApiEndPoints.RUN_REPORT + "/Savings Transaction Receipt") fun getTransactionReceipt( @Query("output-type") outputType: String, - @Query("R_transactionId") R_transactionId: String, - ): Observable + @Query("R_transactionId") transactionId: String, + ): Flow } diff --git a/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/SavedCardService.kt b/core/network/src/commonMain/kotlin/org/mifospay/core/network/services/SavedCardService.kt similarity index 64% rename from core/network/src/androidMain/kotlin/org/mifospay/core/network/services/SavedCardService.kt rename to core/network/src/commonMain/kotlin/org/mifospay/core/network/services/SavedCardService.kt index 916554e7c..dcf5e4a60 100644 --- a/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/SavedCardService.kt +++ b/core/network/src/commonMain/kotlin/org/mifospay/core/network/services/SavedCardService.kt @@ -9,40 +9,37 @@ */ package org.mifospay.core.network.services -import com.mifospay.core.model.entity.savedcards.Card +import de.jensklingenberg.ktorfit.http.Body +import de.jensklingenberg.ktorfit.http.DELETE +import de.jensklingenberg.ktorfit.http.GET +import de.jensklingenberg.ktorfit.http.POST +import de.jensklingenberg.ktorfit.http.PUT +import de.jensklingenberg.ktorfit.http.Path +import kotlinx.coroutines.flow.Flow +import org.mifospay.core.model.entity.savedcards.Card import org.mifospay.core.network.ApiEndPoints -import org.mifospay.core.network.GenericResponse -import retrofit2.http.Body -import retrofit2.http.DELETE -import retrofit2.http.GET -import retrofit2.http.POST -import retrofit2.http.PUT -import retrofit2.http.Path -import rx.Observable +import org.mifospay.core.network.model.GenericResponse -/** - * Created by ankur on 21/May/2018 - */ interface SavedCardService { @POST(ApiEndPoints.DATATABLES + "/saved_cards/{clientId}") fun addSavedCard( @Path("clientId") clientId: Int, @Body card: Card, - ): Observable + ): Flow @GET(ApiEndPoints.DATATABLES + "/saved_cards/{clientId}") - fun getSavedCards(@Path("clientId") clientId: Int): Observable> + fun getSavedCards(@Path("clientId") clientId: Int): Flow> @DELETE(ApiEndPoints.DATATABLES + "/saved_cards/{clientId}/{cardId}") fun deleteCard( @Path("clientId") clientId: Int, @Path("cardId") cardId: Int, - ): Observable + ): Flow @PUT(ApiEndPoints.DATATABLES + "/saved_cards/{clientId}/{cardId}") fun updateCard( @Path("clientId") clientId: Int, @Path("cardId") cardId: Int, @Body card: Card, - ): Observable + ): Flow } diff --git a/core/network/src/commonMain/kotlin/org/mifospay/core/network/services/SavingsAccountsService.kt b/core/network/src/commonMain/kotlin/org/mifospay/core/network/services/SavingsAccountsService.kt new file mode 100644 index 000000000..7927c84cd --- /dev/null +++ b/core/network/src/commonMain/kotlin/org/mifospay/core/network/services/SavingsAccountsService.kt @@ -0,0 +1,60 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.network.services + +import de.jensklingenberg.ktorfit.http.Body +import de.jensklingenberg.ktorfit.http.GET +import de.jensklingenberg.ktorfit.http.POST +import de.jensklingenberg.ktorfit.http.Path +import de.jensklingenberg.ktorfit.http.Query +import kotlinx.coroutines.flow.Flow +import org.mifospay.core.model.entity.Page +import org.mifospay.core.model.entity.accounts.savings.SavingAccount +import org.mifospay.core.model.entity.accounts.savings.SavingsWithAssociationsEntity +import org.mifospay.core.model.entity.accounts.savings.TransactionsEntity +import org.mifospay.core.network.ApiEndPoints +import org.mifospay.core.network.model.GenericResponse + +interface SavingsAccountsService { + @GET(ApiEndPoints.SAVINGS_ACCOUNTS + "/{accountId}") + suspend fun getSavingsWithAssociations( + @Path("accountId") accountId: Long, + @Query("associations") associationType: String, + ): Flow + + @GET(ApiEndPoints.SAVINGS_ACCOUNTS) + suspend fun getSavingsAccounts( + @Query("limit") limit: Int, + ): Flow> + + @POST(ApiEndPoints.SAVINGS_ACCOUNTS) + suspend fun createSavingsAccount(@Body savingAccount: SavingAccount): Flow + + @POST(ApiEndPoints.SAVINGS_ACCOUNTS + "/{accountId}") + suspend fun blockUnblockAccount( + @Path("accountId") accountId: Long, + @Query("command") command: String?, + ): Flow + + @GET( + ApiEndPoints.SAVINGS_ACCOUNTS + "/{accountId}/" + ApiEndPoints.TRANSACTIONS + + "/{transactionId}", + ) + suspend fun getSavingAccountTransaction( + @Path("accountId") accountId: Long, + @Path("transactionId") transactionId: Long, + ): Flow + + @POST( + ApiEndPoints.SAVINGS_ACCOUNTS + + "/{accountId}/" + ApiEndPoints.TRANSACTIONS + "?command=deposit", + ) + suspend fun payViaMobile(@Path("accountId") accountId: Long): Flow +} diff --git a/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/SearchService.kt b/core/network/src/commonMain/kotlin/org/mifospay/core/network/services/SearchService.kt similarity index 71% rename from core/network/src/androidMain/kotlin/org/mifospay/core/network/services/SearchService.kt rename to core/network/src/commonMain/kotlin/org/mifospay/core/network/services/SearchService.kt index a11f281e0..c80edd09c 100644 --- a/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/SearchService.kt +++ b/core/network/src/commonMain/kotlin/org/mifospay/core/network/services/SearchService.kt @@ -9,17 +9,17 @@ */ package org.mifospay.core.network.services -import com.mifospay.core.model.entity.SearchedEntity +import de.jensklingenberg.ktorfit.http.GET +import de.jensklingenberg.ktorfit.http.Query +import kotlinx.coroutines.flow.Flow +import org.mifospay.core.model.entity.SearchedEntity import org.mifospay.core.network.ApiEndPoints -import retrofit2.http.GET -import retrofit2.http.Query -import rx.Observable interface SearchService { @GET(ApiEndPoints.SEARCH) - fun searchResources( + suspend fun searchResources( @Query("query") query: String, @Query("resource") resources: String, @Query("exactMatch") exactMatch: Boolean, - ): Observable> + ): Flow> } diff --git a/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/StandingInstructionService.kt b/core/network/src/commonMain/kotlin/org/mifospay/core/network/services/StandingInstructionService.kt similarity index 72% rename from core/network/src/androidMain/kotlin/org/mifospay/core/network/services/StandingInstructionService.kt rename to core/network/src/commonMain/kotlin/org/mifospay/core/network/services/StandingInstructionService.kt index 13426e54a..2fbd5cbe7 100644 --- a/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/StandingInstructionService.kt +++ b/core/network/src/commonMain/kotlin/org/mifospay/core/network/services/StandingInstructionService.kt @@ -9,19 +9,19 @@ */ package org.mifospay.core.network.services -import com.mifospay.core.model.entity.Page -import com.mifospay.core.model.entity.payload.StandingInstructionPayload -import com.mifospay.core.model.entity.standinginstruction.SDIResponse -import com.mifospay.core.model.entity.standinginstruction.StandingInstruction +import de.jensklingenberg.ktorfit.http.Body +import de.jensklingenberg.ktorfit.http.GET +import de.jensklingenberg.ktorfit.http.POST +import de.jensklingenberg.ktorfit.http.PUT +import de.jensklingenberg.ktorfit.http.Path +import de.jensklingenberg.ktorfit.http.Query +import kotlinx.coroutines.flow.Flow +import org.mifospay.core.model.entity.Page +import org.mifospay.core.model.entity.payload.StandingInstructionPayload +import org.mifospay.core.model.entity.standinginstruction.SDIResponse +import org.mifospay.core.model.entity.standinginstruction.StandingInstruction import org.mifospay.core.network.ApiEndPoints -import org.mifospay.core.network.GenericResponse -import retrofit2.http.Body -import retrofit2.http.GET -import retrofit2.http.POST -import retrofit2.http.PUT -import retrofit2.http.Path -import retrofit2.http.Query -import rx.Observable +import org.mifospay.core.network.model.GenericResponse interface StandingInstructionService { @@ -29,7 +29,7 @@ interface StandingInstructionService { fun createStandingInstruction( @Body standingInstructionPayload: StandingInstructionPayload, - ): Observable + ): Flow /** * @param clientId - passed as Query to limit the response to client specific response @@ -37,13 +37,13 @@ interface StandingInstructionService { @GET(ApiEndPoints.STANDING_INSTRUCTION) fun getAllStandingInstructions( @Query("clientId") clientId: Long, - ): Observable> + ): Flow> @GET("${ApiEndPoints.STANDING_INSTRUCTION}/{standingInstructionId}") fun getStandingInstruction( @Path("standingInstructionId") standingInstructionId: Long, - ): Observable + ): Flow /** * @param command - if command is passed as "update" then the corresponding standing instruction @@ -56,12 +56,12 @@ interface StandingInstructionService { fun deleteStandingInstruction( @Path("standingInstructionId") standingInstructionId: Long, @Query("command") command: String, - ): Observable + ): Flow @PUT("${ApiEndPoints.STANDING_INSTRUCTION}/{standingInstructionId}") fun updateStandingInstruction( @Path("standingInstructionId") standingInstructionId: Long, @Body standingInstructionPayload: StandingInstructionPayload, @Query("command") command: String, - ): Observable + ): Flow } diff --git a/core/network/src/commonMain/kotlin/org/mifospay/core/network/services/ThirdPartyTransferService.kt b/core/network/src/commonMain/kotlin/org/mifospay/core/network/services/ThirdPartyTransferService.kt new file mode 100644 index 000000000..601234d2d --- /dev/null +++ b/core/network/src/commonMain/kotlin/org/mifospay/core/network/services/ThirdPartyTransferService.kt @@ -0,0 +1,27 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.network.services + +import de.jensklingenberg.ktorfit.http.Body +import de.jensklingenberg.ktorfit.http.GET +import de.jensklingenberg.ktorfit.http.POST +import kotlinx.coroutines.flow.Flow +import org.mifospay.core.model.entity.TPTResponse +import org.mifospay.core.model.entity.payload.TransferPayload +import org.mifospay.core.model.entity.templates.account.AccountOptionsTemplate +import org.mifospay.core.network.ApiEndPoints + +interface ThirdPartyTransferService { + @GET(ApiEndPoints.ACCOUNT_TRANSFER + "/template?type=tpt") + fun accountTransferTemplate(): Flow + + @POST(ApiEndPoints.ACCOUNT_TRANSFER + "?type=tpt") + fun makeTransfer(@Body transferPayload: TransferPayload): Flow +} diff --git a/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/TwoFactorAuthService.kt b/core/network/src/commonMain/kotlin/org/mifospay/core/network/services/TwoFactorAuthService.kt similarity index 59% rename from core/network/src/androidMain/kotlin/org/mifospay/core/network/services/TwoFactorAuthService.kt rename to core/network/src/commonMain/kotlin/org/mifospay/core/network/services/TwoFactorAuthService.kt index 968c5a6b9..c3defdb53 100644 --- a/core/network/src/androidMain/kotlin/org/mifospay/core/network/services/TwoFactorAuthService.kt +++ b/core/network/src/commonMain/kotlin/org/mifospay/core/network/services/TwoFactorAuthService.kt @@ -9,24 +9,21 @@ */ package org.mifospay.core.network.services -import com.mifospay.core.model.domain.twofactor.AccessToken +import de.jensklingenberg.ktorfit.http.GET +import de.jensklingenberg.ktorfit.http.POST +import de.jensklingenberg.ktorfit.http.Query +import kotlinx.coroutines.flow.Flow +import org.mifospay.core.model.domain.twofactor.AccessToken import org.mifospay.core.model.domain.twofactor.DeliveryMethod import org.mifospay.core.network.ApiEndPoints -import retrofit2.http.GET -import retrofit2.http.POST -import retrofit2.http.Query -import rx.Observable -/** - * Created by ankur on 01/June/2018 - */ interface TwoFactorAuthService { - @get:GET(ApiEndPoints.TWOFACTOR) - val deliveryMethods: Observable> + @GET(ApiEndPoints.TWOFACTOR) + fun deliveryMethods(): Flow> @POST(ApiEndPoints.TWOFACTOR) - fun requestOTP(@Query("deliveryMethod") deliveryMethod: String): Observable + fun requestOTP(@Query("deliveryMethod") deliveryMethod: String): Flow @POST(ApiEndPoints.TWOFACTOR + "/validate") - fun validateToken(@Query("token") token: String): Observable + fun validateToken(@Query("token") token: String): Flow } diff --git a/core/network/src/commonMain/kotlin/org/mifospay/core/network/services/UserService.kt b/core/network/src/commonMain/kotlin/org/mifospay/core/network/services/UserService.kt new file mode 100644 index 000000000..2a6c585f7 --- /dev/null +++ b/core/network/src/commonMain/kotlin/org/mifospay/core/network/services/UserService.kt @@ -0,0 +1,45 @@ +/* + * 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/mobile-wallet/blob/master/LICENSE.md + */ +package org.mifospay.core.network.services + +import de.jensklingenberg.ktorfit.http.Body +import de.jensklingenberg.ktorfit.http.DELETE +import de.jensklingenberg.ktorfit.http.GET +import de.jensklingenberg.ktorfit.http.POST +import de.jensklingenberg.ktorfit.http.PUT +import de.jensklingenberg.ktorfit.http.Path +import kotlinx.coroutines.flow.Flow +import org.mifospay.core.model.domain.user.NewUser +import org.mifospay.core.model.entity.UserWithRole +import org.mifospay.core.network.ApiEndPoints +import org.mifospay.core.network.model.CommonResponse +import org.mifospay.core.network.model.GenericResponse + +interface UserService { + @GET(ApiEndPoints.USER) + fun users(): Flow> + + @POST(ApiEndPoints.USER) + fun createUser(@Body user: NewUser): Flow + + @PUT(ApiEndPoints.USER + "/{userId}") + fun updateUser( + @Path("userId") userId: Int, + @Body updateUserEntity: NewUser, + ): Flow + + @DELETE(ApiEndPoints.USER + "/{userId}") + fun deleteUser( + @Path("userId") userId: Int, + ): Flow + + @GET("self/userdetails") + fun getUser(): Flow +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 1f7d9e375..582e711b8 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -30,7 +30,7 @@ datastore = "1.1.1" dependencyGuard = "0.5.0" detekt = "1.23.7" espresso-core = "3.6.1" -fineractSdk = "1.06" +fineractSdk = "1.0.3" firebaseBom = "33.3.0" firebaseCrashlyticsPlugin = "3.0.2" firebasePerfPlugin = "1.4.2" @@ -188,6 +188,8 @@ kotlinx-serialization-json = { group = "org.jetbrains.kotlinx", name = "kotlinx- ksp-gradlePlugin = { group = "com.google.devtools.ksp", name = "com.google.devtools.ksp.gradle.plugin", version.ref = "ksp" } ktlint-gradlePlugin = { group = "org.jlleitschuh.gradle", name = "ktlint-gradle", version.ref = "ktlint" } ktor-client-android = { group = "io.ktor", name = "ktor-client-android", version.ref = "ktorVersion" } +ktor-client-auth = { group = "io.ktor", name = "ktor-client-auth", version.ref = "ktorVersion" } +ktor-client-cio = { group = "io.ktor", name = "ktor-client-cio", version.ref = "ktorVersion" } ktor-client-content-negotiation = { group = "io.ktor", name = "ktor-client-content-negotiation", version.ref = "ktorVersion" } ktor-client-core = { group = "io.ktor", name = "ktor-client-core", version.ref = "ktorVersion" } ktor-client-darwin = { group = "io.ktor", name = "ktor-client-darwin", version.ref = "ktorVersion" } @@ -231,6 +233,7 @@ squareup-retrofit2 = { group = "com.squareup.retrofit2", name = "retrofit", vers truth = { group = "com.google.truth", name = "truth", version.ref = "truth" } twitter-detekt-compose = { group = "com.twitter.compose.rules", name = "detekt", version.ref = "twitter-detekt-compose" } zxing = { group = "com.google.zxing", name = "core", version.ref = "zxingVersion" } +fineract-api = { group = "io.github.niyajali", name = "fineract-client-kmp", version.ref = "fineractSdk" } [bundles] androidx-compose-ui-test = [ @@ -276,6 +279,7 @@ mifospay-cmp-feature = { id = "mifospay.cmp.feature", version = "unspecified" } mifospay-jvm-library = { id = "mifospay.jvm.library", version = "unspecified" } mifospay-kmp-koin = { id = "mifospay.kmp.koin", version = "unspecified" } mifospay-kmp-library = { id = "mifospay.kmp.library", version = "unspecified" } +mifospay-kotlin-inject = { id = "mifospay.kmp.inject", version = "unspecified" } module-graph = { id = "com.jraska.module.graph.assertion", version.ref = "moduleGraph" } protobuf = { id = "com.google.protobuf", version.ref = "protobufPlugin" } roborazzi = { id = "io.github.takahirom.roborazzi", version.ref = "roborazzi" } diff --git a/settings.gradle.kts b/settings.gradle.kts index 9cb771d36..f43a17c79 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -17,7 +17,7 @@ dependencyResolutionManagement { } } - plugins { +plugins { id("org.gradle.toolchains.foojay-resolver-convention") version("0.8.0") id("org.ajoberstar.reckon.settings") version("0.18.3") }