- Adding and Updating API Endpoints
- Adding and Updating Unit Testing for Database Model
- Adding and Updating Unit Testing for API Endpoint
There are 5 major steps to creating or editing an endpoint.
- Navigate to the models directory:
backend/internal/models
- Find the model for the endpoint you are working on.
- If the model is not there, create it
- If the model is not accurate, make changes to ensure the model will reflect the needs.
- Navigate to the server directory:
backend/internal/server/apis
- Create or find the .go file for the Endpoint you are working on.
- Implement or edit the API Handlers. The most common handlers are GET and POST.
The following links to the current penalty API handlers. Use this as an example for creating new handlers so everything in the backend follows a similar pattern.
- Add in any handlers to the init function
func init() {
apis.RegisterHandler(fiber.MethodGet, "/generics", auth.Public, getGenericsHandler)
apis.RegisterHandler(fiber.MethodPost, "/generics", auth.Public, postGenericHandler)
}
- Navigate to the db directory:
backend/internal/db
- Create or find the .go file for the endpoint you are working on.
- Implement or edit the methods within the .go file. These can include Get, Create
The following link is to an example .go file containing methods to be used as an example in creating new methods to keep methods consistent throughout the backend. The preload can be used to load any needed database relation.
-
Navigate to the open api spec directory:
static/oas/v1
-
Create or update the corresponding .yml file to correctly reflect any changes you have made.
-
Use the following linked .yml file to keep the documentation consistent throughout the backend.
Adding a unit test for a database model. These tests will be using a docker spin up of the actual database for testing the database interfacing functions.
Uses the dockertest go package
To be expounded upon once a unit testing pattern is achieved.
Adding a unit test for an API endpoint. These tests will be using a mock up of the database models involved.
To be expounded upon once a unit testing pattern is achieved.