Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/com/apmath/loans/domain/repositories/Repository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import com.apmath.loans.domain.exceptions.runtime.RemoveAbsentLoanException
import com.apmath.loans.domain.exceptions.runtime.RemoveUnidentifiedLoanException
import com.apmath.loans.domain.exceptions.runtime.StoreIdentifiedLoanException
import com.apmath.loans.domain.models.loans.LoanInterface
import com.apmath.loans.domain.models.payments.PaymentFromCalculationInterface
import com.apmath.loans.domain.data.Type

class Repository : RepositoryInterface {
private var identity: Int = 1
Expand Down Expand Up @@ -34,4 +36,10 @@ class Repository : RepositoryInterface {
this.loans.remove(loan.id)
}

override fun getListOfPayments(id: Int, type: Type?): List<PaymentFromCalculationInterface> {

val loan = get(id)

return loan.getPayments(type)
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.apmath.loans.domain.repositories

import com.apmath.loans.domain.models.loans.LoanInterface
import com.apmath.loans.domain.models.payments.PaymentFromCalculationInterface
import com.apmath.loans.domain.data.Type

//TODO replace with database
interface RepositoryInterface {
fun get(id: Int): LoanInterface
fun getAll(): List<LoanInterface>
fun store(loan: LoanInterface)
fun remove(loan: LoanInterface)
fun getListOfPayments(id: Int, type: Type?): List<PaymentFromCalculationInterface>
}
18 changes: 5 additions & 13 deletions src/com/apmath/loans/domain/services/PaymentService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,12 @@ import com.apmath.loans.domain.repositories.RepositoryInterface
import com.apmath.loans.infrastructure.models.payments.PaymentFromCalculation

class PaymentService(
private val calculationsFetcher: CalculationsFetcherInterface,
private val repository: RepositoryInterface
) : PaymentServiceInterface {
override suspend fun get(loanIdHeader: Int?, loanId: Int?): Array<PaymentFromCalculationInterface> {
// for manual testing
val payment = PaymentFromCalculation(
"date",
1,
2,
3,
Type.REGULAR,
4,
5
)
return arrayOf(payment)
override suspend fun get(loanIdHeader: Int?, loanId: Int): List<PaymentFromCalculationInterface> {

val results: List<PaymentFromCalculationInterface> = repository.getListOfPayments(loanId, null)

return results
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ package com.apmath.loans.domain.services
import com.apmath.loans.domain.models.payments.PaymentFromCalculationInterface

interface PaymentServiceInterface {
suspend fun get(loanIdHeader: Int?, loanId: Int?) : Array<PaymentFromCalculationInterface>
suspend fun get(loanIdHeader: Int?, loanId: Int) : List<PaymentFromCalculationInterface>
}