Glofox Backend Task (Daniel Pons)
Notes
- Service implemented following the Acceptance Criteria of the two Stories written in the PDF provided to me
- Used a well-known third party package for the API routing: go-chi (https://github.com/go-chi/chi)
- The project structure follows a clean approach separatig the entry point of the service, with the handlers, models / entities and data repository
- The entry point is on cmd/service/main.go
- Memory has been used for data persistence
- The service is listening by default on 8080
- Both the requests and the responses (if applicable) are in application/json type
Endpoints
POST /classes
Parameters
Name | Required | Type | Description |
---|---|---|---|
name |
required | string | Name of the class (e.g. Pilates) |
startDate |
required | string | The start date from which classes will be available Format: yyyy-mm-dd |
endDate |
required | string | The date of the last class Format: yyyy-mm-dd |
capacity |
required | number | The maximum capacity for each of the days |
Example
{
"name": "Pilates",
"startDate": "2022-08-01",
"endDate": "2022-08-20",
"capacity": 10
}
Validations
- If any field is missing in the request, it will be rejected
- Dates must follow the indicated format
- If startDate is after the endDate, the request will be rejected
- if a Class already exists for that day, it will not be added or overwritten
POST /bookings
Parameters
Name | Required | Type | Description |
---|---|---|---|
attendant |
required | string | Name of the member who is booking the class |
date |
required | string | The date for which the member want to book a classFormat: yyyy-mm-dd |
Example
{
"attendant": "Daniel",
"date": "2022-08-04"
}
Validations
- If any field is missing in the request, it will be rejected
- Date must follow the indicated format
- No actions are taken in case of overbooking, although a log is printed when it’s happening
Run
This service has been implemented using Go 1.17 using Go Modules.
The following script downloads the required modules at project level and run the service
_scripts/run.sh
If there is a problem with the modules management on local machine, Docker can be used.
_scripts/docker.sh
It will build an image following the Dockerfile and run it exposing the port 8080
Test
To run all the unit tests
_scripts/tests.sh