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

Academies database connection - add search provider #168

Conversation

lookupdaily
Copy link
Contributor

@lookupdaily lookupdaily commented Oct 9, 2023

This change swaps the search functionality in the TrustProvider and TrustSearch classes of the project for a new TrustSearch class in the AcademiesDb project - as search will now be handled with a query to the database.

Also added the missing properties Uid and GroupId into the search results listing, replacing Ukprn, as these are the identifiers we have decided to show in our design.

This is related to User Story 134572: Build: Connect to Academies DB

Changes

  • Move TrustSearch and Trust related interfaces to new Dfe.FindInformationAcademiesTrusts.Data project. This will hold all interfaces which will be used by the Dfe.FindInformationAcademiesTrusts.Db project
  • Create new TrustSearch provider in the Academies Db project, responsible for fetching search result using query.
  • Update trust search response to include correct properties
  • Remove properties which are not to be included in the search results list: Ukprn and Number of academies in trust
  • Add a mock db context class to mock the Academies db context

Screenshots of UI changes

Before

Screenshot of search results page with old properties

After

Add screenshot of updated search results page

Checklist

  • Update Azure secrets with db connection string
  • Deploy this branch to the test environment for manual testing once comments have been resolved and checks have passed
  • Attach this pull request to the appropriate user story in Azure DevOps
  • Update the ADR decision log if needed

dynamictulip and others added 16 commits October 3, 2023 17:41
This project will house interfaces implemented by data providers and types used by data consumers. As this project is intended to only be for interfaces and POCOs there is no need for an associated unit test project

Add project reference to AcademiesDb project.
Moq and Fluent Assertions. Add to global usings
We will use this to help mock our dbcontext.
Create new class in `Dfe.FindInformationAcademiesTrusts.Db` which will handle trust search. This should pass our exisitng tests for `TrustSearch`, so have moved these to `Dfe.FindInformationAcademiesTrusts.Db.UnitTests` with a MockDbContext to mock our connection to the database.

We have changed the tests/implementation for an empty search term to return an empty list, before calling the database.

We will need to add additional tests and implementation for the following:
- Trust search entry should include an address
- Trust search entry should include identifiers
Move address formatter from trust provider to new Trust Helper utility class.

Add address to search response.
Swap 'GetTrustsByName' to use new Academies Db `TrustSearch`.

Get Trusts by Ukprn still uses the trust provider for now
The unique identifier for trusts will now be 'GroupId' or 'Trn' - naming this 'Uid' as this will be the unique identifier we use for trusts.

This has currently only been renamed in the 'TrustSearchEntry' model, but would need renaming in the route query params for trust pages, and on the search results ui.
This was removed from our designs, as it was deemed not necessary for a search result.
Now that we have the connection to the academies Database we will use the Uid as the unique identifier rather than ukprn, so changing this on the search results page, and in page routing properties.

This will cause any 'GetTrustByUkprn' requests to fail on search and trust pages, and will need to be replaced by a new method to fetch trust by UID, calling the database.
The DI framework registers the `academiesDbContext` through `builder.Services.AddDbContext` which doesn't associate it with the `IAcademiesDbContext` interface that we use for testing. We've added a second constructor to allow the DI container to instantiate `TrustSearch` and set it to call the constructor that we use in testing
LINQ cannot translate `string.contains(..., StringComparison.InvariantCultureIgnoreCase)` into SQL. As the standard `string.contains(..)` is translated to case insensitive sql by default we are using that instead.

Also:
- Added `Take(20)` to protect the database from returning thousands of items
- Add tests to check that only the first 20 results are returned
- Refactor tests:
  - Move address test setup into test, as it is not needed in the constructor
  - create method to generate and setup a dbcontext response for a list of trusts with any length.
Trust search results should be ordered alphabetically by name.

The ordering should take place before taking the first 20, to ensure the first 20 alphabetical results are returned. We may want to add further tests for this.
@lookupdaily lookupdaily temporarily deployed to development October 9, 2023 08:39 — with GitHub Actions Inactive
@lookupdaily lookupdaily temporarily deployed to development October 9, 2023 08:42 — with GitHub Actions Inactive
@lookupdaily lookupdaily temporarily deployed to development October 9, 2023 09:43 — with GitHub Actions Inactive
@lookupdaily lookupdaily temporarily deployed to development October 9, 2023 09:46 — with GitHub Actions Inactive
@lookupdaily lookupdaily changed the title Academies db connection - add search provider Academies database connection - add search provider Oct 9, 2023
@lookupdaily lookupdaily marked this pull request as ready for review October 9, 2023 10:56
@dynamictulip dynamictulip temporarily deployed to test October 9, 2023 14:33 — with GitHub Actions Inactive
@dynamictulip dynamictulip temporarily deployed to test October 9, 2023 14:36 — with GitHub Actions Inactive
@lookupdaily lookupdaily temporarily deployed to development October 9, 2023 14:57 — with GitHub Actions Inactive
@lookupdaily lookupdaily temporarily deployed to development October 9, 2023 14:57 — with GitHub Actions Inactive
… groups

We only want to return single and multi academy trusts so we need to filter out all other group types including Trust.
GroupUid and GroupId are never null for single and multi academy trusts but we should still check as they are nullable fields and we want to use non nullable C# properties.
@nwarms nwarms temporarily deployed to development October 9, 2023 15:43 — with GitHub Actions Inactive
@nwarms nwarms temporarily deployed to development October 9, 2023 15:46 — with GitHub Actions Inactive
@nwarms nwarms temporarily deployed to development October 9, 2023 15:47 — with GitHub Actions Inactive
@nwarms nwarms temporarily deployed to development October 9, 2023 15:50 — with GitHub Actions Inactive
…test data.

This is because of a previous change where these field could no longer be null. Because of this no results were being returned when we did not populate these properties.
@nwarms nwarms temporarily deployed to development October 9, 2023 16:04 — with GitHub Actions Inactive
@nwarms nwarms temporarily deployed to development October 9, 2023 16:07 — with GitHub Actions Inactive
@dynamictulip dynamictulip temporarily deployed to development October 11, 2023 10:01 — with GitHub Actions Inactive
@dynamictulip dynamictulip temporarily deployed to development October 11, 2023 10:04 — with GitHub Actions Inactive
@dynamictulip dynamictulip temporarily deployed to development October 11, 2023 10:26 — with GitHub Actions Inactive
@dynamictulip dynamictulip temporarily deployed to development October 11, 2023 10:29 — with GitHub Actions Inactive
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@dynamictulip dynamictulip merged commit 2eff22a into academies-db-connection-feature Oct 11, 2023
@dynamictulip dynamictulip deleted the academies-db-connection/add-search-provider branch October 11, 2023 11:05
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.

3 participants