Skip to content

Tom/dls 9710/redo #185

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/uk/gov/hmrc/helptosaveapi/auth/Auth.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 HM Revenue & Customs
* Copyright 2024 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 HM Revenue & Customs
* Copyright 2024 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,19 +16,17 @@

package uk.gov.hmrc.helptosaveapi.connectors

import java.util.UUID

import com.google.inject.{ImplementedBy, Inject, Singleton}
import play.api.Configuration
import play.api.libs.json.{Json, Writes}
import uk.gov.hmrc.helptosaveapi.connectors.HelpToSaveConnectorImpl.CreateAccountInfo
import uk.gov.hmrc.helptosaveapi.http.HttpClient.HttpClientOps
import uk.gov.hmrc.helptosaveapi.models.ValidateBankDetailsRequest
import uk.gov.hmrc.helptosaveapi.models.createaccount.CreateAccountBody
import uk.gov.hmrc.helptosaveapi.util.Logging
import uk.gov.hmrc.helptosaveapi.models.ValidateBankDetailsRequest
import uk.gov.hmrc.http.{HeaderCarrier, HttpResponse}
import uk.gov.hmrc.http._

import java.util.UUID
import scala.concurrent.{ExecutionContext, Future}

@ImplementedBy(classOf[HelpToSaveConnectorImpl])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 HM Revenue & Customs
* Copyright 2024 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,8 +19,6 @@ package uk.gov.hmrc.helptosaveapi.controllers
import akka.stream.Materializer
import com.typesafe.config.Config
import controllers.Assets

import javax.inject.{Inject, Singleton}
import play.api.Configuration
import play.api.libs.json.{Format, Json}
import play.api.mvc.{Action, AnyContent, ControllerComponents}
Expand All @@ -30,6 +28,7 @@ import uk.gov.hmrc.helptosaveapi.controllers.DocumentationController.APIAccess.V
import uk.gov.hmrc.helptosaveapi.views.txt
import uk.gov.hmrc.play.bootstrap.backend.controller.BackendController

import javax.inject.{Inject, Singleton}
import scala.concurrent.ExecutionContext

@Singleton
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 HM Revenue & Customs
* Copyright 2024 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,8 +16,6 @@

package uk.gov.hmrc.helptosaveapi.controllers

import java.time.LocalDate
import java.util.UUID
import cats.instances.string._
import cats.syntax.eq._
import com.google.inject.Inject
Expand All @@ -38,6 +36,8 @@ import uk.gov.hmrc.helptosaveapi.util.{LogMessageTransformer, Logging, toFuture}
import uk.gov.hmrc.http.HeaderCarrier
import uk.gov.hmrc.play.bootstrap.backend.controller.BackendController

import java.time.LocalDate
import java.util.UUID
import scala.concurrent.{ExecutionContext, Future}

