diff --git a/src/main/resources/interface-specification.yml b/src/main/resources/interface-specification.yml index 524f221a..fe3b2449 100644 --- a/src/main/resources/interface-specification.yml +++ b/src/main/resources/interface-specification.yml @@ -804,6 +804,15 @@ paths: format: uuid default: [] explode: false + - in: query + name: states + description: comma separated sequence of states + schema: + type: array + items: + $ref: '#/components/schemas/AgreementState' + default: [] + explode: false - in: query name: offset required: true diff --git a/src/main/scala/it/pagopa/interop/agreementprocess/api/impl/AgreementApiServiceImpl.scala b/src/main/scala/it/pagopa/interop/agreementprocess/api/impl/AgreementApiServiceImpl.scala index 7d7c69f7..b6c109cd 100644 --- a/src/main/scala/it/pagopa/interop/agreementprocess/api/impl/AgreementApiServiceImpl.scala +++ b/src/main/scala/it/pagopa/interop/agreementprocess/api/impl/AgreementApiServiceImpl.scala @@ -1284,6 +1284,7 @@ final case class AgreementApiServiceImpl( eServiceName: Option[String], consumersIds: String, producersIds: String, + states: String, offset: Int, limit: Int )(implicit @@ -1296,10 +1297,12 @@ final case class AgreementApiServiceImpl( logger.info(operationLabel) val result: Future[CompactEServices] = for { - eservices <- ReadModelAgreementQueries.listEServicesAgreements( + statesEnum <- parseArrayParameters(states).traverse(AgreementState.fromValue).toFuture + eservices <- ReadModelAgreementQueries.listEServicesAgreements( eServiceName = eServiceName, consumersIds = parseArrayParameters(consumersIds), producersIds = parseArrayParameters(producersIds), + states = statesEnum, offset = offset, limit = limit ) diff --git a/src/main/scala/it/pagopa/interop/agreementprocess/common/readmodel/ReadModelAgreementQueries.scala b/src/main/scala/it/pagopa/interop/agreementprocess/common/readmodel/ReadModelAgreementQueries.scala index c6c2771e..13588300 100644 --- a/src/main/scala/it/pagopa/interop/agreementprocess/common/readmodel/ReadModelAgreementQueries.scala +++ b/src/main/scala/it/pagopa/interop/agreementprocess/common/readmodel/ReadModelAgreementQueries.scala @@ -301,13 +301,17 @@ object ReadModelAgreementQueries extends ReadModelQuery { private def listEServiceAgreementsFilters( name: Option[String], consumersIds: List[String], - producersIds: List[String] + producersIds: List[String], + states: List[AgreementState] ): Bson = { val nameFilter = name.map(n => Filters.regex("eservices.data.name", escape(n), "i")) val consumersIdsFilter = mapToVarArgs(consumersIds.map(Filters.eq("data.consumerId", _)))(Filters.or) val producersIdsFilter = mapToVarArgs(producersIds.map(Filters.eq("data.producerId", _)))(Filters.or) + val statesFilter = listStatesFilter(states) - mapToVarArgs(nameFilter.toList ++ consumersIdsFilter.toList ++ producersIdsFilter.toList)(Filters.and) + mapToVarArgs(nameFilter.toList ++ consumersIdsFilter.toList ++ producersIdsFilter.toList ++ statesFilter.toList)( + Filters.and + ) .getOrElse(Filters.empty()) } @@ -315,10 +319,11 @@ object ReadModelAgreementQueries extends ReadModelQuery { eServiceName: Option[String], consumersIds: List[String], producersIds: List[String], + states: List[AgreementState], offset: Int, limit: Int )(implicit ec: ExecutionContext, readModel: ReadModelService): Future[PaginatedResult[CompactEService]] = { - val query: Bson = listEServiceAgreementsFilters(eServiceName, consumersIds, producersIds) + val query: Bson = listEServiceAgreementsFilters(eServiceName, consumersIds, producersIds, states) val filterPipeline: Seq[Bson] = Seq( lookup("eservices", "data.eserviceId", "data.id", "eservices"), unwind("$eservices", UnwindOptions().preserveNullAndEmptyArrays(false)), diff --git a/src/test/scala/it/pagopa/interop/agreementprocess/AgreementApiAuthzSpec.scala b/src/test/scala/it/pagopa/interop/agreementprocess/AgreementApiAuthzSpec.scala index bb6890d2..fe2574a1 100644 --- a/src/test/scala/it/pagopa/interop/agreementprocess/AgreementApiAuthzSpec.scala +++ b/src/test/scala/it/pagopa/interop/agreementprocess/AgreementApiAuthzSpec.scala @@ -172,7 +172,7 @@ class AgreementApiAuthzSpec extends AnyWordSpecLike with MockFactory with AuthzS validateAuthorization( endpoint, { implicit c: Seq[(String, String)] => - service.getAgreementEServices(Some("query"), "consumersIds", "producersIds", 0, 0) + service.getAgreementEServices(Some("query"), "consumersIds", "producersIds", "states", 0, 0) } ) }