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-23287] Update Enum Value for consistency #540

Merged
merged 36 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
52c1e46
NOJIRA Remove advanced-rate enum from def1
MadStu Aug 27, 2024
a133b38
Merge remote-tracking branch 'origin/main'
MadStu Aug 28, 2024
0e59ea3
Merge remote-tracking branch 'origin/main'
MadStu Sep 2, 2024
4e8a18f
Merge remote-tracking branch 'origin/main'
MadStu Sep 4, 2024
56a4c5c
Merge remote-tracking branch 'origin/main'
MadStu Sep 20, 2024
2e87f80
MTDSA-23287 Shared code update
MadStu Sep 24, 2024
170cdef
MTDSA-26589 Create V7
MadStu Sep 24, 2024
3f61172
[MTDSA-26589] Update first 2 enum values
MadStu Sep 24, 2024
f238420
Update OAS
MadStu Sep 24, 2024
4d42270
Update typeOfDividend enums
MadStu Sep 24, 2024
57fb101
[MTDSA-23287] Update enums for consistency
MadStu Sep 25, 2024
d851574
[MTDSA-23287] Update lossType enums for consistency
MadStu Sep 25, 2024
cacf091
[MTDSA-23287] Update TypeOfDividend enums for consistency
MadStu Sep 25, 2024
72cbba2
[MTDSA-23287] Update chargeableEventGainsIncome enums
MadStu Sep 25, 2024
add7253
[MTDSA-23287] Update deficiencyReliefType enums
MadStu Sep 25, 2024
ccc81cf
[MTDSA-23287] Update ShareSchemeDetail enums
MadStu Sep 26, 2024
6c6fb22
[MTDSA-23287] Update TaxRegime enums
MadStu Sep 26, 2024
d2d220f
[MTDSA-23287] Update AllowancesReliefsAndDeductionsType enums
MadStu Sep 26, 2024
2b1e830
[MTDSA-23287] Update PensionContributionAndChargesType enums
MadStu Sep 26, 2024
63dccab
[MTDSA-23287] Update InputsOtherType enums
MadStu Sep 26, 2024
3fb6373
[MTDSA-23287] Update calculationReason enums
MadStu Sep 26, 2024
9c88048
Implement PR Comments
MadStu Oct 1, 2024
9627f03
Create AllowancesReliefsAndDeductionsType rename test
MadStu Oct 1, 2024
bcc192b
Tidy code alignment
MadStu Oct 1, 2024
7e42f9d
Create Tests for new enum renames
MadStu Oct 1, 2024
2c0fcc1
Reorganise TypeOfDividend Stucture
MadStu Oct 1, 2024
b71662a
Reorganise TaxRegime Stucture
MadStu Oct 1, 2024
c1c8aaf
Reorganise Source Stucture
MadStu Oct 1, 2024
f342297
Reorganise ShortServiceRefundBandName Stucture
MadStu Oct 1, 2024
307eb0b
Reorganise LossType Stucture
MadStu Oct 1, 2024
b5fe17d
Reorganise InputsOtherType Stucture
MadStu Oct 1, 2024
1aa611a
Reorganise CalculationReason Stucture
MadStu Oct 1, 2024
69e4806
Reorganise AllowancesReliefsAndDeductionsType Stucture
MadStu Oct 1, 2024
08c9b53
Reorganise PensionContributionAndChargesType Stucture
MadStu Oct 1, 2024
d40baa7
Reorganise ShareSchemeDetailType Stucture
MadStu Oct 1, 2024
75eb054
Reorganise ReliefsClaimedType Stucture
MadStu Oct 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
19 changes: 17 additions & 2 deletions app/shared/controllers/validators/resolvers/ResolveTaxYear.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ object ResolveTaxYear extends ResolverSupport {
case _ => Invalid(List(TaxYearFormatError))
}

def resolverWithCustomErrors(formatError: MtdError, rangeError: MtdError): Resolver[String, TaxYear] = {
case value @ taxYearFormat(start, end) =>
if (end.toInt - start.toInt == 1)
Valid(TaxYear.fromMtd(value))
else
Invalid(List(rangeError))

case _ => Invalid(List(formatError))
}

def apply(value: String): Validated[Seq[MtdError], TaxYear] = resolver(value)

def apply(value: Option[String]): Validated[Seq[MtdError], Option[TaxYear]] =
Expand All @@ -55,10 +65,15 @@ object ResolveTaxYear extends ResolverSupport {

}

