-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Cleaning up endpoints and responses
- Loading branch information
1 parent
6ae6a7f
commit dd5dfb7
Showing
13 changed files
with
296 additions
and
102 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
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,19 @@ | ||
/* | ||
* Copyright 2017 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.epayeapi.models | ||
|
||
case class AggregatedTotals(credit: BigDecimal, debit: BigDecimal) |
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
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
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,65 @@ | ||
/* | ||
* Copyright 2017 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.epayeapi.models | ||
|
||
object Example extends App { | ||
import scala.concurrent.ExecutionContext.Implicits.global | ||
import scala.concurrent.Future | ||
import scala.concurrent.Await | ||
import scala.concurrent.duration.Duration | ||
import scala.util.{Success, Failure} | ||
|
||
sealed trait Resp | ||
case class Good(i: Int) extends Resp | ||
case class Bad(s: String) extends Resp | ||
|
||
object Foo { | ||
def run: Int = { | ||
val first: Future[Resp] = Future.successful(Good(1)) | ||
val econd: Future[Resp] = Future.successful(Bad("nope")) | ||
|
||
|
||
val res = for { | ||
Good(one) <- first | ||
Good(two) <- econd | ||
} yield Good(one + two) | ||
|
||
// | ||
// res.onComplete { | ||
// case Success(res) => | ||
// println("OK") | ||
// res | ||
// case Failure(res) => | ||
// println(s"Fail: $res") | ||
// res | ||
// } | ||
|
||
val finalREsult: Resp = Await.result(res.recover { | ||
case ex: Exception => | ||
println(ex) | ||
Bad("Exception handler") | ||
}, Duration.Inf) | ||
|
||
println(s"Final: $finalREsult") | ||
|
||
100 | ||
} | ||
} | ||
|
||
Foo.run | ||
|
||
} |
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
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,31 @@ | ||
/* | ||
* Copyright 2017 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.epayeapi.models | ||
|
||
import uk.gov.hmrc.domain.EmpRef | ||
|
||
case class Link(href: String) | ||
|
||
object Link { | ||
val prefix = "/organisation/paye" | ||
|
||
def summaryLink(empRef: EmpRef): Link = | ||
Link(s"$prefix/${empRef.taxOfficeNumber}/${empRef.taxOfficeReference}/") | ||
|
||
def empRefsLink(): Link = | ||
Link(s"$prefix/") | ||
} |
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,76 @@ | ||
/* | ||
* Copyright 2017 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.epayeapi.models | ||
|
||
import uk.gov.hmrc.domain.EmpRef | ||
|
||
case class Breakdown( | ||
rti: BigDecimal, | ||
nonRti: BigDecimal | ||
) | ||
|
||
case class OutstandingCharges( | ||
amount: BigDecimal, | ||
breakdown: Breakdown | ||
) | ||
|
||
case class SummaryResponse( | ||
outstandingCharges: OutstandingCharges, | ||
_links: SummaryLinks | ||
) | ||
|
||
object SummaryResponse { | ||
def apply(empRef: EmpRef, totals: AggregatedTotals, byType: AggregatedTotalsByType): SummaryResponse = | ||
SummaryResponse( | ||
OutstandingCharges( | ||
totals.debit, | ||
Breakdown( | ||
byType.rti.debit, | ||
byType.nonRti.debit | ||
) | ||
), | ||
SummaryLinks(empRef) | ||
) | ||
} | ||
|
||
case class TotalsByTypeResponse( | ||
rti: AggregatedTotals, | ||
non_rti: AggregatedTotals, | ||
_links: SummaryLinks | ||
) | ||
|
||
object TotalsByTypeResponse { | ||
def apply(empRef: EmpRef, totals: AggregatedTotalsByType): TotalsByTypeResponse = | ||
TotalsByTypeResponse( | ||
AggregatedTotals(totals.rti.credit, totals.rti.debit), | ||
AggregatedTotals(totals.nonRti.credit, totals.nonRti.debit), | ||
SummaryLinks(empRef) | ||
) | ||
} | ||
|
||
case class SummaryLinks( | ||
empRefs: Link, | ||
self: Link | ||
) | ||
|
||
object SummaryLinks { | ||
def apply(empRef: EmpRef): SummaryLinks = SummaryLinks( | ||
Link.empRefsLink(), | ||
Link.summaryLink(empRef) | ||
) | ||
} | ||
|
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
Oops, something went wrong.