-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* PFS-143 Create back-end structure similar to finance-hub * PFS-143 Create back-end structure similar to finance-hub * PFS-143 Add test upload file code * PFS-143 Update makefile and build yml * PFS-143 Fix linting * PFS-143 Add localstack for local bucket * PFS-143 Upload file from form * PFS-143 Fix linting * PFS-143 Add SSE to upload * PFS-143 Add success message, remove test upload type * PFS-143 Migrate to aws-sdk-go-v2 * PFS-143 Attempt to fix blank endpoint * PFS-143 Attempt to fix blank endpoint * PFS-143 Undo previous change * PFS-143 Move uploads to subfolder in bucket * PFS-143 Move CSV header validation to back-end * PFS-143 Add cypress test & api unit tests * PFS-143 Create ADR * PFS-143 Fix build * PFS-143 Code cleanup, move upload type enum to shared * PFS-143 Change case of upload type enum, undo SSE env var * PFS-143 Fix cypress test * PFS-143 Fix cypress test
- Loading branch information
1 parent
4b79699
commit f09a7c1
Showing
92 changed files
with
1,453 additions
and
516 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
File renamed without changes.
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,23 @@ | ||
# 3. Create a new Finance Admin Back End | ||
|
||
Date: 2024-09-24 | ||
|
||
## Status | ||
|
||
Accepted | ||
|
||
## Context | ||
|
||
We have created the Finance Admin front end, however the decision was made to add a service between S3 and the front end | ||
to upload and download files from S3 without making AWS credentials accessible to the user. | ||
|
||
## Decision | ||
|
||
A new back end will be created in this repo, similarly to the structure of the finance hub. This will communicate with S3 | ||
to perform uploads and downloads using Go's AWS SDK. This back end will also allow us to perform any other logic required for | ||
the finance admin system, such as validation. | ||
|
||
## Consequences | ||
|
||
This ensures we can interact with S3 whilst keeping our AWS credentials away from the client, but increases the complexity of the system. | ||
|
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,79 @@ | ||
package apierror | ||
|
||
import ( | ||
"fmt" | ||
"net/http" | ||
"strings" | ||
) | ||
|
||
type BadRequest struct { | ||
error | ||
Field string `json:"field,omitempty"` | ||
Reason string `json:"reason"` | ||
} | ||
|
||
func BadRequestError(field string, reason string, error error) *BadRequest { | ||
return &BadRequest{error: error, Field: field, Reason: reason} | ||
} | ||
|
||
func (b BadRequest) Error() string { | ||
return b.Reason | ||
} | ||
|
||
func (b BadRequest) HTTPStatus() int { return http.StatusBadRequest } | ||
|
||
func (b BadRequest) HasData() bool { | ||
return true | ||
} | ||
|
||
type BadRequests struct { | ||
Reasons []string `json:"reasons"` | ||
} | ||
|
||
func BadRequestsError(reasons []string) *BadRequests { | ||
return &BadRequests{Reasons: reasons} | ||
} | ||
|
||
func (b BadRequests) Error() string { | ||
return fmt.Sprintf("bad requests: %s", strings.Join(b.Reasons, ", ")) | ||
} | ||
|
||
func (b BadRequests) HTTPStatus() int { return http.StatusBadRequest } | ||
|
||
func (b BadRequests) HasData() bool { | ||
return true | ||
} | ||
|
||
type NotFound struct { | ||
error | ||
} | ||
|
||
func NotFoundError(error error) *NotFound { | ||
return &NotFound{error: error} | ||
} | ||
|
||
func (n NotFound) Unwrap() error { | ||
return n.error | ||
} | ||
|
||
func (n NotFound) Error() string { | ||
return "requested resource not found" | ||
} | ||
|
||
func (n NotFound) HTTPStatus() int { return http.StatusNotFound } | ||
|
||
type ValidationErrors map[string]map[string]string | ||
|
||
type ValidationError struct { | ||
Errors ValidationErrors `json:"validation_errors"` | ||
} | ||
|
||
func (ve ValidationError) Error() string { | ||
return "validation failed" | ||
} | ||
|
||
func (ve ValidationError) HTTPStatus() int { return http.StatusUnprocessableEntity } | ||
|
||
func (ve ValidationError) HasData() bool { | ||
return true | ||
} |
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,29 @@ | ||
const { defineConfig } = require("cypress") | ||
|
||
module.exports = defineConfig({ | ||
fixturesFolder: false, | ||
e2e: { | ||
setupNodeEvents(on, config) { | ||
on("task", { | ||
log(message) { | ||
console.log(message); | ||
|
||
return null | ||
}, | ||
table(message) { | ||
console.table(message); | ||
|
||
return null | ||
}, | ||
failed: require("cypress-failed-log/src/failed")() | ||
}); | ||
}, | ||
baseUrl: "http://localhost:8888/finance-admin", | ||
specPattern: "e2e/**/*.cy.{js,ts}", | ||
screenshotsFolder: "screenshots", | ||
supportFile: "support/e2e.ts", | ||
modifyObstructiveCode: false, | ||
}, | ||
viewportWidth: 1000, | ||
viewportHeight: 1000, | ||
}); |
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,41 @@ | ||
describe("Finance Admin", () => { | ||
beforeEach(() => { | ||
cy.visit("/uploads"); | ||
}); | ||
|
||
describe("Upload file", () => { | ||
it("Uploads file successfully", () => { | ||
cy.get('[data-cy=\"report-upload-type\"]').select('DEBT_CHASE') | ||
cy.get('#file-upload').selectFile('cypress/fixtures/debt_chase_example.csv') | ||
cy.get('.govuk-button').contains('Upload report').click() | ||
cy.url().should("include","/uploads?success=upload"); | ||
cy.get('.moj-banner').contains('File successfully uploaded') | ||
}); | ||
|
||
it("Validates missing file", () => { | ||
cy.get('[data-cy=\"report-upload-type\"]').select('DEPUTY_SCHEDULE') | ||
cy.get('.govuk-button').contains('Upload report').click() | ||
cy.get('.govuk-error-summary').contains('No file uploaded') | ||
cy.get('#f-FileUpload').contains('No file uploaded') | ||
cy.get('#f-FileUpload').should('have.class', 'govuk-form-group--error') | ||
}) | ||
|
||
it("Validates empty headers", () => { | ||
cy.get('[data-cy=\"report-upload-type\"]').select('DEPUTY_SCHEDULE') | ||
cy.get('#file-upload').selectFile('cypress/fixtures/empty_report.csv') | ||
cy.get('.govuk-button').contains('Upload report').click() | ||
cy.get('.govuk-error-summary').contains('Failed to read CSV headers') | ||
cy.get('#f-FileUpload').contains('Failed to read CSV headers') | ||
cy.get('#f-FileUpload').should('have.class', 'govuk-form-group--error') | ||
}) | ||
|
||
it("Validates CSV headers", () => { | ||
cy.get('[data-cy=\"report-upload-type\"]').select('DEPUTY_SCHEDULE'); | ||
cy.get('#file-upload').selectFile('cypress/fixtures/debt_chase_example.csv') | ||
cy.get('.govuk-button').contains('Upload report').click() | ||
cy.get('.govuk-error-summary').contains('CSV headers do not match for the report trying to be uploaded') | ||
cy.get('#f-FileUpload').contains('CSV headers do not match for the report trying to be uploaded') | ||
cy.get('#f-FileUpload').should('have.class', 'govuk-form-group--error') | ||
}); | ||
}); | ||
}); |
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 @@ | ||
Client_no,Deputy_name,Total_debt |
Empty file.
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,40 @@ | ||
FROM golang:1.22-alpine AS base | ||
WORKDIR /app | ||
|
||
ENV CGO_ENABLED=0 GOOS=linux | ||
|
||
RUN update-ca-certificates | ||
|
||
FROM base AS dev | ||
WORKDIR /app/finance-admin-api | ||
|
||
RUN go install github.com/cosmtrek/[email protected] && go install github.com/go-delve/delve/cmd/dlv@latest | ||
EXPOSE 8080 | ||
EXPOSE 2345 | ||
|
||
ENTRYPOINT ["air"] | ||
|
||
FROM base as build-env | ||
WORKDIR /app | ||
|
||
COPY go.mod go.sum ./ | ||
RUN go mod download | ||
|
||
COPY . . | ||
|
||
WORKDIR /app/finance-admin-api | ||
|
||
RUN go build -a -installsuffix cgo -o /go/bin/finance-admin-api | ||
|
||
FROM alpine:3 | ||
WORKDIR /go/bin | ||
|
||
RUN apk --update --no-cache add \ | ||
ca-certificates \ | ||
tzdata | ||
|
||
# Patch vulnerabilities | ||
RUN apk upgrade --no-cache busybox libcrypto3 libssl3 | ||
|
||
COPY --from=build-env /go/bin/finance-admin-api finance-admin-api | ||
ENTRYPOINT ["./finance-admin-api"] |
Oops, something went wrong.