Skip to content

Latest commit

 

History

History
74 lines (56 loc) · 3.48 KB

README.md

File metadata and controls

74 lines (56 loc) · 3.48 KB

Power Play Backend

image

Go

Table of Contents

Adding and Updating API Endpoints

There are 5 major steps to creating or editing an endpoint.

Ensure Model is Created and Up to Date

  1. Navigate to the models directory:
    backend/internal/models
  2. 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.

Add or Edit API Endpoint Handlers

  1. Navigate to the server directory:
    backend/internal/server/apis
  2. Create or find the .go file for the Endpoint you are working on.
  3. Implement or edit the API Handlers. The most common handlers are GET and POST.

GET and POST Handlers

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.

  1. 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)
}

Add or Edit any DB methods used in the API endpoint

  1. Navigate to the db directory:
    backend/internal/db
  2. Create or find the .go file for the endpoint you are working on.
  3. Implement or edit the methods within the .go file. These can include Get, Create

Get and Create Method

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.

Update the Open API docs

  1. Navigate to the open api spec directory:
    static/oas/v1

  2. Create or update the corresponding .yml file to correctly reflect any changes you have made.

  3. Use the following linked .yml file to keep the documentation consistent throughout the backend.

Adding and Updating Unit Testing for Database Model

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 and Updating Unit Testing for API Endpoint

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.