Created
April 25, 2021 19:00
-
-
Save Ochornma/1be92401289697f2c1707d3a1f1fa4d5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class SoftKashRepositoryImpl( | |
| private val softKashDao: SoftKashDao, | |
| private val softKashNetworkDataSource: SoftKashNetworkDataSource | |
| ) : SoftKashRepository { | |
| init { | |
| softKashNetworkDataSource.getAllAdmins.observeForever {admins -> | |
| persistAdmins(admins) | |
| } | |
| softKashNetworkDataSource.getAllLoanProducts.observeForever {products -> | |
| persistLoanProducts(products) | |
| } | |
| } | |
| override suspend fun getAllAdmins(): LiveData<out GetAdminResponse> { | |
| return withContext(Dispatchers.IO){ | |
| fetchAdmins() | |
| return@withContext softKashDao.getAllAdmins() | |
| } | |
| } | |
| override suspend fun getAllLoanProducts(): LiveData<out LoanProductResponse> { | |
| return withContext(Dispatchers.IO){ | |
| fetchLoanProduct() | |
| return@withContext softKashDao.getAllLoanProducts() | |
| } | |
| } | |
| override suspend fun getAllTransactions( | |
| paginate: String, | |
| result: (Response<TransactionResponse>) -> Unit | |
| ) { | |
| softKashNetworkDataSource.getTransactions(paginate){ | |
| result(it) | |
| } | |
| } | |
| override suspend fun getAllLoans(paginate: String, result: (Response<LoansResponse>) -> Unit) { | |
| softKashNetworkDataSource.getLoans(paginate){ | |
| result(it) | |
| } | |
| } | |
| override suspend fun getUserNextOfKin(userId: Int, result: (Response<NestOfKinResponse>) -> Unit) { | |
| softKashNetworkDataSource.nextOfKinDetail(userId){nestOfKinResponse -> | |
| result(nestOfKinResponse) | |
| } | |
| } | |
| override suspend fun getUserEmployerDetail(userId: Int, result: (Response<EmployerResponse>) -> Unit) { | |
| softKashNetworkDataSource.employerDetail(userId){employer-> | |
| result(employer) | |
| } | |
| } | |
| override suspend fun deleteDocument( | |
| id: Int, | |
| result: (Response<DocumentDeleteResponse>) -> Unit | |
| ) { | |
| softKashNetworkDataSource.deleteDocuments(id){doc -> | |
| result(doc) | |
| } | |
| } | |
| override suspend fun getPaymentHistory( | |
| paginate: String, | |
| result: (Response<RepaymentHistoryResponse>) -> Unit | |
| ) { | |
| softKashNetworkDataSource.getPaymentHistory(paginate){ | |
| result(it) | |
| } | |
| } | |
| override suspend fun getUserDetail(userId: Int, result: (Response<UserDetailsResponse>) -> Unit) { | |
| softKashNetworkDataSource.userDetail(userId){res -> | |
| result(res) | |
| } | |
| } | |
| override suspend fun getUserSpecificLoan( | |
| userId: Int, | |
| result: (Response<UserDetailLoanResponse>) -> Unit | |
| ) { | |
| softKashNetworkDataSource.getUserSpecificLoan(userId){response -> | |
| result(response) | |
| } | |
| } | |
| override suspend fun addAdmins(firstName: RequestBody, lastName: RequestBody, email: RequestBody, | |
| phoneNo: RequestBody, department: RequestBody, roleName: RequestBody, | |
| staffId: RequestBody, roleId: RequestBody, password: RequestBody, result: (Response<AddAdminResponse>) -> Unit) { | |
| softKashNetworkDataSource.addAdmins(firstName, lastName, email, phoneNo, department, roleName, staffId, roleId, password){response -> | |
| result(response) | |
| } | |
| } | |
| override suspend fun getLoanByStatus( | |
| status: String, | |
| result: (Response<LoanByStatusResponse>) -> Unit | |
| ) { | |
| softKashNetworkDataSource.getLoanByStatus(status){ | |
| result(it) | |
| } | |
| } | |
| override suspend fun getUserTransactionHistory(userId: Int, paginate: String, | |
| result: (Response<UserTransactionResponse>) -> Unit) { | |
| softKashNetworkDataSource.getUserTransactionHistory(userId, paginate){ | |
| result(it) | |
| } | |
| } | |
| override suspend fun approveAndRejectLoan(action: RequestBody, loanId: RequestBody, | |
| adminId: RequestBody, userId: RequestBody, | |
| result: (Response<ApproveAndRejectLoanResponse>) -> Unit) { | |
| softKashNetworkDataSource.approveAndRejectLoan(action, loanId,adminId, userId){ | |
| result(it) | |
| } | |
| } | |
| override suspend fun disburseLoan( | |
| adminId: RequestBody, | |
| userId: RequestBody, | |
| loanId: RequestBody, | |
| result: (Response<DisburseLoanResponse>) -> Unit | |
| ) { | |
| softKashNetworkDataSource.disburseLoan(adminId,userId,loanId){ | |
| result(it) | |
| } | |
| } | |
| override suspend fun login( | |
| email: RequestBody, | |
| password: RequestBody, | |
| result: (Response<LogInResponse>) -> Unit | |
| ) { | |
| softKashNetworkDataSource.login(email, password){ | |
| result(it) | |
| } | |
| } | |
| override suspend fun blockAdmin(adminId: Int, result: (Response<BlockAdminResponse>) -> Unit) { | |
| softKashNetworkDataSource.blockAdmin(adminId){ | |
| result(it) | |
| } | |
| } | |
| override suspend fun unblockAdmin( | |
| adminId: Int, | |
| result: (Response<BlockAdminResponse>) -> Unit | |
| ) { | |
| softKashNetworkDataSource.unblockAdmin(adminId){ | |
| result(it) | |
| } | |
| } | |
| override suspend fun sendOtp(phoneNo: RequestBody, result: (Response<OtpResponse>) -> Unit) { | |
| softKashNetworkDataSource.sendOtp(phoneNo){ | |
| result(it) | |
| } | |
| } | |
| override suspend fun forgotPassword(adminId: Int, token: RequestBody, newPass: RequestBody, | |
| confirmPass: RequestBody, result: (Response<ForgotPasswordResponse>) -> Unit) { | |
| softKashNetworkDataSource.forgotPassword(adminId, token, newPass, confirmPass){ | |
| result(it) | |
| } | |
| } | |
| override suspend fun changePassword(adminId: Int, oldPass: RequestBody, newPass: RequestBody, | |
| confirmPass: RequestBody, result: (Response<ResetPasswordResponse>) -> Unit) { | |
| softKashNetworkDataSource.changePassword(adminId, oldPass, newPass, confirmPass){ | |
| result(it) | |
| } | |
| } | |
| override suspend fun blockUser(userId: Int, result: (Response<BlockUserResponse>) -> Unit) { | |
| softKashNetworkDataSource.blockUser(userId){ | |
| result(it) | |
| } | |
| } | |
| override suspend fun unBlockUser(userId: Int, result: (Response<BlockUserResponse>) -> Unit) { | |
| softKashNetworkDataSource.unBlockUser(userId){ | |
| result(it) | |
| } | |
| } | |
| override suspend fun getSystemAnalysis(result: (Response<SystemAnalysisResponse>) -> Unit) { | |
| softKashNetworkDataSource.getSystemAnalysis { | |
| result(it) | |
| } | |
| } | |
| override suspend fun getUsers(paginate: String, result: (Response<GetUserResponse>) -> Unit) { | |
| softKashNetworkDataSource.getUsers(paginate){ | |
| result(it) | |
| } | |
| } | |
| override suspend fun searchUser( | |
| paginate: String, | |
| words: String, | |
| result: (Response<SearchUserResponse>) -> Unit | |
| ) { | |
| softKashNetworkDataSource.searchUser(paginate, words){ | |
| result(it) | |
| } | |
| } | |
| override suspend fun searchLoan( | |
| paginate: String, | |
| words: String, | |
| result: (Response<LoansResponse>) -> Unit | |
| ) { | |
| softKashNetworkDataSource.searchLoan(paginate, words){ | |
| result(it) | |
| } | |
| } | |
| override suspend fun searchTransaction( | |
| paginate: String, | |
| words: String, | |
| result: (Response<TransactionResponse>) -> Unit | |
| ) { | |
| softKashNetworkDataSource.searchTransaction(paginate, words){ | |
| result(it) | |
| } | |
| } | |
| override suspend fun logInOtp(token: RequestBody, result: (Response<LoginOtpResponse>) -> Unit) { | |
| softKashNetworkDataSource.logInOtp(token){ | |
| result(it) | |
| } | |
| } | |
| override suspend fun searchLoansByDate( | |
| paginate: String, | |
| from: String, | |
| to: String, | |
| result: (Response<LoansResponse>) -> Unit | |
| ) { | |
| softKashNetworkDataSource.searchLoansByDate(paginate, from, to){ | |
| result(it) | |
| } | |
| } | |
| override suspend fun searchTransactionByDate( | |
| paginate: String, | |
| from: String, | |
| to: String, | |
| result: (Response<TransactionResponse>) -> Unit | |
| ) { | |
| softKashNetworkDataSource.searchTransactionByDate(paginate, from, to){ | |
| result(it) | |
| } | |
| } | |
| override suspend fun getTypeOfBusiness(result: (Response<TypeOfBusinessResponse>) -> Unit) { | |
| softKashNetworkDataSource.getTypeOfBusiness(){ | |
| result(it) | |
| } | |
| } | |
| override suspend fun addTypeOfBusiness( | |
| name: RequestBody, | |
| desc: RequestBody, | |
| result: (Response<AddTypeOfBusinessResponse>) -> Unit | |
| ) { | |
| softKashNetworkDataSource.addTypeOfBusiness(name, desc){ | |
| result(it) | |
| } | |
| } | |
| override suspend fun deleteTypeOfBusiness( | |
| id: Int, | |
| result: (Response<DeleteTypeOfBusinessResponse>) -> Unit | |
| ) { | |
| softKashNetworkDataSource.deleteTypeOfBusiness(id){ | |
| result(it) | |
| } | |
| } | |
| override suspend fun getReasonForLoan(result: (Response<ReasonForLoanResponse>) -> Unit) { | |
| softKashNetworkDataSource.getReasonForLoan { | |
| result(it) | |
| } | |
| } | |
| override suspend fun deleteReasonForLoan( | |
| id: Int, | |
| result: (Response<DeleteTypeOfBusinessResponse>) -> Unit | |
| ) { | |
| softKashNetworkDataSource.deleteReasonForLoan(id){ | |
| result(it) | |
| } | |
| } | |
| override suspend fun addReasons( | |
| name: RequestBody, | |
| desc: RequestBody, | |
| result: (Response<AddReasonsRespose>) -> Unit | |
| ) { | |
| softKashNetworkDataSource.addReasons(name, desc){ | |
| result(it) | |
| } | |
| } | |
| override suspend fun addLoanProduct( | |
| productName: RequestBody, | |
| minAmount: RequestBody, | |
| maxAmount: RequestBody, | |
| penalty: RequestBody, | |
| tenureType: RequestBody, | |
| minCreditSCore: RequestBody, | |
| minKycLevel: RequestBody, | |
| processFees: RequestBody, | |
| systemCanApprove: RequestBody, | |
| maxTenure: RequestBody, | |
| interestRate: RequestBody, | |
| interestRateType: RequestBody, | |
| loanType: RequestBody, | |
| result: (Response<AddLoanProductResponse>) -> Unit | |
| ) { | |
| softKashNetworkDataSource.addLoanProduct(productName, minAmount, maxAmount, penalty, tenureType, | |
| minCreditSCore, minKycLevel, processFees, systemCanApprove, maxTenure, interestRate, | |
| interestRateType, loanType){ | |
| result(it) | |
| } | |
| } | |
| override suspend fun deleteLoanProduct( | |
| id: Int, | |
| result: (Response<DeleteLoanProductResponse>) -> Unit | |
| ) { | |
| softKashNetworkDataSource.deleteLoanProduct(id){ | |
| result(it) | |
| } | |
| } | |
| override suspend fun getBureau(userId: Int, result: (Response<BureauResponse>) -> Unit) { | |
| softKashNetworkDataSource.getBureau(userId){ | |
| result(it) | |
| } | |
| } | |
| override suspend fun getRoles(result: (Response<GetRolesResponse>) -> Unit) { | |
| softKashNetworkDataSource.getRoles { | |
| result(it) | |
| } | |
| } | |
| override suspend fun addRoles( | |
| name: RequestBody, | |
| desc: RequestBody, | |
| result: (Response<AddRolesResponse>) -> Unit | |
| ) { | |
| softKashNetworkDataSource.addRoles(name, desc){ | |
| result(it) | |
| } | |
| } | |
| override suspend fun deleteRoles(id: Int, result: (Response<DeleteRolesResponse>) -> Unit) { | |
| softKashNetworkDataSource.deleteRoles(id){ | |
| result(it) | |
| } | |
| } | |
| override suspend fun getUnverifiedBVN(result: (Response<UnverifiedResponse>) -> Unit) { | |
| softKashNetworkDataSource.getUnverifiedBVN { | |
| result(it) | |
| } | |
| } | |
| override suspend fun verifyBVN( | |
| userId: RequestBody, | |
| adminId: RequestBody, | |
| result: (Response<VerifyResponse>) -> Unit | |
| ) { | |
| softKashNetworkDataSource.verifyBVN(userId, adminId) { | |
| result(it) | |
| } | |
| } | |
| private fun persistAdmins(addAdmins: GetAdminResponse){ | |
| GlobalScope.launch(Dispatchers.IO) { | |
| softKashDao.insertAdmin(addAdmins) | |
| } | |
| } | |
| private suspend fun fetchAdmins(){ | |
| softKashNetworkDataSource.fetchAllAdmins() | |
| } | |
| private fun persistLoanProducts(loanProduct: LoanProductResponse){ | |
| GlobalScope.launch(Dispatchers.IO) { | |
| softKashDao.insertLoanProduct(loanProduct) | |
| } | |
| } | |
| private suspend fun fetchLoanProduct(){ | |
| softKashNetworkDataSource.getLoanProducts() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment