An open API service indexing awesome lists of open source software.

https://github.com/defra/pha-import-notifications

Git repository for service pha-import-notifications
https://github.com/defra/pha-import-notifications

backend cdp dotnet service

Last synced: about 2 months ago
JSON representation

Git repository for service pha-import-notifications

Awesome Lists containing this project

README

          

# Defra PHA Import Notifications

This service provides Port Health Authorities (PHAs) access to a mixture of IPAFFS, ALVS, CDS and GVMS data.

The solution supplies an endpoint for querying for updated records within a certain time period
and then provides the ability to retrieve all the data for those records.

## Prerequisites

The solution requires:

- .NET 9

```bash
brew tap isen-ng/dotnet-sdk-versions
brew install --cask dotnet-sdk9
```

- Docker (optional)

## Installation

1. Clone this repository
2. Install the required tools with `dotnet tool restore`
3. Check the solution builds with `dotnet build`
4. Check the service builds with `docker build .`

## Running

1. Run the application via your favourite IDE or via Docker:
```
docker build -t pha-import-notifications .
docker run -p 8080:8080 \
-e ASPNETCORE_ENVIRONMENT=Development \
-e ENVIRONMENT=Local \
pha-import-notifications
```
2. Navigate to http://localhost:8080/redoc

## Endpoints

The endpoints are detailed in the OpenAPI spec which is available either via the Redoc URL,
or alternatively via the [OpenAPI Spec URL](http://localhost:8080/.well-known/openapi/v1/openapi.json).

A JWT is required to authenticate the user when making requests.
A local one can be generated by running `./scripts/generate-jwt.sh` and then including it as a `Bearer` token in the `Authorization` header.

Get all updated import notifications within a time period:
```http request
http://localhost:8080/import-notifications?bcp=BCP1&from=2025-02-12T12:00:00+00:00&to=2025-02-12T12:30:00+00:00
```

Get an import notification:
```http request
http://localhost:8080/import-notifications/CHEDA.GB.2024.4792831
```

## Update Trade Imports Data Schema

When a schema change in Trade Data Imports is made we need to update our models.

At the moment this is a manual process:

1. Fetch the `openapi.json` artifact from the latest build of [trade-imports-data-api](https://github.com/defra/trade-imports-data-api/actions/workflows/publish.yml?query=branch%3Amain)
2. In the PHA API repository, extract and copy this to the tools/SchemaToCSharp folder
3. Run `make update-tradeimportsdataapi-schema` in the root of the repository
4. Observe any changes that have been made and commit them

## Update Trade Imports Data Stub Scenarios

Following a schema change, we need to update the response JSON that Trade Imports Data will give us.

At the moment this is a manual process:

1. Checkout main from [trade-imports-data-api](https://github.com/defra/trade-imports-data-api)
2. Locate the integration test called `ShouldImportPhaStubScenario`
3. Update the test so it will save the generated output
4. Understand and act on any redaction work needed before committing anything
5. Run the test and take the output from the generated `PhaScenarioTestsOutput` folder
6. Replace the [TradeImportsDataApiStub/Scenarios folder](tests/TradeImportsDataApiStub/Scenarios) in this repo with the contents of the folder above
7. Do the same for the [Trade Imports Data Stub Scenarios](https://github.com/DEFRA/trade-imports-data-api-stub/tree/main/src/Stub/Scenarios)
8. Observe any changes that have been made and commit them

## Development

It is possible to configure the PHA API to query a deployed Trade Imports Data instance.

Fill out the [TradeImportsDataApiOptions](./src/Api/Configuration/TradeImportsDataApiOptions.cs) configuration to point at a Trade Imports Data instance and then
perform a request to the PHA API whilst connected to the VPN.

The `Username` and `Password` are Basic Auth credentials.

## Testing

The unit and integration tests can either be run via your IDE or alternatively with `dotnet test .`

A SonarCloud setup will run static analysis on the code when raising a PR.

# Linting

We use [CSharpier](https://csharpier.com) to lint our code.

You can run the linter with `dotnet csharpier check .`

## License

This project is licensed under The Open Government Licence (OGL) Version 3.
See the [LICENSE](./LICENSE) for more details.