Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ARS-430: Save submitted answers (#29)
- Loading branch information
1 parent
e862bbf
commit d02634c
Showing
30 changed files
with
747 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
app/uk/gov/hmrc/advancevaluationrulings/controllers/package.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* 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 uk.gov.hmrc.advancevaluationrulings | ||
|
||
import scala.concurrent.Future | ||
import scala.util.{Failure, Success, Try} | ||
|
||
import play.api.libs.json._ | ||
import play.api.mvc.{Request, Result, Results} | ||
import uk.gov.hmrc.advancevaluationrulings.logging.RequestAwareLogger | ||
import uk.gov.hmrc.advancevaluationrulings.models.common.Statuses | ||
import uk.gov.hmrc.advancevaluationrulings.models.errors.{ErrorResponse, ValidationError, ValidationErrors} | ||
import uk.gov.hmrc.http.HeaderCarrier | ||
|
||
package object controllers { | ||
|
||
protected lazy val logger: RequestAwareLogger = new RequestAwareLogger(this.getClass) | ||
|
||
def extractFromJson[T]( | ||
func: T => Future[Result] | ||
)(implicit request: Request[JsValue], reads: Reads[T], hc: HeaderCarrier): Future[Result] = { | ||
logger.warn(s"Received json request: ${Json.prettyPrint(request.body)}") | ||
Try(request.body.validate[T]) match { | ||
case Success(JsSuccess(payload, _)) => func(payload) | ||
case Success(JsError(errors)) => | ||
val failureReason = errors | ||
.map { case (path, _) => s"field at path: [$path] missing or invalid" } | ||
.mkString(", ") | ||
toBadRequest(failureReason) | ||
case Failure(e) => | ||
toBadRequest(e.getMessage) | ||
} | ||
} | ||
|
||
private def toBadRequest(errorMessage: String)(implicit hc: HeaderCarrier) = { | ||
logger.warn(s"Failed to extract case class from Json: $errorMessage") | ||
Future.successful( | ||
Results.BadRequest( | ||
Json.toJson( | ||
ErrorResponse( | ||
Statuses.ValidationFailed, | ||
ValidationErrors(Seq(ValidationError(errorMessage))) | ||
) | ||
) | ||
) | ||
) | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
app/uk/gov/hmrc/advancevaluationrulings/models/ValuationRulingsApplication.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* 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 uk.gov.hmrc.advancevaluationrulings.models | ||
|
||
import java.time.Instant | ||
|
||
import play.api.libs.json._ | ||
import uk.gov.hmrc.advancevaluationrulings.models.common.UserAnswers | ||
import uk.gov.hmrc.mongo.play.json.formats.MongoJavatimeFormats | ||
|
||
final case class ValuationRulingsApplication( | ||
id: String, | ||
data: UserAnswers, | ||
applicationNumber: String, | ||
lastUpdated: Instant | ||
) | ||
|
||
object ValuationRulingsApplication { | ||
|
||
val reads: Reads[ValuationRulingsApplication] = { | ||
|
||
import play.api.libs.functional.syntax._ | ||
|
||
( | ||
(__ \ "_id").read[String] and | ||
(__ \ "data").read[UserAnswers] and | ||
(__ \ "applicationNumber").read[String] and | ||
(__ \ "lastUpdated").read(MongoJavatimeFormats.instantFormat) | ||
)(ValuationRulingsApplication.apply _) | ||
} | ||
|
||
val writes: OWrites[ValuationRulingsApplication] = { | ||
|
||
import play.api.libs.functional.syntax._ | ||
|
||
( | ||
(__ \ "_id").write[String] and | ||
(__ \ "data").write[UserAnswers] and | ||
(__ \ "applicationNumber").write[String] and | ||
(__ \ "lastUpdated").write(MongoJavatimeFormats.instantFormat) | ||
)(unlift(ValuationRulingsApplication.unapply)) | ||
} | ||
|
||
implicit val format: OFormat[ValuationRulingsApplication] = OFormat(reads, writes) | ||
} |
29 changes: 29 additions & 0 deletions
29
app/uk/gov/hmrc/advancevaluationrulings/models/common/ApplicationContactDetails.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* 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 uk.gov.hmrc.advancevaluationrulings.models.common | ||
|
||
import play.api.libs.json.{Json, OFormat} | ||
|
||
final case class ApplicationContactDetails( | ||
name: String, | ||
email: String, | ||
phone: String | ||
) | ||
|
||
object ApplicationContactDetails { | ||
implicit val format: OFormat[ApplicationContactDetails] = Json.format[ApplicationContactDetails] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
app/uk/gov/hmrc/advancevaluationrulings/models/common/LastUpdatedTime.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* 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 uk.gov.hmrc.advancevaluationrulings.models.common | ||
|
||
import play.api.libs.json.Format | ||
import uk.gov.hmrc.mongo.play.json.formats.MongoJavatimeFormats | ||
|
||
import java.time.Instant | ||
|
||
final case class LastUpdatedTime(value: Instant) | ||
|
||
object LastUpdatedTime { | ||
implicit val format: Format[Instant] = MongoJavatimeFormats.instantFormat | ||
} |
33 changes: 33 additions & 0 deletions
33
app/uk/gov/hmrc/advancevaluationrulings/models/common/RegisteredDetailsCheck.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 uk.gov.hmrc.advancevaluationrulings.models.common | ||
|
||
import play.api.libs.json.{Json, OFormat} | ||
|
||
final case class RegisteredDetailsCheck( | ||
value: Boolean, | ||
eori: String, | ||
name: String, | ||
streetAndNumber: String, | ||
city: String, | ||
country: String, | ||
postalCode: Option[String] | ||
) | ||
|
||
object RegisteredDetailsCheck { | ||
implicit val format: OFormat[RegisteredDetailsCheck] = Json.format[RegisteredDetailsCheck] | ||
} |
29 changes: 29 additions & 0 deletions
29
app/uk/gov/hmrc/advancevaluationrulings/models/common/Statuses.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* 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 uk.gov.hmrc.advancevaluationrulings.models.common | ||
|
||
object Statuses { | ||
|
||
val ApplicationSubmitted = "ApplicationSubmitted" | ||
val SubmissionFailed = "SubmissionFailed" | ||
val ConnectorError = "ConnectorError" | ||
val UpstreamServiceError = "UpstreamServiceError" | ||
val SerializationError = "SerializationError" | ||
val ParseError = "ParseError" | ||
val ValidationFailed = "ValidationFailed" | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
app/uk/gov/hmrc/advancevaluationrulings/models/common/SubmissionSuccess.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* 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 uk.gov.hmrc.advancevaluationrulings.models.common | ||
|
||
import play.api.libs.json.{Json, OFormat} | ||
|
||
final case class SubmissionSuccess( | ||
acknowledged: Boolean, | ||
status: String = Statuses.ApplicationSubmitted | ||
) | ||
|
||
object SubmissionSuccess { | ||
implicit val format: OFormat[SubmissionSuccess] = Json.format[SubmissionSuccess] | ||
} |
29 changes: 29 additions & 0 deletions
29
app/uk/gov/hmrc/advancevaluationrulings/models/common/SupportingDocument.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* 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 uk.gov.hmrc.advancevaluationrulings.models.common | ||
|
||
import play.api.libs.json.{Json, OFormat} | ||
|
||
final case class SupportingDocument( | ||
fileName: String, | ||
downloadUrl: String, | ||
isConfidential: Boolean | ||
) | ||
|
||
object SupportingDocument { | ||
implicit val format: OFormat[SupportingDocument] = Json.format[SupportingDocument] | ||
} |
Oops, something went wrong.