diff --git a/app/connectors/CreateIncomeSourcesConnector.scala b/app/connectors/CreateIncomeSourcesConnector.scala index ac7c252..85985df 100644 --- a/app/connectors/CreateIncomeSourcesConnector.scala +++ b/app/connectors/CreateIncomeSourcesConnector.scala @@ -33,15 +33,15 @@ class CreateIncomeSourcesConnector @Inject()(http: HttpClient, appConfig: AppConfig, auditService: AuditService)(implicit ec: ExecutionContext) { - def businessIncomeUrl(mtdbsaRef: String): String = s"${appConfig.desURL}/income-tax/income-sources/mtdbsa/$mtdbsaRef/ITSA/business" + private def businessIncomeUrl(mtdbsaRef: String): String = { + s"${appConfig.desURL}/income-tax/income-sources/mtdbsa/$mtdbsaRef/ITSA/business" + } def createBusinessIncomeSources(agentReferenceNumber: Option[String], mtdbsaRef: String, createIncomeSources: CreateIncomeSourcesModel) (implicit hc: HeaderCarrier, request: Request[_]): Future[PostIncomeSourceResponse] = { - auditService.extendedAudit(CompletedSignUpAudit(agentReferenceNumber, createIncomeSources, appConfig.desAuthorisationToken)) - val headerCarrier: HeaderCarrier = hc .copy(authorization = Some(Authorization(appConfig.desAuthorisationToken))) .withExtraHeaders(appConfig.desEnvironmentHeader) @@ -56,7 +56,13 @@ class CreateIncomeSourcesConnector @Inject()(http: HttpClient, implicitly[HttpReads[PostIncomeSourceResponse]], headerCarrier, implicitly - ) + ) map { + case Left(error) => + Left(error) + case Right(value) => + auditService.extendedAudit(CompletedSignUpAudit(agentReferenceNumber, createIncomeSources, appConfig.desAuthorisationToken)) + Right(value) + } } diff --git a/app/repositories/SessionDataRepository.scala b/app/repositories/SessionDataRepository.scala index 8c98a67..81edc97 100644 --- a/app/repositories/SessionDataRepository.scala +++ b/app/repositories/SessionDataRepository.scala @@ -17,21 +17,16 @@ package repositories import com.mongodb.client.model.{FindOneAndUpdateOptions, IndexOptions} -import com.mongodb.client.result.DeleteResult import config.AppConfig import org.bson.Document import org.bson.conversions.Bson import org.mongodb.scala.model.IndexModel import org.mongodb.scala.result.InsertOneResult -import play.api.libs.json.Json.JsValueWrapper import play.api.libs.json._ -import uk.gov.hmrc.http.InternalServerException import uk.gov.hmrc.mongo.MongoComponent import uk.gov.hmrc.mongo.play.json.PlayMongoRepository -import utils.JsonUtils.JsObjectUtil import java.time.Instant -import java.util.UUID import java.util.concurrent.TimeUnit import javax.inject.{Inject, Singleton} import scala.concurrent.{ExecutionContext, Future} diff --git a/app/services/SessionDataService.scala b/app/services/SessionDataService.scala index ef64f58..88e7db6 100644 --- a/app/services/SessionDataService.scala +++ b/app/services/SessionDataService.scala @@ -23,27 +23,26 @@ import repositories.SessionDataRepository import uk.gov.hmrc.http.{HeaderCarrier, InternalServerException} import javax.inject.{Inject, Singleton} -import scala.concurrent.{ExecutionContext, Future} +import scala.concurrent.Future @Singleton -class SessionDataService @Inject()(sessionDataRepository: SessionDataRepository, val appConfig: AppConfig) - (implicit ec: ExecutionContext) extends FeatureSwitching { +class SessionDataService @Inject()(sessionDataRepository: SessionDataRepository, val appConfig: AppConfig) extends FeatureSwitching { - def getAllSessionData(implicit hc:HeaderCarrier): Future[Option[JsValue]] = + def getAllSessionData(implicit hc: HeaderCarrier): Future[Option[JsValue]] = sessionDataRepository.getSessionData(sessionId = sessionIdFromHC) - def getSessionData(dataId: String)(implicit hc:HeaderCarrier): Future[Option[JsValue]] = + def getSessionData(dataId: String)(implicit hc: HeaderCarrier): Future[Option[JsValue]] = sessionDataRepository.getDataFromSession(sessionId = sessionIdFromHC, dataId = dataId) - def insertSessionData(dataId: String, data: JsValue)(implicit hc:HeaderCarrier): Future[Option[JsValue]] = + def insertSessionData(dataId: String, data: JsValue)(implicit hc: HeaderCarrier): Future[Option[JsValue]] = sessionDataRepository.insertDataWithSession( sessionId = sessionIdFromHC, dataId = dataId, data = data ) - def deleteSessionData(dataId: String)(implicit hc:HeaderCarrier): Future[Option[JsValue]] = + def deleteSessionData(dataId: String)(implicit hc: HeaderCarrier): Future[Option[JsValue]] = sessionDataRepository.deleteDataWithSession( sessionId = sessionIdFromHC, dataId = dataId diff --git a/project/plugins.sbt b/project/plugins.sbt index a6dc55d..65bb6c8 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -2,9 +2,9 @@ resolvers += "HMRC-open-artefacts-maven" at "https://open.artefacts.tax.service.gov.uk/maven2" resolvers += Resolver.url("HMRC-open-artefacts-ivy", url("https://open.artefacts.tax.service.gov.uk/ivy2"))(Resolver.ivyStylePatterns) -addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.20.0") +addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.21.0") -addSbtPlugin("uk.gov.hmrc" % "sbt-distributables" % "2.4.0") +addSbtPlugin("uk.gov.hmrc" % "sbt-distributables" % "2.5.0") addSbtPlugin("org.playframework" % "sbt-plugin" % "3.0.0") diff --git a/test/services/SessionDataServiceSpec.scala b/test/services/SessionDataServiceSpec.scala index 22e9495..7e9d76a 100644 --- a/test/services/SessionDataServiceSpec.scala +++ b/test/services/SessionDataServiceSpec.scala @@ -16,7 +16,6 @@ package services -import com.mongodb.client.result.DeleteResult import common.CommonSpec import config.MicroserviceAppConfig import config.featureswitch.FeatureSwitching @@ -28,11 +27,9 @@ import play.api.Configuration import play.api.libs.json.{JsObject, Json} import play.api.test.Helpers.{await, defaultAwaitTimeout} import repositories.SessionDataRepository -import services.SubscriptionDataService.{Created, Existence, Existing} import uk.gov.hmrc.http.{HeaderCarrier, InternalServerException, SessionId} import uk.gov.hmrc.play.bootstrap.config.ServicesConfig -import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.Future class SessionDataServiceSpec extends CommonSpec with MockitoSugar with FeatureSwitching with BeforeAndAfterEach {