Skip to content

Add JSON Endpoints for /find-local-council for App to query #4710

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

Closed
wants to merge 18 commits into from

Conversation

KludgeKML
Copy link
Contributor

@KludgeKML KludgeKML commented Mar 19, 2025

⚠️ This repo is Continuously Deployed: make sure you follow the guidance ⚠️

What

Why

https://trello.com/c/YX1VcZj0/335-create-json-endpoint-version-of-find-local-council-for-app

How

Screenshots?

- although it might normally be a factory or service item, this class is relatively simple so
  we also add a method to build from a local custodian code.
- Local links manager always returns 2-tier councils with the district first, then county, so
  it's safe to rely on that order. It only ever returns 1 or 2, not found will throw a GdsApi
  error which a controller can handle reasonably.
- this promotes it into being able to be raised/caught, which the name implies it should be.
- for initial refactoring, it makes sense to encapsulate this. It's not quite a Location model
  yet, but we can improve on it later.
- Here although we're making the action a bit bigger, we're removing a lot of private code and
  turning the inverted code (where we try to get the error and work with the side-effects of that)
  into more straightforward, readable code with exception paths.
- These actually change _very_ infrequently, but 5 minutes is a common
  caching time for gov.uk, so we shouldn't introduce a surprise longer
  cache without very good reason.
- Since we do a bunch of checking in the initializer, and we can't
  call addresses without an object, it's safe to skip a bunch of
  error checking here (we know we're going to get _something_).
- We don't strictly need to make the postcode attribute readable
  outside the model, but it seems a reasonable thing to do.
- AddressListPresenter takes a list of addresses (from a PostcodeLookup) and reformats them
  to the format wanted by the component, also doing a lookup to find the slug from the lcc.
- Get rid of @addresses which was only used for the count > 6 check (we can just use the
  output from the presenter, which is more appropriate anyway)
- we don't need the SplitPostcodeSupport concern at this point.
- Refactor the making into a private class method so it can be used for response from other
  methods.
- Handle two-tier correctly - we can't always assume they'll come back in order, and we
  can't always assume the top-tier will be a county (it might occasionally be a unitary if we're
  in the middle of local-authority merges). So if there are two results, the parent will be
  whatever is not a district (usually county, sometimes unitary), and the child/singleton will
  be whatever is not a county (either a district in a two-tier, or a unitary in a one-tier).
- We will also want to load the model from a slug, so add a method to do that.
- Now we can get a proper LocalAuthority model by slug, we can simplify this method,
  and make the templates a little nicer.
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4710 March 19, 2025 17:17 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4710 March 19, 2025 17:38 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4710 March 19, 2025 17:39 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4710 March 20, 2025 09:28 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4710 March 20, 2025 10:20 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4710 March 20, 2025 11:28 Inactive
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4710 March 20, 2025 15:15 Inactive
@KludgeKML KludgeKML changed the title WIP Add JSON Endpoints for /find-local-council for App to query Mar 20, 2025
@govuk-ci govuk-ci temporarily deployed to govuk-frontend-app-pr-4710 March 24, 2025 13:58 Inactive
@KludgeKML KludgeKML force-pushed the refactor-find-my-council branch from 57cd120 to 4c1ffff Compare March 24, 2025 14:41
Base automatically changed from refactor-find-my-council to main March 25, 2025 12:19
@KludgeKML
Copy link
Contributor Author

Closing in favour of this: #4720

@KludgeKML KludgeKML closed this Apr 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants