Skip to content

Commit

Permalink
fix(code-review): refactoring searchCriteria arg
Browse files Browse the repository at this point in the history
  • Loading branch information
pietro-tota committed Aug 10, 2023
1 parent 1bba156 commit afbe97f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import reactor.core.publisher.Mono
*/
interface TransactionDataProvider {

/** Retrieve total record count for the given search criteria */
fun totalRecordCount(searchCriteria: HelpDeskSearchTransactionRequestDto): Mono<Int>
/** Retrieve total record count for the given search parameters */
fun totalRecordCount(searchParams: HelpDeskSearchTransactionRequestDto): Mono<Int>

/**
* Perform paginated query for retrieve transaction information for the given search criteria
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,35 @@ class PMTransactionDataProvider(@Autowired private val connectionFactory: Connec

private val logger = LoggerFactory.getLogger(javaClass)

override fun totalRecordCount(searchCriteria: HelpDeskSearchTransactionRequestDto): Mono<Int> =
when (searchCriteria) {
override fun totalRecordCount(searchParams: HelpDeskSearchTransactionRequestDto): Mono<Int> =
when (searchParams) {
is SearchTransactionRequestPaymentTokenDto -> Mono.just(0)
is SearchTransactionRequestRptIdDto -> Mono.just(0)
is SearchTransactionRequestTransactionIdDto -> Mono.just(0)
is SearchTransactionRequestEmailDto ->
getTotalResultCount(buildTransactionByUserEmailCountQuery(searchCriteria.userEmail))
getTotalResultCount(buildTransactionByUserEmailCountQuery(searchParams.userEmail))
is SearchTransactionRequestFiscalCodeDto ->
Mono.error(RuntimeException("Not implemented yet"))
else -> Mono.error(InvalidSearchCriteriaException(searchCriteria.type, ProductDto.PM))
else -> Mono.error(InvalidSearchCriteriaException(searchParams.type, ProductDto.PM))
}

override fun findResult(
searchCriteria: HelpDeskSearchTransactionRequestDto,
searchParams: HelpDeskSearchTransactionRequestDto,
pageSize: Int,
pageNumber: Int
): Mono<List<TransactionResultDto>> {
val searchCriteriaType = searchCriteria.type
val searchCriteriaType = searchParams.type
val invalidSearchCriteriaError =
Mono.error<List<TransactionResultDto>>(
InvalidSearchCriteriaException(searchCriteriaType, ProductDto.PM)
)
return when (searchCriteria) {
return when (searchParams) {
is SearchTransactionRequestPaymentTokenDto -> invalidSearchCriteriaError
is SearchTransactionRequestRptIdDto -> invalidSearchCriteriaError
is SearchTransactionRequestTransactionIdDto -> invalidSearchCriteriaError
is SearchTransactionRequestEmailDto ->
getResultSetFromPaginatedQuery(
resultQuery =
buildTransactionByUserEmailPaginatedQuery(searchCriteria.userEmail),
resultQuery = buildTransactionByUserEmailPaginatedQuery(searchParams.userEmail),
pageNumber = pageNumber,
pageSize = pageSize,
searchType = searchCriteriaType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class PmService(@Autowired val pmTransactionDataProvider: PMTransactionDataProvi
if (totalCount > 0) {
pmTransactionDataProvider
.findResult(
searchCriteria = pmSearchTransactionRequestDto,
searchParams = pmSearchTransactionRequestDto,
pageSize = pageSize,
pageNumber = pageNumber
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class PMTransactionDataProviderTest {
)
StepVerifier.create(
pmTransactionDataProvider.findResult(
searchCriteria = HelpdeskTestUtils.buildSearchRequestByUserMail(),
searchParams = HelpdeskTestUtils.buildSearchRequestByUserMail(),
pageNumber = 0,
pageSize = 10
)
Expand All @@ -96,7 +96,7 @@ class PMTransactionDataProviderTest {

StepVerifier.create(
pmTransactionDataProvider.totalRecordCount(
searchCriteria = HelpdeskTestUtils.buildSearchRequestByRptId()
searchParams = HelpdeskTestUtils.buildSearchRequestByRptId()
)
)
.expectNext(0)
Expand All @@ -108,7 +108,7 @@ class PMTransactionDataProviderTest {

StepVerifier.create(
pmTransactionDataProvider.findResult(
searchCriteria = HelpdeskTestUtils.buildSearchRequestByRptId(),
searchParams = HelpdeskTestUtils.buildSearchRequestByRptId(),
pageNumber = 0,
pageSize = 10
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class PmServiceTest {
.willReturn(Mono.just(totalCount))
given(
pmTransactionDataProvider.findResult(
searchCriteria = searchCriteria,
searchParams = searchCriteria,
pageSize = pageSize,
pageNumber = pageNumber
)
Expand Down

0 comments on commit afbe97f

Please sign in to comment.