class HelpToSaveController @Inject() (
Expand Down
2 changes: 1 addition & 1 deletion app/uk/gov/hmrc/helptosaveapi/http/HttpClient.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 HM Revenue & Customs
* Copyright 2024 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion app/uk/gov/hmrc/helptosaveapi/metrics/Metrics.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 HM Revenue & Customs
* Copyright 2024 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion app/uk/gov/hmrc/helptosaveapi/models/AccessType.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 HM Revenue & Customs
* Copyright 2024 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion app/uk/gov/hmrc/helptosaveapi/models/Account.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 HM Revenue & Customs
* Copyright 2024 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion app/uk/gov/hmrc/helptosaveapi/models/ApiError.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 HM Revenue & Customs
* Copyright 2024 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
8 changes: 4 additions & 4 deletions app/uk/gov/hmrc/helptosaveapi/models/BonusTerm.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 HM Revenue & Customs
* Copyright 2024 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,13 +16,13 @@

package uk.gov.hmrc.helptosaveapi.models

import java.time.LocalDate
import java.time.format.DateTimeFormatter

import play.api.libs.json.Reads.localDateReads
import play.api.libs.json.Writes.temporalWrites
import play.api.libs.json.{Format, Json}

import java.time.LocalDate
import java.time.format.DateTimeFormatter

case class BonusTerm(startDate: LocalDate, endDate: LocalDate, bonusEstimate: BigDecimal)

object BonusTerm {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 HM Revenue & Customs
* Copyright 2024 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion app/uk/gov/hmrc/helptosaveapi/models/EnrolmentStatus.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 HM Revenue & Customs
* Copyright 2024 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
6 changes: 3 additions & 3 deletions app/uk/gov/hmrc/helptosaveapi/models/HtsAccount.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 HM Revenue & Customs
* Copyright 2024 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,10 +16,10 @@

package uk.gov.hmrc.helptosaveapi.models

import java.time.LocalDate

import play.api.libs.json.{Format, Json}

import java.time.LocalDate

case class HtsBonusTerm(
bonusEstimate: BigDecimal,
bonusPaid: BigDecimal,
Expand Down
2 changes: 1 addition & 1 deletion app/uk/gov/hmrc/helptosaveapi/models/Registration.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 HM Revenue & Customs
* Copyright 2024 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 HM Revenue & Customs
* Copyright 2024 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 HM Revenue & Customs
* Copyright 2024 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,14 +16,14 @@

package uk.gov.hmrc.helptosaveapi.models.createaccount

import java.time.LocalDate
import java.time.format.DateTimeFormatter

import play.api.libs.json.Reads.localDateReads
import play.api.libs.json.Writes.temporalWrites
import play.api.libs.json._
import uk.gov.hmrc.helptosaveapi.models.createaccount.CreateAccountBody.{BankDetails, ContactDetails}

import java.time.LocalDate
import java.time.format.DateTimeFormatter

case class CreateAccountBody(
nino: String,
forename: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 HM Revenue & Customs
* Copyright 2024 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 HM Revenue & Customs
* Copyright 2024 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,15 +16,15 @@

package uk.gov.hmrc.helptosaveapi.models.createaccount

import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
import java.util.UUID

import cats.Show
import play.api.libs.json.Reads.zonedDateTimeReads
import play.api.libs.json.Writes.temporalWrites
import play.api.libs.json._

import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
import java.util.UUID

case class CreateAccountHeader(
version: String,
createdTimestamp: ZonedDateTime,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 HM Revenue & Customs
* Copyright 2024 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 HM Revenue & Customs
* Copyright 2024 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 HM Revenue & Customs
* Copyright 2024 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,9 +16,10 @@

package uk.gov.hmrc.helptosaveapi.models.createaccount

import java.time.LocalDate
import uk.gov.hmrc.auth.core.retrieve.ItmpAddress

import java.time.LocalDate

case class RetrievedUserDetails(
nino: Option[String],
forename: Option[String],
Expand Down
56 changes: 30 additions & 26 deletions app/uk/gov/hmrc/helptosaveapi/repo/EligibilityStore.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 HM Revenue & Customs
* Copyright 2024 HM Revenue & Customs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,19 +16,19 @@

package uk.gov.hmrc.helptosaveapi.repo

import java.util.UUID

import cats.data.OptionT
import cats.instances.either._
import cats.syntax.either._
import com.google.inject.{ImplementedBy, Inject, Singleton}
import play.api.libs.json.{Format, JsValue, Json}
import uk.gov.hmrc.helptosaveapi.models.EligibilityResponse
import uk.gov.hmrc.helptosaveapi.repo.EligibilityStore.EligibilityResponseWithNINO
import uk.gov.hmrc.mongo.{CurrentTimestampSupport, MongoComponent}
import uk.gov.hmrc.mongo.cache.{CacheIdType, DataKey, MongoCacheRepository}
import uk.gov.hmrc.mongo.{CurrentTimestampSupport, MongoComponent}
import uk.gov.hmrc.play.bootstrap.config.ServicesConfig
import uk.gov.hmrc.play.http.logging.Mdc.preservingMdc

import java.util.UUID
import scala.concurrent.{ExecutionContext, Future}

@ImplementedBy(classOf[MongoEligibilityStore])
Expand Down Expand Up @@ -72,21 +72,21 @@ class MongoEligibilityStore @Inject() (mongoComponent: MongoComponent, servicesC
override def get(
correlationId: UUID
)(implicit ec: ExecutionContext): Future[Either[String, Option[EligibilityResponseWithNINO]]] =
doFindById(correlationId.toString)
.map { maybeCache =>
val response: OptionT[EitherStringOr, EligibilityResponseWithNINO] = for {
cache <- OptionT.fromOption[EitherStringOr](maybeCache)
data <- OptionT.fromOption[EitherStringOr](Some(cache.data))
result <- OptionT.liftF[EitherStringOr, EligibilityResponseWithNINO](
(data \ "eligibility")
.validate[EligibilityResponseWithNINO]
.asEither
.leftMap(e => s"Could not parse data: ${e.mkString("; ")}")
)
} yield result

response.value
}
doFindById(correlationId.toString)
.map { maybeCache =>
val response: OptionT[EitherStringOr, EligibilityResponseWithNINO] = for {
cache <- OptionT.fromOption[EitherStringOr](maybeCache)
data <- OptionT.fromOption[EitherStringOr](Some(cache.data))
result <- OptionT.liftF[EitherStringOr, EligibilityResponseWithNINO](
(data \ "eligibility")
.validate[EligibilityResponseWithNINO]
.asEither
.leftMap(e => s"Could not parse data: ${e.mkString("; ")}")
)
} yield result

response.value
}
.recover {
case e =>
Left(e.getMessage)
Expand All @@ -95,11 +95,11 @@ class MongoEligibilityStore @Inject() (mongoComponent: MongoComponent, servicesC
override def put(correlationId: UUID, eligibility: EligibilityResponse, nino: String)(
implicit ec: ExecutionContext
): Future[Either[String, Unit]] =
doCreateOrUpdate(
correlationId.toString,
"eligibility",
Json.toJson(EligibilityResponseWithNINO(eligibility, nino))
).map[Either[String, Unit]] { dbUpdate =>
doCreateOrUpdate(
correlationId.toString,
"eligibility",
Json.toJson(EligibilityResponseWithNINO(eligibility, nino))
).map[Either[String, Unit]] { dbUpdate =>
Right(())
}
.recover {
Expand All @@ -108,8 +108,12 @@ class MongoEligibilityStore @Inject() (mongoComponent: MongoComponent, servicesC
}

private[repo] def doFindById(id: String) =
mongoRepo.findById(id)
preservingMdc {
mongoRepo.findById(id)
}

private[repo] def doCreateOrUpdate(id: String, key: String, toCache: JsValue) =
mongoRepo.put(id)(DataKey(key), toCache)
preservingMdc {
mongoRepo.put(id)(DataKey(key), toCache)
}
}
Loading