Skip to content
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

MTDSA-27526: API#1803 Retrieve Annual Submission EVCP removal #299

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,20 @@ class RetrieveAnnualSubmissionConnector @Inject() (val http: HttpClient, val app
def retrieveAnnualSubmission(request: RetrieveAnnualSubmissionRequestData)(implicit
hc: HeaderCarrier,
ec: ExecutionContext,
correlationId: String): Future[DownstreamOutcome[RetrieveAnnualSubmissionResponse]] = {
correlationId: String
): Future[DownstreamOutcome[RetrieveAnnualSubmissionResponse]] = {

import request._
import schema._

val downstreamUri: DownstreamUri[DownstreamResp] =
if (taxYear.useTaxYearSpecificApi)
TaxYearSpecificIfsUri(s"income-tax/${taxYear.asTysDownstream}/$nino/self-employments/$businessId/annual-summaries")
else
if (taxYear.useTaxYearSpecificApi) {
TaxYearSpecificIfsUri(
s"income-tax/${taxYear.asTysDownstream}/$nino/self-employments/$businessId/annual-summaries"
)
} else {
IfsUri(s"income-tax/nino/$nino/self-employments/$businessId/annual-summaries/${taxYear.asDownstream}")
}

get(downstreamUri)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@

package v4.retrieveAnnualSubmission

import cats.data.Validated
import cats.data.Validated.Valid
import config.SeBusinessConfig
import play.api.libs.json.Reads
import shared.controllers.validators.resolvers.ResolveTaxYear
import shared.controllers.validators.resolvers.ResolveTaxYearMinimum
import shared.models.domain.TaxYear
import shared.models.errors.MtdError
import shared.schema.DownstreamReadable
import v4.retrieveAnnualSubmission.def1.model.response.Def1_RetrieveAnnualSubmissionResponse
import v4.retrieveAnnualSubmission.def2.model.response.Def2_RetrieveAnnualSubmissionResponse
import v4.retrieveAnnualSubmission.def3.model.response.Def3_RetrieveAnnualSubmissionResponse
import v4.retrieveAnnualSubmission.model.response.RetrieveAnnualSubmissionResponse

import scala.math.Ordered.orderingToOrdered
Expand All @@ -40,16 +45,20 @@ object RetrieveAnnualSubmissionSchema {
val connectorReads: Reads[DownstreamResp] = Def2_RetrieveAnnualSubmissionResponse.reads
}

private val latestSchema = Def2
case object Def3 extends RetrieveAnnualSubmissionSchema {
type DownstreamResp = Def3_RetrieveAnnualSubmissionResponse
val connectorReads: Reads[DownstreamResp] = Def3_RetrieveAnnualSubmissionResponse.reads
}

private val resolveTaxYear =
ResolveTaxYearMinimum(minimumTaxYear = SeBusinessConfig.minimumTaxYear)

def schemaFor(taxYear: String): RetrieveAnnualSubmissionSchema =
ResolveTaxYear(taxYear).toOption
.map(schemaFor)
.getOrElse(latestSchema)
def schemaFor(taxYear: String): Validated[Seq[MtdError], RetrieveAnnualSubmissionSchema] =
resolveTaxYear(taxYear) andThen schemaFor

def schemaFor(taxYear: TaxYear): RetrieveAnnualSubmissionSchema =
if (taxYear <= TaxYear.starting(2023)) Def1
else if (taxYear == TaxYear.starting(2024)) Def2
else latestSchema
def schemaFor(taxYear: TaxYear): Validated[Seq[MtdError], RetrieveAnnualSubmissionSchema] =
if (taxYear >= TaxYear.fromMtd("2025-26")) Valid(Def3)
else if (taxYear == TaxYear.fromMtd("2024-25")) Valid(Def2)
else Valid(Def1)

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,26 @@

package v4.retrieveAnnualSubmission

import cats.data.Validated.{Invalid, Valid}
import shared.controllers.validators.Validator
import shared.models.errors.MtdError
import v4.retrieveAnnualSubmission.RetrieveAnnualSubmissionSchema.{Def1, Def2, Def3}
import v4.retrieveAnnualSubmission.def1.Def1_RetrieveAnnualSubmissionValidator
import v4.retrieveAnnualSubmission.def2.Def2_RetrieveAnnualSubmissionValidator
import v4.retrieveAnnualSubmission.def3.Def3_RetrieveAnnualSubmissionValidator
import v4.retrieveAnnualSubmission.model.request.RetrieveAnnualSubmissionRequestData

import javax.inject.{Inject, Singleton}

@Singleton
class RetrieveAnnualSubmissionValidatorFactory @Inject() {

def validator(nino: String, businessId: String, taxYear: String): Validator[RetrieveAnnualSubmissionRequestData] = {
def validator(nino: String, businessId: String, taxYear: String): Validator[RetrieveAnnualSubmissionRequestData] =
RetrieveAnnualSubmissionSchema.schemaFor(taxYear) match {
case RetrieveAnnualSubmissionSchema.Def1 => new Def1_RetrieveAnnualSubmissionValidator(nino, businessId, taxYear)
case RetrieveAnnualSubmissionSchema.Def2 => new Def2_RetrieveAnnualSubmissionValidator(nino, businessId, taxYear)
case Valid(Def1) => new Def1_RetrieveAnnualSubmissionValidator(nino, businessId, taxYear)
case Valid(Def2) => new Def2_RetrieveAnnualSubmissionValidator(nino, businessId, taxYear)
case Valid(Def3) => new Def3_RetrieveAnnualSubmissionValidator(nino, businessId, taxYear)
case Invalid(errors: Seq[MtdError]) => Validator.returningErrors(errors)
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ package v4.retrieveAnnualSubmission.def1

import cats.data.Validated
import cats.implicits._
import config.SeBusinessConfig
import shared.controllers.validators.Validator
import shared.controllers.validators.resolvers.{ResolveBusinessId, ResolveNino, ResolveTaxYearMinimum}
import shared.controllers.validators.resolvers.{ResolveBusinessId, ResolveNino, ResolveTaxYear}
import shared.models.errors.MtdError
import v4.retrieveAnnualSubmission.def1.model.request.Def1_RetrieveAnnualSubmissionRequestData
import v4.retrieveAnnualSubmission.model.request.RetrieveAnnualSubmissionRequestData
Expand All @@ -31,14 +30,11 @@ class Def1_RetrieveAnnualSubmissionValidator(
taxYear: String
) extends Validator[RetrieveAnnualSubmissionRequestData] {

private val resolveTaxYear =
ResolveTaxYearMinimum(minimumTaxYear = SeBusinessConfig.minimumTaxYear)

def validate: Validated[Seq[MtdError], RetrieveAnnualSubmissionRequestData] =
(
ResolveNino(nino),
ResolveBusinessId(businessId),
resolveTaxYear(taxYear)
ResolveTaxYear(taxYear)
).mapN(Def1_RetrieveAnnualSubmissionRequestData)

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ import play.api.libs.json.{JsPath, Json, OWrites, Reads}
import v4.retrieveAnnualSubmission.model.response.RetrieveAnnualSubmissionResponse

case class Def1_RetrieveAnnualSubmissionResponse(
adjustments: Option[Retrieve_Adjustments],
allowances: Option[Retrieve_Allowances],
nonFinancials: Option[Retrieve_NonFinancials]
adjustments: Option[RetrieveAdjustments],
allowances: Option[RetrieveAllowances],
nonFinancials: Option[RetrieveNonFinancials]
) extends RetrieveAnnualSubmissionResponse

object Def1_RetrieveAnnualSubmissionResponse {

implicit val reads: Reads[Def1_RetrieveAnnualSubmissionResponse] = (
(JsPath \ "annualAdjustments").readNullable[Retrieve_Adjustments] and
(JsPath \ "annualAllowances").readNullable[Retrieve_Allowances] and
(JsPath \ "annualNonFinancials").readNullable[Retrieve_NonFinancials]
(JsPath \ "annualAdjustments").readNullable[RetrieveAdjustments] and
(JsPath \ "annualAllowances").readNullable[RetrieveAllowances] and
(JsPath \ "annualNonFinancials").readNullable[RetrieveNonFinancials]
)(Def1_RetrieveAnnualSubmissionResponse.apply _)

implicit val writes: OWrites[Def1_RetrieveAnnualSubmissionResponse] = Json.writes[Def1_RetrieveAnnualSubmissionResponse]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2023 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package v4.retrieveAnnualSubmission.def1.model.response

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

case class RetrieveAdjustments(includedNonTaxableProfits: Option[BigDecimal],
basisAdjustment: Option[BigDecimal],
overlapReliefUsed: Option[BigDecimal],
accountingAdjustment: Option[BigDecimal],
averagingAdjustment: Option[BigDecimal],
outstandingBusinessIncome: Option[BigDecimal],
balancingChargeBpra: Option[BigDecimal],
balancingChargeOther: Option[BigDecimal],
goodsAndServicesOwnUse: Option[BigDecimal])

object RetrieveAdjustments {
implicit val format: Format[RetrieveAdjustments] = Json.format[RetrieveAdjustments]
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@ package v4.retrieveAnnualSubmission.def1.model.response
import play.api.libs.functional.syntax._
import play.api.libs.json.{JsPath, Json, OWrites, Reads}

case class Retrieve_Allowances(annualInvestmentAllowance: Option[BigDecimal],
businessPremisesRenovationAllowance: Option[BigDecimal],
capitalAllowanceMainPool: Option[BigDecimal],
capitalAllowanceSpecialRatePool: Option[BigDecimal],
zeroEmissionsGoodsVehicleAllowance: Option[BigDecimal],
enhancedCapitalAllowance: Option[BigDecimal],
allowanceOnSales: Option[BigDecimal],
capitalAllowanceSingleAssetPool: Option[BigDecimal],
tradingIncomeAllowance: Option[BigDecimal],
electricChargePointAllowance: Option[BigDecimal],
zeroEmissionsCarAllowance: Option[BigDecimal],
structuredBuildingAllowance: Option[Seq[Retrieve_StructuredBuildingAllowance]],
enhancedStructuredBuildingAllowance: Option[Seq[Retrieve_StructuredBuildingAllowance]])
case class RetrieveAllowances(annualInvestmentAllowance: Option[BigDecimal],
businessPremisesRenovationAllowance: Option[BigDecimal],
capitalAllowanceMainPool: Option[BigDecimal],
capitalAllowanceSpecialRatePool: Option[BigDecimal],
zeroEmissionsGoodsVehicleAllowance: Option[BigDecimal],
enhancedCapitalAllowance: Option[BigDecimal],
allowanceOnSales: Option[BigDecimal],
capitalAllowanceSingleAssetPool: Option[BigDecimal],
tradingIncomeAllowance: Option[BigDecimal],
electricChargePointAllowance: Option[BigDecimal],
zeroEmissionsCarAllowance: Option[BigDecimal],
structuredBuildingAllowance: Option[Seq[RetrieveStructuredBuildingAllowance]],
enhancedStructuredBuildingAllowance: Option[Seq[RetrieveStructuredBuildingAllowance]])

object Retrieve_Allowances {
object RetrieveAllowances {

implicit val reads: Reads[Retrieve_Allowances] = (
implicit val reads: Reads[RetrieveAllowances] = (
(JsPath \ "annualInvestmentAllowance").readNullable[BigDecimal] and
(JsPath \ "businessPremisesRenovationAllowance").readNullable[BigDecimal] and
(JsPath \ "capitalAllowanceMainPool").readNullable[BigDecimal] and
Expand All @@ -47,10 +47,10 @@ object Retrieve_Allowances {
(JsPath \ "tradingIncomeAllowance").readNullable[BigDecimal] and
(JsPath \ "electricChargePointAllowance").readNullable[BigDecimal] and
(JsPath \ "zeroEmissionsCarAllowance").readNullable[BigDecimal] and
(JsPath \ "structuredBuildingAllowance").readNullable[Seq[Retrieve_StructuredBuildingAllowance]] and
(JsPath \ "enhancedStructuredBuildingAllowance").readNullable[Seq[Retrieve_StructuredBuildingAllowance]]
)(Retrieve_Allowances.apply _)
(JsPath \ "structuredBuildingAllowance").readNullable[Seq[RetrieveStructuredBuildingAllowance]] and
(JsPath \ "enhancedStructuredBuildingAllowance").readNullable[Seq[RetrieveStructuredBuildingAllowance]]
)(RetrieveAllowances.apply _)

implicit val writes: OWrites[Retrieve_Allowances] = Json.writes[Retrieve_Allowances]
implicit val writes: OWrites[RetrieveAllowances] = Json.writes[RetrieveAllowances]

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ package v4.retrieveAnnualSubmission.def1.model.response
import play.api.libs.functional.syntax._
import play.api.libs.json.{JsPath, Json, OWrites, Reads}

case class Retrieve_Building(name: Option[String], number: Option[String], postcode: String)
case class RetrieveBuilding(name: Option[String], number: Option[String], postcode: String)

object Retrieve_Building {
implicit val writes: OWrites[Retrieve_Building] = Json.writes[Retrieve_Building]
object RetrieveBuilding {
implicit val writes: OWrites[RetrieveBuilding] = Json.writes[RetrieveBuilding]

implicit val reads: Reads[Retrieve_Building] = (
implicit val reads: Reads[RetrieveBuilding] = (
(JsPath \ "name").readNullable[String] and
(JsPath \ "number").readNullable[String] and
(JsPath \ "postCode").read[String]
)(Retrieve_Building.apply _)
)(RetrieveBuilding.apply _)

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ package v4.retrieveAnnualSubmission.def1.model.response

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

case class Retrieve_FirstYear(qualifyingDate: String, qualifyingAmountExpenditure: BigDecimal)
case class RetrieveFirstYear(qualifyingDate: String, qualifyingAmountExpenditure: BigDecimal)

object Retrieve_FirstYear {
implicit val format: OFormat[Retrieve_FirstYear] = Json.format[Retrieve_FirstYear]
object RetrieveFirstYear {
implicit val format: OFormat[RetrieveFirstYear] = Json.format[RetrieveFirstYear]
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import api.models.domain.ex.{DownstreamNicExemption, MtdNicExemption}
import play.api.libs.functional.syntax._
import play.api.libs.json.{JsPath, Json, OWrites, Reads}

case class Retrieve_NonFinancials(businessDetailsChangedRecently: Boolean, class4NicsExemptionReason: Option[MtdNicExemption])
case class RetrieveNonFinancials(businessDetailsChangedRecently: Boolean, class4NicsExemptionReason: Option[MtdNicExemption])

object Retrieve_NonFinancials {
implicit val writes: OWrites[Retrieve_NonFinancials] = Json.writes[Retrieve_NonFinancials]
object RetrieveNonFinancials {
implicit val writes: OWrites[RetrieveNonFinancials] = Json.writes[RetrieveNonFinancials]

implicit val reads: Reads[Retrieve_NonFinancials] = (
implicit val reads: Reads[RetrieveNonFinancials] = (
(JsPath \ "businessDetailsChangedRecently").read[Boolean] and
(JsPath \ "class4NicsExemptionReason").readNullable[DownstreamNicExemption].map(_.map(_.toMtd))
)(Retrieve_NonFinancials.apply _)
)(RetrieveNonFinancials.apply _)

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ package v4.retrieveAnnualSubmission.def1.model.response

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

case class Retrieve_StructuredBuildingAllowance(
case class RetrieveStructuredBuildingAllowance(
amount: BigDecimal,
firstYear: Option[Retrieve_FirstYear],
building: Retrieve_Building
firstYear: Option[RetrieveFirstYear],
building: RetrieveBuilding
)

object Retrieve_StructuredBuildingAllowance {
object RetrieveStructuredBuildingAllowance {

implicit val format: OFormat[Retrieve_StructuredBuildingAllowance] =
Json.format[Retrieve_StructuredBuildingAllowance]
implicit val format: OFormat[RetrieveStructuredBuildingAllowance] =
Json.format[RetrieveStructuredBuildingAllowance]

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,20 @@ package v4.retrieveAnnualSubmission.def2

import cats.data.Validated
import cats.implicits._
import config.SeBusinessConfig
import shared.controllers.validators.Validator
import shared.controllers.validators.resolvers.{ResolveBusinessId, ResolveNino, ResolveTaxYearMinimum}
import shared.controllers.validators.resolvers.{ResolveBusinessId, ResolveNino, ResolveTaxYear}
import shared.models.errors.MtdError
import v4.retrieveAnnualSubmission.def2.model.request.Def2_RetrieveAnnualSubmissionRequestData
import v4.retrieveAnnualSubmission.model.request.RetrieveAnnualSubmissionRequestData

class Def2_RetrieveAnnualSubmissionValidator(nino: String, businessId: String, taxYear: String)
extends Validator[RetrieveAnnualSubmissionRequestData] {

private val resolveTaxYear =
ResolveTaxYearMinimum(minimumTaxYear = SeBusinessConfig.minimumTaxYear)

def validate: Validated[Seq[MtdError], RetrieveAnnualSubmissionRequestData] =
(
ResolveNino(nino),
ResolveBusinessId(businessId),
resolveTaxYear(taxYear)
ResolveTaxYear(taxYear)
).mapN(Def2_RetrieveAnnualSubmissionRequestData)

}
Loading