From 49bde2ea3199700208494753b66023e7c7248764 Mon Sep 17 00:00:00 2001 From: Neirwin Date: Sun, 26 May 2019 19:19:11 +0300 Subject: [PATCH 1/4] added method for getting payments in Repository --- src/com/apmath/loans/application/v1/actions/PaymentList.kt | 2 +- src/com/apmath/loans/domain/repositories/Repository.kt | 5 +++++ .../apmath/loans/domain/repositories/RepositoryInterface.kt | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/com/apmath/loans/application/v1/actions/PaymentList.kt b/src/com/apmath/loans/application/v1/actions/PaymentList.kt index d695756..428d94c 100644 --- a/src/com/apmath/loans/application/v1/actions/PaymentList.kt +++ b/src/com/apmath/loans/application/v1/actions/PaymentList.kt @@ -8,7 +8,7 @@ import com.apmath.loans.domain.models.payments.Payment as PaymentModel import io.ktor.application.ApplicationCall import io.ktor.response.respond -suspend fun ApplicationCall.v1ListPayments(paymentService: PaymentServiceInterface, loanId: Int?){ +suspend fun ApplicationCall.v1ListPayments(paymentService: PaymentServiceInterface, loanId: Int){ val loanIdHeader = getLoanId(request) val payments = diff --git a/src/com/apmath/loans/domain/repositories/Repository.kt b/src/com/apmath/loans/domain/repositories/Repository.kt index bc992a2..d1674eb 100644 --- a/src/com/apmath/loans/domain/repositories/Repository.kt +++ b/src/com/apmath/loans/domain/repositories/Repository.kt @@ -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 @@ -34,4 +36,7 @@ class Repository : RepositoryInterface { this.loans.remove(loan.id) } + override fun getListOfPayments(id: Int, type: Type?): List { + return loans[id]!!.getPayments(type) + } } diff --git a/src/com/apmath/loans/domain/repositories/RepositoryInterface.kt b/src/com/apmath/loans/domain/repositories/RepositoryInterface.kt index faf9804..9f925b5 100644 --- a/src/com/apmath/loans/domain/repositories/RepositoryInterface.kt +++ b/src/com/apmath/loans/domain/repositories/RepositoryInterface.kt @@ -1,6 +1,8 @@ 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 { @@ -8,4 +10,5 @@ interface RepositoryInterface { fun getAll(): List fun store(loan: LoanInterface) fun remove(loan: LoanInterface) + fun getListOfPayments(id: Int, type: Type?): List } From f7ef906047d7757246626de81ed27ab467937dfb Mon Sep 17 00:00:00 2001 From: Neirwin Date: Sun, 26 May 2019 19:21:27 +0300 Subject: [PATCH 2/4] rewrote service --- .../loans/domain/services/PaymentService.kt | 18 +++++------------- .../domain/services/PaymentServiceInterface.kt | 2 +- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/com/apmath/loans/domain/services/PaymentService.kt b/src/com/apmath/loans/domain/services/PaymentService.kt index bee933a..81940ca 100644 --- a/src/com/apmath/loans/domain/services/PaymentService.kt +++ b/src/com/apmath/loans/domain/services/PaymentService.kt @@ -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 { - // 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 { + + val results: List = repository.getListOfPayments(loanId, null) + + return results } } diff --git a/src/com/apmath/loans/domain/services/PaymentServiceInterface.kt b/src/com/apmath/loans/domain/services/PaymentServiceInterface.kt index 67ac89f..846546f 100644 --- a/src/com/apmath/loans/domain/services/PaymentServiceInterface.kt +++ b/src/com/apmath/loans/domain/services/PaymentServiceInterface.kt @@ -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 + suspend fun get(loanIdHeader: Int?, loanId: Int) : List } From 59a8f0e5b4c5dc66ccb916dbc35fa8852c0acc86 Mon Sep 17 00:00:00 2001 From: Neirwin Date: Mon, 27 May 2019 12:41:45 +0300 Subject: [PATCH 3/4] Added not null assertion --- src/com/apmath/loans/application/v1/actions/PaymentList.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/apmath/loans/application/v1/actions/PaymentList.kt b/src/com/apmath/loans/application/v1/actions/PaymentList.kt index 27e5e80..46fc556 100644 --- a/src/com/apmath/loans/application/v1/actions/PaymentList.kt +++ b/src/com/apmath/loans/application/v1/actions/PaymentList.kt @@ -14,7 +14,7 @@ suspend fun ApplicationCall.v1ListPayments(paymentService: PaymentServiceInterfa val payments = try { - paymentService.get(loanIdHeader, loanId) + paymentService.get(loanIdHeader, loanId!!) } catch (e: LoanNotFoundException) { NotFoundException("Loan not found") } From 977e441fdc700a9cbecb151ec423745f22e1c0eb Mon Sep 17 00:00:00 2001 From: Neirwin Date: Mon, 27 May 2019 13:53:04 +0300 Subject: [PATCH 4/4] added check for loan existence in Repository method --- src/com/apmath/loans/domain/repositories/Repository.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/com/apmath/loans/domain/repositories/Repository.kt b/src/com/apmath/loans/domain/repositories/Repository.kt index d1674eb..3c84176 100644 --- a/src/com/apmath/loans/domain/repositories/Repository.kt +++ b/src/com/apmath/loans/domain/repositories/Repository.kt @@ -37,6 +37,9 @@ class Repository : RepositoryInterface { } override fun getListOfPayments(id: Int, type: Type?): List { - return loans[id]!!.getPayments(type) + + val loan = get(id) + + return loan.getPayments(type) } }