case class ResolveTaxYearMinimum(minimumTaxYear: TaxYear, error: MtdError = RuleTaxYearNotSupportedError) extends ResolverSupport {
case class ResolveTaxYearMinimum(
minimumTaxYear: TaxYear,
notSupportedError: MtdError = RuleTaxYearNotSupportedError,
formatError: MtdError = TaxYearFormatError,
rangeError: MtdError = RuleTaxYearRangeInvalidError
) extends ResolverSupport {

val resolver: Resolver[String, TaxYear] =
ResolveTaxYear.resolver thenValidate satisfiesMin(minimumTaxYear, error)
ResolveTaxYear.resolverWithCustomErrors(formatError, rangeError) thenValidate satisfiesMin(minimumTaxYear, notSupportedError)

def apply(value: String): Validated[Seq[MtdError], TaxYear] = resolver(value)

Expand Down
8 changes: 6 additions & 2 deletions app/shared/shared-code-changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ For the Shared Code update steps, see: https://confluence.tools.tax.service.gov.

Place new items at the top, and auto-format the file...

## September 17 2024: ResolveTaxYearMinimum

Added an apply function on ResolveTaxYearMinimum to allow adding custom errors. Required in individual-losses-api.

## August 29 2024: Increased code coverage

Increased the coverage for ResolveTaxYearMinMax and ResolveDateRange so that introducing the shared code into other APIs won't
reduce their coverage % quite so much.
Increased the coverage for ResolveTaxYearMinMax and ResolveDateRange so that introducing the shared code into other APIs
won't reduce their coverage % quite so much.

## Aug 21 2024: Re-engineer BaseDownstreamConnector and DownstreamUri for HIP support

Expand Down
36 changes: 36 additions & 0 deletions app/v7/common/model/response/CalculationType.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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 v7.common.model.response

import common.utils.enums.Enums
import play.api.libs.json.{Reads, Writes}

sealed trait CalculationType

object CalculationType {

case object `in-year` extends CalculationType
case object `final-declaration` extends CalculationType

implicit val writes: Writes[CalculationType] = Enums.writes[CalculationType]

implicit val reads: Reads[CalculationType] = Enums.readsUsing[CalculationType] {
case "inYear" => `in-year`
case "crystallisation" => `final-declaration`
}

}
39 changes: 39 additions & 0 deletions app/v7/common/model/response/ChargeableEventGainsIncomeType.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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 v7.common.model.response

import common.utils.enums.Enums
import play.api.libs.json.{Reads, Writes}

sealed trait ChargeableEventGainsIncomeType

object ChargeableEventGainsIncomeType {
case object `life-insurance` extends ChargeableEventGainsIncomeType
case object `capital-redemption` extends ChargeableEventGainsIncomeType
case object `life-annuity` extends ChargeableEventGainsIncomeType
case object `voided-isa` extends ChargeableEventGainsIncomeType

implicit val writes: Writes[ChargeableEventGainsIncomeType] = Enums.writes[ChargeableEventGainsIncomeType]

implicit val reads: Reads[ChargeableEventGainsIncomeType] = Enums.readsUsing {
case "lifeInsurance" => `life-insurance`
case "capitalRedemption" => `capital-redemption`
case "lifeAnnuity" => `life-annuity`
case "voidedIsa" => `voided-isa`
}

}
43 changes: 43 additions & 0 deletions app/v7/common/model/response/ClaimType.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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 v7.common.model.response

import common.utils.enums.Enums
import play.api.libs.json.{Reads, Writes}

sealed trait ClaimType

object ClaimType {
case object `carry-forward` extends ClaimType
case object `carry-sideways` extends ClaimType
case object `carry-forward-to-carry-sideways` extends ClaimType
case object `carry-sideways-fhl` extends ClaimType
case object `carry-backwards` extends ClaimType
case object `carry-backwards-general-income` extends ClaimType

implicit val writes: Writes[ClaimType] = Enums.writes[ClaimType]

implicit val reads: Reads[ClaimType] = Enums.readsUsing {
case "CF" => `carry-forward`
case "CSGI" => `carry-sideways`
case "CFCSGI" => `carry-forward-to-carry-sideways`
case "CSFHL" => `carry-sideways-fhl`
case "CB" => `carry-backwards`
case "CBGI" => `carry-backwards-general-income`
}

}
80 changes: 80 additions & 0 deletions app/v7/common/model/response/IncomeSourceType.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* 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 v7.common.model.response

import common.utils.enums.Enums
import play.api.libs.json._

sealed trait IncomeSourceType

object IncomeSourceType {

case object `self-employment` extends IncomeSourceType
case object `uk-property-non-fhl` extends IncomeSourceType
case object `foreign-property-fhl-eea` extends IncomeSourceType
case object `uk-property-fhl` extends IncomeSourceType
case object `employments` extends IncomeSourceType
case object `foreign-income` extends IncomeSourceType
case object `foreign-dividends` extends IncomeSourceType
case object `uk-savings-and-gains` extends IncomeSourceType
case object `uk-dividends` extends IncomeSourceType
case object `state-benefits` extends IncomeSourceType
case object `gains-on-life-policies` extends IncomeSourceType
case object `share-schemes` extends IncomeSourceType
case object `foreign-property` extends IncomeSourceType
case object `foreign-savings-and-gains` extends IncomeSourceType
case object `other-dividends` extends IncomeSourceType
case object `uk-securities` extends IncomeSourceType
case object `other-income` extends IncomeSourceType
case object `foreign-pension` extends IncomeSourceType
case object `non-paye-income` extends IncomeSourceType
case object `capital-gains-tax` extends IncomeSourceType
case object `charitable-giving` extends IncomeSourceType

implicit val incomeSourceTypeWrites: Writes[IncomeSourceType] = Enums.writes[IncomeSourceType]

implicit val reads: Reads[IncomeSourceType] = Enums.readsUsing {
case "01" => `self-employment`
case "02" => `uk-property-non-fhl`
case "03" => `foreign-property-fhl-eea`
case "04" => `uk-property-fhl`
case "05" => `employments`
case "06" => `foreign-income`
case "07" => `foreign-dividends`
case "09" => `uk-savings-and-gains`
case "10" => `uk-dividends`
case "11" => `state-benefits`
case "12" => `gains-on-life-policies`
case "13" => `share-schemes`
case "15" => `foreign-property`
case "16" => `foreign-savings-and-gains`
case "17" => `other-dividends`
case "18" => `uk-securities`
case "19" => `other-income`
case "20" => `foreign-pension`
case "21" => `non-paye-income`
case "22" => `capital-gains-tax`
case "98" => `charitable-giving`
}

def formatRestricted(types: IncomeSourceType*): Format[IncomeSourceType] = new Format[IncomeSourceType] {
override def writes(o: IncomeSourceType): JsValue = incomeSourceTypeWrites.writes(o)

override def reads(json: JsValue): JsResult[IncomeSourceType] = json.validate[IncomeSourceType](Enums.readsRestricted(types: _*))
}

}
41 changes: 41 additions & 0 deletions app/v7/common/model/response/PensionBandName.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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 v7.common.model.response

import common.utils.enums.Enums
import play.api.libs.json.{Reads, Writes}

sealed trait PensionBandName

object PensionBandName {
case object `basic-rate` extends PensionBandName
case object `intermediate-rate` extends PensionBandName
case object `higher-rate` extends PensionBandName
case object `additional-rate` extends PensionBandName
case object `advanced-rate` extends PensionBandName

implicit val writes: Writes[PensionBandName] = Enums.writes[PensionBandName]

implicit val reads: Reads[PensionBandName] = Enums.readsUsing {
case "BRT" => `basic-rate`
case "IRT" => `intermediate-rate`
case "HRT" => `higher-rate`
case "ART" => `additional-rate`
case "AVRT" => `advanced-rate`
}

}
40 changes: 40 additions & 0 deletions app/v7/common/model/response/StudentLoanPlanType.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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 v7.common.model.response

import common.utils.enums.Enums
import play.api.libs.json.{Reads, Writes}

sealed trait StudentLoanPlanType

object StudentLoanPlanType {

case object `plan1` extends StudentLoanPlanType
case object `plan2` extends StudentLoanPlanType
case object `postgraduate` extends StudentLoanPlanType
case object `plan4` extends StudentLoanPlanType

implicit val writes: Writes[StudentLoanPlanType] = Enums.writes[StudentLoanPlanType]

implicit val reads: Reads[StudentLoanPlanType] = Enums.readsUsing {
case "01" => `plan1`
case "02" => `plan2`
case "03" => `postgraduate`
case "04" => `plan4`
}

}
53 changes: 53 additions & 0 deletions app/v7/listCalculations/ListCalculationsConnector.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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 v7.listCalculations

import shared.connectors.DownstreamUri.{DesUri, TaxYearSpecificIfsUri}
import shared.connectors.httpparsers.StandardDownstreamHttpParser._
import shared.connectors.{BaseDownstreamConnector, DownstreamOutcome, DownstreamUri}
import shared.config.AppConfig
import uk.gov.hmrc.http.{HeaderCarrier, HttpClient}
import v7.listCalculations.def1.model.response.Calculation
import v7.listCalculations.model.request.ListCalculationsRequestData
import v7.listCalculations.model.response.ListCalculationsResponse

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

@Singleton
class ListCalculationsConnector @Inject() (val http: HttpClient, val appConfig: AppConfig) extends BaseDownstreamConnector {

def list(request: ListCalculationsRequestData)(implicit
hc: HeaderCarrier,
ec: ExecutionContext,
correlationId: String
): Future[DownstreamOutcome[ListCalculationsResponse[Calculation]]] = {

import request._
import schema._

val downstreamUri: DownstreamUri[DownstreamResp] =
if (taxYear.useTaxYearSpecificApi) {
TaxYearSpecificIfsUri(s"income-tax/view/calculations/liability/${taxYear.asTysDownstream}/$nino")
} else {
DesUri(s"income-tax/list-of-calculation-results/$nino?taxYear=${taxYear.asDownstream}")
}

get(downstreamUri)
}

}
Loading