Skip to content

Commit

Permalink
feat(query): create common interface for search
Browse files Browse the repository at this point in the history
  • Loading branch information
pietro-tota committed Aug 9, 2023
1 parent 6316c79 commit d17672c
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package it.pagopa.ecommerce.helpdesk.dataproviders

import it.pagopa.generated.ecommerce.helpdesk.model.HelpDeskSearchTransactionRequestDto
import it.pagopa.generated.ecommerce.helpdesk.model.TransactionResultDto
import reactor.core.publisher.Mono

/**
* Transaction data provider interface. This interface models common function for transaction data
* provider in order to search for transactions given a specific HelpDeskSearchTransactionRequestDto
* criteria
*
* @see HelpDeskSearchTransactionRequestDto
*/
interface TransactionDataProvider {

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

/**
* Perform paginated query for retrieve transaction information for the given search criteria
*/
fun findResult(
searchCriteria: HelpDeskSearchTransactionRequestDto,
offset: Int,
limit: Int
): Mono<List<TransactionResultDto>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package it.pagopa.ecommerce.helpdesk.dataproviders.mongo

import it.pagopa.ecommerce.helpdesk.dataproviders.TransactionDataProvider
import it.pagopa.generated.ecommerce.helpdesk.model.*
import org.springframework.stereotype.Component
import reactor.core.publisher.Mono

@Component
class EcommerceTransactionDataProvider() : TransactionDataProvider {

override fun totalRecorcCount(searchCriteria: HelpDeskSearchTransactionRequestDto): Mono<Int> =
when (searchCriteria) {
is SearchTransactionRequestPaymentTokenDto -> Mono.just(0) // TODO implementare
is SearchTransactionRequestRptIdDto -> Mono.just(0) // TODO implementare
is SearchTransactionRequestTransactionIdDto -> Mono.just(0) // TODO implementare
is SearchTransactionRequestEmailDto -> Mono.just(0)
is SearchTransactionRequestFiscalCodeDto -> Mono.just(0)
else ->
Mono.error(
RuntimeException("Unhandled search criteria ${searchCriteria.javaClass}")
)
}

override fun findResult(
searchCriteria: HelpDeskSearchTransactionRequestDto,
offset: Int,
limit: Int
): Mono<List<TransactionResultDto>> =
when (searchCriteria) {
is SearchTransactionRequestPaymentTokenDto ->
Mono.just(listOf(TransactionResultDto())) // TODO implementare
is SearchTransactionRequestRptIdDto ->
Mono.just(listOf(TransactionResultDto())) // TODO implementare
is SearchTransactionRequestTransactionIdDto ->
Mono.just(listOf(TransactionResultDto())) // TODO implementare
is SearchTransactionRequestEmailDto -> Mono.just(listOf(TransactionResultDto()))
is SearchTransactionRequestFiscalCodeDto -> Mono.just(listOf(TransactionResultDto()))
else ->
Mono.error(
RuntimeException("Unhandled search criteria ${searchCriteria.javaClass}")
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package it.pagopa.ecommerce.helpdesk.dataproviders.oracle

import io.r2dbc.spi.ConnectionFactory
import it.pagopa.ecommerce.helpdesk.dataproviders.TransactionDataProvider
import it.pagopa.generated.ecommerce.helpdesk.model.*
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component
import reactor.core.publisher.Mono

@Component
class PMTransactionDataProvider(@Autowired connectionFactory: ConnectionFactory) :
TransactionDataProvider {

override fun totalRecorcCount(searchCriteria: HelpDeskSearchTransactionRequestDto): Mono<Int> =
when (searchCriteria) {
is SearchTransactionRequestPaymentTokenDto -> Mono.just(0)
is SearchTransactionRequestRptIdDto -> Mono.just(0)
is SearchTransactionRequestTransactionIdDto -> Mono.just(0)
is SearchTransactionRequestEmailDto -> Mono.just(0) // TODO implementare
is SearchTransactionRequestFiscalCodeDto -> Mono.just(0) // TODO implementare
else ->
Mono.error(
RuntimeException("Unhandled search criteria ${searchCriteria.javaClass}")
)
}

override fun findResult(
searchCriteria: HelpDeskSearchTransactionRequestDto,
offset: Int,
limit: Int
): Mono<List<TransactionResultDto>> =
when (searchCriteria) {
is SearchTransactionRequestPaymentTokenDto -> Mono.just(listOf(TransactionResultDto()))
is SearchTransactionRequestRptIdDto -> Mono.just(listOf(TransactionResultDto()))
is SearchTransactionRequestTransactionIdDto -> Mono.just(listOf(TransactionResultDto()))
is SearchTransactionRequestEmailDto ->
Mono.just(listOf(TransactionResultDto())) // TODO implementare
is SearchTransactionRequestFiscalCodeDto ->
Mono.just(listOf(TransactionResultDto())) // TODO implementare
else ->
Mono.error(
RuntimeException("Unhandled search criteria ${searchCriteria.javaClass}")
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import it.pagopa.ecommerce.helpdesk.dataproviders.oracle.buildTransactionByUserE
import it.pagopa.ecommerce.helpdesk.dataproviders.oracle.getResultSetFromPaginatedQuery
import it.pagopa.ecommerce.helpdesk.utils.buildTransactionSearchResponse
import it.pagopa.generated.ecommerce.helpdesk.model.PmSearchTransactionRequestDto
import it.pagopa.generated.ecommerce.helpdesk.model.PmSearchTransactionRequestEmailDto
import it.pagopa.generated.ecommerce.helpdesk.model.PmSearchTransactionRequestFiscalCodeDto
import it.pagopa.generated.ecommerce.helpdesk.model.SearchTransactionRequestEmailDto
import it.pagopa.generated.ecommerce.helpdesk.model.SearchTransactionRequestFiscalCodeDto
import it.pagopa.generated.ecommerce.helpdesk.model.SearchTransactionResponseDto
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
Expand All @@ -30,7 +30,7 @@ class PmService(@Autowired val connectionFactory: ConnectionFactory) {
.doOnNext { logger.info("Search type: ${it.type}") }
.flatMap {
when (it) {
is PmSearchTransactionRequestEmailDto ->
is SearchTransactionRequestEmailDto ->
getResultSetFromPaginatedQuery(
connectionFactory = connectionFactory,
totalRecordCountQuery =
Expand All @@ -39,7 +39,7 @@ class PmService(@Autowired val connectionFactory: ConnectionFactory) {
pageSize = pageSize,
pageNumber = pageNumber
)
is PmSearchTransactionRequestFiscalCodeDto ->
is SearchTransactionRequestFiscalCodeDto ->
Mono.error(RuntimeException("Not implemented yet"))
else -> Mono.error(RuntimeException(""))
}
Expand Down
14 changes: 14 additions & 0 deletions src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<springProperty name="ECS_SERVICE_VERSION" source="build.version"/>
<appender name="ECS_JSON_CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder class="co.elastic.logging.logback.EcsEncoder">
<serviceName>${ECS_SERVICE_NAME:-undefined}</serviceName>
<serviceVersion>${ECS_SERVICE_VERSION}</serviceVersion>
<serviceEnvironment>${ECS_SERVICE_ENVIRONMENT:-undefined}</serviceEnvironment>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="ECS_JSON_CONSOLE"/>
</root>
</configuration>

0 comments on commit d17672c

Please sign in to comment.