Skip to content

Commit

Permalink
Merge pull request #245 from pagopa/PIN-4708
Browse files Browse the repository at this point in the history
PIN-4709: BKE - catalog-process: Modified behaviour of DELETE -> /eservices/:id
  • Loading branch information
nttdata-rtorsoli authored Mar 18, 2024
2 parents 399373c + 9fa8847 commit 0c07d7e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -728,12 +728,22 @@ final case class ProcessApiServiceImpl(
val operationLabel = s"Deleting EService $eServiceId"
logger.info(operationLabel)

def isDeletable(catalogItem: CatalogItem): Either[Throwable, Option[CatalogDescriptor]] = Either
.cond(
catalogItem.descriptors.isEmpty ||
(catalogItem.descriptors.length == 1 && catalogItem.descriptors.exists(_.state == Draft)),
catalogItem.descriptors.headOption,
EServiceWithDescriptorsNotDeletable(catalogItem.id.toString)
)

val result: Future[Unit] = for {
organizationId <- getOrganizationIdFutureUUID(contexts)
eServiceUuid <- eServiceId.toFutureUUID
catalogItem <- catalogManagementService.getEServiceById(eServiceUuid)
_ <- assertRequesterAllowed(catalogItem.producerId)(organizationId)
result <- catalogManagementService.deleteEService(eServiceId)
descriptor <- isDeletable(catalogItem).toFuture
_ <- descriptor.fold(Future.unit)(d => catalogManagementService.deleteDraft(eServiceId, d.id.toString))
result <- catalogManagementService.deleteEService(eServiceId)
} yield result

onComplete(result) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ import it.pagopa.interop.catalogprocess.errors.CatalogProcessErrors.{
DescriptorDocumentNotFound,
EServiceDescriptorNotFound,
EServiceNotFound,
EServiceRiskAnalysisNotFound,
EServiceWithDescriptorsNotDeletable
EServiceRiskAnalysisNotFound
}
import it.pagopa.interop.commons.logging.{CanLogContextFields, ContextFieldsToLog}

Expand Down Expand Up @@ -78,7 +77,6 @@ final case class CatalogManagementServiceImpl(invoker: CatalogManagementInvoker,
invoker.invoke(request, s"E-Service $eServiceId deleted").recoverWith {
case err: ApiError[_] if err.code == 404 =>
Future.failed(EServiceNotFound(eServiceId))
case err: ApiError[_] if err.code == 409 => Future.failed(EServiceWithDescriptorsNotDeletable(eServiceId))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import it.pagopa.interop.catalogprocess.errors.CatalogProcessErrors.{
DescriptorDocumentNotFound,
EServiceNotFound,
EServiceRiskAnalysisNotFound,
AttributeNotFound,
EServiceWithDescriptorsNotDeletable
AttributeNotFound
}
import it.pagopa.interop.catalogprocess.model._
import it.pagopa.interop.commons.cqrs.service.ReadModelService
Expand Down Expand Up @@ -3282,14 +3281,11 @@ class CatalogProcessSpec extends SpecHelper with AnyWordSpecLike with ScalatestR
.once()
.returns(Future.successful(eService))

(mockCatalogManagementService
.deleteEService(_: String)(_: Seq[(String, String)]))
.expects(eService.id.toString, *)
.returning(Future.failed(EServiceWithDescriptorsNotDeletable(SpecData.catalogItem.id.toString)))
.once()

Delete() ~> service.deleteEService(SpecData.catalogItem.id.toString) ~> check {
status shouldEqual StatusCodes.Conflict
val problem = responseAs[Problem]
problem.status shouldBe StatusCodes.Conflict.intValue
problem.errors.head.code shouldBe "009-0021"
}
}
"fail if requester is not the Producer" in {
Expand Down

0 comments on commit 0c07d7e

Please sign in to comment.