def fetchCancelledSubscriptions()

in membership-attribute-service/app/controllers/AccountController.scala [222:243]


  def fetchCancelledSubscriptions(): Action[AnyContent] =
    AuthorizeForRecentLogin(Return401IfNotSignedInRecently, requiredScopes = List(completeReadSelf)).async { implicit request =>
      import request.logPrefix
      metrics.measureDuration("GET /user-attributes/me/cancelled-subscriptions") {
        implicit val tp: TouchpointComponents = request.touchpoint
        val emptyResponse = Ok("[]")
        request.redirectAdvice.userId match {
          case Some(identityId) =>
            for {
              catalog <- tp.futureCatalog
              result <-
                (for {
                  contact <- OptionT(EitherT(tp.contactRepository.get(identityId)))
                  subs <- OptionT(EitherT(tp.subscriptionService.recentlyCancelled(contact)).map(Option(_)))
                } yield {
                  Ok(Json.toJson(subs.map(CancelledSubscription(_, catalog))))
                }).getOrElse(emptyResponse).leftMap(_ => emptyResponse).merge // we discard errors as this is not critical endpoint
            } yield result
          case None => Future.successful(unauthorized)
        }
      }
    }