Skip to content

Commit

Permalink
Merge pull request #40 from hmrc/feature/relative-links
Browse files Browse the repository at this point in the history
YTA-3213: Modifying relative links to exclude the base part of the url.
  • Loading branch information
flashingpumpkin authored Feb 19, 2018
2 parents 6f6b2ec + 35211a2 commit 7dcce1c
Show file tree
Hide file tree
Showing 24 changed files with 124 additions and 139 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ case class GetEmpRefsController @Inject() (
def successHandler: PartialFunction[EpayeResponse[EpayeEmpRefsResponse], Result] = {
case EpayeSuccess(EpayeEmpRefsResponse(empRefs)) =>
Logger.error(s"EmpRefs received: $empRefs")
val empRefsJson = EmpRefsJson.fromSeq(config.apiBaseUrl, empRefs)
val empRefsJson = EmpRefsJson.fromSeq(empRefs)
Ok(Json.toJson(empRefsJson))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ case class GetStatementsController @Inject()(

def successHandler(empRef: EmpRef): PartialFunction[EpayeResponse[EpayeMasterData], Result] = {
case EpayeSuccess(EpayeMasterData(_, yearRegistered)) =>
val statements = StatementsJson(config.apiBaseUrl, empRef, yearRegistered)
val statements = StatementsJson(empRef, yearRegistered)
Ok(Json.toJson(statements))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ case class GetSummaryController @Inject() (

def successHandler(empRef: EmpRef): PartialFunction[EpayeResponse[EpayeTotalsResponse], Result] = {
case EpayeSuccess(totals) =>
Ok(Json.toJson(SummaryJson(config.apiBaseUrl, empRef, totals)))
Ok(Json.toJson(SummaryJson(empRef, totals)))
}
}
16 changes: 8 additions & 8 deletions app/uk/gov/hmrc/epayeapi/models/out/AnnualStatementJson.scala
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ case class MonthlyChargesJson(

object MonthlyChargesJson {

def from(apiBaseUrl: String, lineItem: LineItem, empRef: EmpRef, taxYear: TaxYear): Option[MonthlyChargesJson] = {
def from(lineItem: LineItem, empRef: EmpRef, taxYear: TaxYear): Option[MonthlyChargesJson] = {
for {
epayeTaxMonth <- lineItem.taxMonth
taxMonth = TaxMonth(taxYear, epayeTaxMonth.month)
Expand All @@ -107,7 +107,7 @@ object MonthlyChargesJson {
balance = lineItem.balance,
dueDate = lineItem.dueDate,
isSpecified = lineItem.isSpecified,
_links = SelfLink(Link.monthlyStatementLink(apiBaseUrl, empRef, taxYear, taxMonth))
_links = SelfLink(Link.monthlyStatementLink(empRef, taxYear, taxMonth))
)
}
}
Expand Down Expand Up @@ -137,15 +137,15 @@ object AnnualStatementJson {
taxYear = taxYear,
_embedded = EmbeddedRtiChargesJson(
EarlierYearUpdateJson.extractFrom(epayeAnnualStatement.rti.lineItems),
epayeAnnualStatement.rti.lineItems.flatMap(MonthlyChargesJson.from(apiBaseUrl, _, empRef, taxYear))
epayeAnnualStatement.rti.lineItems.flatMap(MonthlyChargesJson.from(_, empRef, taxYear))
),
nonRtiCharges = epayeAnnualStatement.nonRti.lineItems.flatMap(NonRtiChargesJson.from(_, taxYear)),
_links = AnnualStatementLinksJson(
empRefs = Link.empRefsLink(apiBaseUrl),
statements = Link.statementsLink(apiBaseUrl, empRef),
self = Link.anualStatementLink(apiBaseUrl, empRef, taxYear),
next = Link.anualStatementLink(apiBaseUrl, empRef, taxYear.next),
previous = Link.anualStatementLink(apiBaseUrl, empRef, taxYear.previous)
empRefs = Link.empRefsLink,
statements = Link.statementsLink(empRef),
self = Link.anualStatementLink(empRef, taxYear),
next = Link.anualStatementLink(empRef, taxYear.next),
previous = Link.anualStatementLink(empRef, taxYear.previous)
)
)

Expand Down
23 changes: 10 additions & 13 deletions app/uk/gov/hmrc/epayeapi/models/out/EmpRefsJson.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,23 @@ case class EmbeddedEmpRefs(
)

object EmpRefsJson {
def fromSeq(apiBaseUrl: String, seq: Seq[EmpRef]): EmpRefsJson =
EmpRefsJson(EmbeddedEmpRefs(seq.map(EmpRefItem(apiBaseUrl, _))), EmpRefsLinks(apiBaseUrl))
def fromSeq(seq: Seq[EmpRef]): EmpRefsJson =
EmpRefsJson(EmbeddedEmpRefs(seq.map(EmpRefItem(_))), EmpRefsLinks())

def apply(apiBaseUrl: String, empRef: EmpRef): EmpRefsJson =
fromSeq(apiBaseUrl, Seq(empRef))
def apply(empRef: EmpRef): EmpRefsJson = fromSeq(Seq(empRef))
}

case class EmpRefItem(taxOfficeNumber: String, taxOfficeReference: String, _links: EmpRefLinks)

object EmpRefItem {
def apply(apiBaseUrl: String, empRef: EmpRef): EmpRefItem =
EmpRefItem(empRef.taxOfficeNumber, empRef.taxOfficeReference, EmpRefLinks(apiBaseUrl, empRef))
def apply(empRef: EmpRef): EmpRefItem =
EmpRefItem(empRef.taxOfficeNumber, empRef.taxOfficeReference, EmpRefLinks(empRef))
}

case class EmpRefsLinks(self: Link)

object EmpRefsLinks {
def apply(apiBaseUrl: String): EmpRefsLinks =
new EmpRefsLinks(self = Link.empRefsLink(apiBaseUrl))
def apply(): EmpRefsLinks = new EmpRefsLinks(self = Link.empRefsLink)
}

case class EmpRefLinks(
Expand All @@ -58,12 +56,11 @@ case class EmpRefLinks(
)

object EmpRefLinks {
def apply(apiBaseUrl: String, empRef: EmpRef): EmpRefLinks =
def apply(empRef: EmpRef): EmpRefLinks =
EmpRefLinks(
self = Link.summaryLink(apiBaseUrl, empRef),
statements = Link.statementsLink(apiBaseUrl, empRef),
currentStatement = Link.anualStatementLink(apiBaseUrl, empRef, taxYear = TaxYear(TaxYearResolver.currentTaxYear))
self = Link.summaryLink(empRef),
statements = Link.statementsLink(empRef),
currentStatement = Link.anualStatementLink(empRef, TaxYear(TaxYearResolver.currentTaxYear))
)
// EmpRefLinks(summary = Link.summaryLink(apiBaseUrl, empRef))
}

20 changes: 10 additions & 10 deletions app/uk/gov/hmrc/epayeapi/models/out/Link.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ case class Link(href: String)
object Link {
val prefix = "/organisations/paye"

def empRefsLink(apiBaseUrl: String): Link =
Link(s"$apiBaseUrl$prefix/")
def empRefsLink: Link =
Link(s"$prefix/")

def summaryLink(apiBaseUrl: String, empRef: EmpRef): Link =
Link(s"$apiBaseUrl$prefix/${empRef.taxOfficeNumber}/${empRef.taxOfficeReference}")
def summaryLink(empRef: EmpRef): Link =
Link(s"$prefix/${empRef.taxOfficeNumber}/${empRef.taxOfficeReference}")

def statementsLink(apiBaseUrl: String, empRef: EmpRef): Link =
Link(s"$apiBaseUrl$prefix/${empRef.taxOfficeNumber}/${empRef.taxOfficeReference}/statements")
def statementsLink(empRef: EmpRef): Link =
Link(s"$prefix/${empRef.taxOfficeNumber}/${empRef.taxOfficeReference}/statements")

def anualStatementLink(apiBaseUrl: String, empRef: EmpRef, taxYear: TaxYear): Link =
Link(s"$apiBaseUrl$prefix/${empRef.taxOfficeNumber}/${empRef.taxOfficeReference}/statements/${taxYear.asString}")
def anualStatementLink(empRef: EmpRef, taxYear: TaxYear): Link =
Link(s"$prefix/${empRef.taxOfficeNumber}/${empRef.taxOfficeReference}/statements/${taxYear.asString}")

def monthlyStatementLink(apiBaseUrl: String, empRef: EmpRef, taxYear: TaxYear, taxMonth: TaxMonth): Link =
Link(s"$apiBaseUrl$prefix/${empRef.taxOfficeNumber}/${empRef.taxOfficeReference}/statements/${taxYear.asString}/${taxMonth.asString}")
def monthlyStatementLink(empRef: EmpRef, taxYear: TaxYear, taxMonth: TaxMonth): Link =
Link(s"$prefix/${empRef.taxOfficeNumber}/${empRef.taxOfficeReference}/statements/${taxYear.asString}/${taxMonth.asString}")
}
16 changes: 8 additions & 8 deletions app/uk/gov/hmrc/epayeapi/models/out/MonthlyStatementJson.scala
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ object MonthlyStatementJson {
writeOffs = Charges(json.writeOffs),
dueDate = json.balance.dueDate,
summary = MonthlySummaryJson(json),
_links = MonthlyStatementLinksJson(apiBaseUrl, empRef, taxYear, taxMonth)
_links = MonthlyStatementLinksJson(empRef, taxYear, taxMonth)
)
}

Expand Down Expand Up @@ -123,19 +123,19 @@ object MonthlySummaryJson {
}

object MonthlyStatementLinksJson {
def apply(apiBaseUrl: String, empRef: EmpRef, taxYear: TaxYear, taxMonth: TaxMonth): MonthlyStatementLinksJson =
def apply(empRef: EmpRef, taxYear: TaxYear, taxMonth: TaxMonth): MonthlyStatementLinksJson =
MonthlyStatementLinksJson(
empRefs =
Link.empRefsLink(apiBaseUrl),
Link.empRefsLink,
statements =
Link.summaryLink(apiBaseUrl, empRef),
Link.summaryLink(empRef),
annualStatement =
Link.anualStatementLink(apiBaseUrl, empRef, taxYear),
Link.anualStatementLink(empRef, taxYear),
self =
Link.monthlyStatementLink(apiBaseUrl, empRef, taxYear, taxMonth),
Link.monthlyStatementLink(empRef, taxYear, taxMonth),
next =
Link.monthlyStatementLink(apiBaseUrl, empRef, if (taxMonth.isLast) taxYear.next else taxYear, taxMonth.next),
Link.monthlyStatementLink(empRef, if (taxMonth.isLast) taxYear.next else taxYear, taxMonth.next),
previous =
Link.monthlyStatementLink(apiBaseUrl, empRef, if (taxMonth.isFirst) taxYear.previous else taxYear, taxMonth.previous)
Link.monthlyStatementLink(empRef, if (taxMonth.isFirst) taxYear.previous else taxYear, taxMonth.previous)
)
}
8 changes: 4 additions & 4 deletions app/uk/gov/hmrc/epayeapi/models/out/StatementsJson.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ case class Links(
)

object StatementsJson {
def apply(apiBaseUrl: String, empRef: EmpRef, taxYearOfRegistration: Option[TaxYear]): StatementsJson = {
def apply(empRef: EmpRef, taxYearOfRegistration: Option[TaxYear]): StatementsJson = {
def taxYearStatement(taxYear: TaxYear): Statement = {
Statement(
taxYear = taxYear,
_links = StatementLinks(self = Link.anualStatementLink(apiBaseUrl, empRef, taxYear))
_links = StatementLinks(self = Link.anualStatementLink(empRef, taxYear))
)
}

Expand All @@ -61,8 +61,8 @@ object StatementsJson {
} yield taxYearStatement(taxYear)

val links = Links(
empRefs = Link.empRefsLink(apiBaseUrl),
self = Link.statementsLink(apiBaseUrl, empRef)
empRefs = Link.empRefsLink,
self = Link.statementsLink(empRef)
)

StatementsJson(
Expand Down
10 changes: 5 additions & 5 deletions app/uk/gov/hmrc/epayeapi/models/out/SummaryJson.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ case class SummaryJson(
)

object SummaryJson {
def apply(apiBaseUrl: String, empRef: EmpRef, total: EpayeTotalsResponse): SummaryJson =
def apply(empRef: EmpRef, total: EpayeTotalsResponse): SummaryJson =
SummaryJson(
OutstandingCharges(
total.overall,
Expand All @@ -44,7 +44,7 @@ object SummaryJson {
nonRti = total.nonRti.totals.balance
)
),
SummaryLinks(apiBaseUrl, empRef)
SummaryLinks(empRef)
)
}

Expand All @@ -54,9 +54,9 @@ case class SummaryLinks(
)

object SummaryLinks {
def apply(apiBaseUrl: String, empRef: EmpRef): SummaryLinks = SummaryLinks(
Link.empRefsLink(apiBaseUrl),
Link.summaryLink(apiBaseUrl, empRef)
def apply(empRef: EmpRef): SummaryLinks = SummaryLinks(
Link.empRefsLink,
Link.summaryLink(empRef)
)
}

12 changes: 6 additions & 6 deletions resources/public/api/conf/1.0/examples/AnnualStatement.get.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,27 @@
"isSpecified": false,
"_links": {
"self": {
"href": "https://api.service.hmrc.gov.uk/organisations/paye/001/AB00001/statements/2016-17/4"
"href": "/organisations/paye/001/AB00001/statements/2016-17/4"
}
}
}
]
},
"_links": {
"empRefs": {
"href": "https://api.service.hmrc.gov.uk/organisations/paye/"
"href": "/organisations/paye/"
},
"statements": {
"href": "https://api.service.hmrc.gov.uk/organisations/paye/001/AB00001/statements"
"href": "/organisations/paye/001/AB00001/statements"
},
"self": {
"href": "https://api.service.hmrc.gov.uk/organisations/paye/001/AB00001/statements/2016-17"
"href": "/organisations/paye/001/AB00001/statements/2016-17"
},
"next": {
"href": "https://api.service.hmrc.gov.uk/organisations/paye/001/AB00001/statements/2017-18"
"href": "/organisations/paye/001/AB00001/statements/2017-18"
},
"previous": {
"href": "https://api.service.hmrc.gov.uk/organisations/paye/001/AB00001/statements/2015-16"
"href": "/organisations/paye/001/AB00001/statements/2015-16"
}
}
}
14 changes: 7 additions & 7 deletions resources/public/api/conf/1.0/examples/Epaye.get.array.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
"taxOfficeReference": "AB00001",
"_links": {
"self": {
"href": "https://api.service.hmrc.gov.uk/organisations/paye/001/AB00001"
"href": "/organisations/paye/001/AB00001"
},
"statements": {
"href": "https://api.service.hmrc.gov.uk/organisations/paye/001/AB00001/statements"
"href": "/organisations/paye/001/AB00001/statements"
},
"currentStatement": {
"href": "https://api.service.hmrc.gov.uk/organisations/paye/001/AB00001/statements/2017-18"
"href": "/organisations/paye/001/AB00001/statements/2017-18"
}
}
},
Expand All @@ -21,21 +21,21 @@
"taxOfficeReference": "CD00002",
"_links": {
"self": {
"href": "https://api.service.hmrc.gov.uk/organisations/paye/001/CD00002"
"href": "/organisations/paye/001/CD00002"
},
"statements": {
"href": "https://api.service.hmrc.gov.uk/organisations/paye/001/CD00002/statements"
"href": "/organisations/paye/001/CD00002/statements"
},
"currentStatement": {
"href": "https://api.service.hmrc.gov.uk/organisations/paye/001/CD00002/statements/2017-18"
"href": "/organisations/paye/001/CD00002/statements/2017-18"
}
}
}
]
},
"_links": {
"self": {
"href": "https://api.service.hmrc.gov.uk/organisations/paye/"
"href": "/organisations/paye/"
}
}
}
12 changes: 6 additions & 6 deletions resources/public/api/conf/1.0/examples/MonthlyStatement.get.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,24 @@

"_links": {
"empRefs": {
"href": "https://api.service.hmrc.gov.uk/organisations/paye/"
"href": "/organisations/paye/"
},
"statements": {
"href": "https://api.service.hmrc.gov.uk/organisations/paye/001/AB00001/statements"
"href": "/organisations/paye/001/AB00001/statements"
},
"annualStatement": {
"href": "https://api.service.hmrc.gov.uk/organisations/paye/001/AB00001/statements/2016-17"
"href": "/organisations/paye/001/AB00001/statements/2016-17"
},

"self": {
"href": "https://api.service.hmrc.gov.uk/organisations/paye/001/AB00001/statements/2016-17/3"
"href": "/organisations/paye/001/AB00001/statements/2016-17/3"
},

"next": {
"href": "https://api.service.hmrc.gov.uk/organisations/paye/001/AB00001/statements/2016-17/2"
"href": "/organisations/paye/001/AB00001/statements/2016-17/2"
},
"previous": {
"href": "https://api.service.hmrc.gov.uk/organisations/paye/001/AB00001/statements/2016-17/4"
"href": "/organisations/paye/001/AB00001/statements/2016-17/4"
}
}
}
10 changes: 5 additions & 5 deletions resources/public/api/conf/1.0/examples/Statements.get.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"_links": {
"self": {
"href": "https://api.service.hmrc.gov.uk/organisations/paye/001/AB00001/statements/2016-17"
"href": "/organisations/paye/001/AB00001/statements/2016-17"
}
}
}, {
Expand All @@ -19,7 +19,7 @@
},
"_links": {
"self": {
"href": "https://api.service.hmrc.gov.uk/organisations/paye/001/AB00001/statements/2015-16"
"href": "/organisations/paye/001/AB00001/statements/2015-16"
}
}
}, {
Expand All @@ -30,17 +30,17 @@
},
"_links": {
"self": {
"href": "https://api.service.hmrc.gov.uk/organisations/paye/001/AB00001/statements/2014-15"
"href": "/organisations/paye/001/AB00001/statements/2014-15"
}
}
}]
},
"_links": {
"empRefs": {
"href": "https://api.service.hmrc.gov.uk/organisations/paye/"
"href": "/organisations/paye/"
},
"self": {
"href": "https://api.service.hmrc.gov.uk/organisations/paye/001/AB00001/statements"
"href": "/organisations/paye/001/AB00001/statements"
}
}
}
4 changes: 2 additions & 2 deletions resources/public/api/conf/1.0/examples/Summary.get.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
},
"_links": {
"empRefs": {
"href": "https://api.service.hmrc.gov.uk/organisations/paye/"
"href": "/organisations/paye/"
},
"self": {
"href": "https://api.service.hmrc.gov.uk/organisations/paye/001/AB00001"
"href": "/organisations/paye/001/AB00001"
}
}
}
Loading

0 comments on commit 7dcce1c

Please sign in to comment.