6. Guides

Guide to Adding a New Endpoint

This guide will walk you through the steps to add a new endpoint with a new table in the Database. Its based on the “hospital” endpoint.

Step 1: Add Domain Models and Access Rights

Update the domain/models/hospital.go and domain/access/rights.go files to define the Hospital model and access rights.

// hospital.go
type Hospital struct {
}

// rights.go
models.AccessRightViewHospital,
models.AccessRightCreateHospital,
models.AccessRightUpdateHospital,
models.AccessRightDeleteHospital,

Step 2: Implement CRUD Operations

Implement the CRUD operations for the Hospital entity in the funcs/rest/hospitals directory.

Step 3: Update Stores

Update the domain/stores/stores.go file to include the Hospitals store.

func Hospitals(store storeapi.Store) (storeapi.ItemStore[models.Hospital], error) {
}

Step 4: Update Environment Variables

Update the README.md, compose.yml, compose.tables.yml files to include the new environment variable for the Hospitals store aswell as the table-seed.

# README.md
- KATAPP_STORE_HOSPITALS=Hospitals

# compose.yml
- KATAPP_STORE_HOSPITALS=Hospitals

# compose.table.yaml
- table-seed-vehicles:
    image: amazon/aws-cli:latest
    container_name: table-seed-hospital
    environment:
      - AWS_ACCESS_KEY_ID=dave
      - AWS_SECRET_ACCESS_KEY=dave
    command: >
      dynamodb create-table --table-name Hospitals --attribute-definitions AttributeName=_id,AttributeType=S --key-schema AttributeName=_id,KeyType=HASH --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 --endpoint-url http://dynamodb:8000 --region eu-central-1      
    networks:
      - katapp-local

Step 5: Update Docker Configuration

Update the dockerfile to include the new environment variable.

ENV KATAPP_STORE_HOSPITALS=Hospitals

Step 6: Update Deployment Configuration

Update the deployment/environment/environment.go and deployment/tables/tables.go files to include the new Hospitals table.

// environment.go
{Name: vars.EnvKatAppStoreHospitals, Value: *katappDependencies.Tables.HospitalsTable.TableName()}

// tables.go
hospitalsTable := addKatAppTable(stack, stage, "Hospitals")

Additionally, update the deployment/tables/tables.go file to include the new Hospitals table in the AddKatAppTables function.

// tables.go
func AddKatAppTables(stack awscdk.Stack, stage stage.Stage) KatAppTables {
}

Step 7: Update Roles

Update the domain/roles/roles.go file to include the new access rights for the Hospital entity.

models.AccessRightViewHospital,
models.AccessRightCreateHospital,
models.AccessRightUpdateHospital,
models.AccessRightDeleteHospital,

Additionally, update the domain/models/role.go file to include the new access rights for the Hospital entity.

// role.go
Rights []AccessRight `json:"rights,omitempty" dynamodbav:"rights" bson:"rights" schema:"enum=AccessRightAccessManagementConsole AccessRightAccessTenantConsole AccessRightAccessDashboard AccessRightViewTenant AccessRightActivateTenant AccessRightViewUser AccessRightDeleteUser AccessRightActivateUser AccessRightCreateDevice AccessRightCreateDeviceToken AccessRightViewRole AccessRightCreateRole AccessRightAssignRole AccessRightViewTriage AccessRightCreateTriage AccessRightUpdateTriage AccessRightViewPatient AccessRightCreatePatient AccessRightUpdatePatient AccessRightViewDisaster AccessRightCreateDisaster AccessRightWebSocket AccessRightWebSocketEventOnCreateTriage AccessRightWebSocketEventOnCreatePatient AccessRightWebSocketEventOnCreateDisaster AccessRightWebSocketEventOnUpdatePatient AccessRightWebSocketEventOnUpdateDisaster AccessRightViewVehicle AccessRightCreateVehicle AccessRightUpdateVehicle AccessRightDeleteVehicle AccessRightViewHospital AccessRightCreateHospital AccessRightUpdateHospital AccessRightDeleteHospital"`

Step 8: Update WebSocket Access Rights

Update the domain/models/websocket.go file to include the new access rights for the Hospital entity.

// websocket.go
AccessRights []AccessRight `json:"accessRights,omitempty" dynamodbav:"accessRights" bson:"accessRights" schema:"enum=AccessRightAccessManagementConsole AccessRightAccessTenantConsole AccessRightAccessDashboard AccessRightViewTenant AccessRightActivateTenant AccessRightViewUser AccessRightDeleteUser AccessRightActivateUser AccessRightCreateDevice AccessRightCreateDeviceToken AccessRightViewRole AccessRightCreateRole AccessRightAssignRole AccessRightViewTriage AccessRightCreateTriage AccessRightUpdateTriage AccessRightViewPatient AccessRightCreatePatient AccessRightUpdatePatient AccessRightViewDisaster AccessRightCreateDisaster AccessRightWebSocket AccessRightWebSocketEventOnCreateTriage AccessRightWebSocketEventOnCreatePatient AccessRightWebSocketEventOnCreateDisaster AccessRightWebSocketEventOnUpdatePatient AccessRightWebSocketEventOnUpdateDisaster AccessRightViewVehicle AccessRightCreateVehicle AccessRightUpdateVehicle AccessRightDeleteVehicle AccessRightViewHospital AccessRightCreateHospital AccessRightUpdateHospital AccessRightDeleteHospital"` //nolint

Step 9: Update Role Creation Request

Update the funcs/rest/roles/createrole/request.go file to include the new access rights for the Hospital entity.

// request.go
Rights []string `json:"rights" validate:"required" schema="enum=AccessRightAccessManagementConsole AccessRightAccessTenantConsole AccessRightAccessDashboard AccessRightViewTenant AccessRightActivateTenant AccessRightViewUser AccessRightDeleteUser AccessRightActivateUser AccessRightCreateDevice AccessRightCreateDeviceToken AccessRightViewRole AccessRightCreateRole AccessRightAssignRole AccessRightViewTriage AccessRightCreateTriage AccessRightUpdateTriage AccessRightViewPatient AccessRightCreatePatient AccessRightUpdatePatient AccessRightViewDisaster AccessRightCreateDisaster AccessRightWebSocket AccessRightWebSocketEventOnCreateTriage AccessRightWebSocketEventOnCreatePatient AccessRightWebSocketEventOnCreateDisaster AccessRightWebSocketEventOnUpdatePatient AccessRightWebSocketEventOnUpdateDisaster AccessRightViewVehicle AccessRightCreateVehicle AccessRightUpdateVehicle AccessRightDeleteVehicle AccessRightViewHospital AccessRightCreateHospital AccessRightUpdateHospital AccessRightDeleteHospital"` //nolint

Step 12: Add Access rights in AWS

In AWS, go to IAM/Roles/YourNewEndpoint/Roles/Permissions and add required permissions.

Step 11: Test the New Endpoint

Ensure that all the changes are tested thoroughly to verify the new endpoint works as expected.