Table of Contents
This service is built using the latest golang version 1.18
.
- Go-Gonic The foundational http router and data binding.
- Gorm.io The DB ORM.
- Cron App scheduler for processed cron jobs.
- Validator Used for applying validation rule 10000 s on user inputs.
This service uses Postgres as it's datastore.
To run the service, make sure you have Docker and Compose installed on testing machine.
Warning: before running the below command please make sure that ports
5432
and6504
are not allocated.
make up
This command builds the service and deploys the built binary to a container, It also spins up a postgres DB instance.
The default exposed service host URL is: https://localhost:6504/
To make sure that the service is up and running you can hit this ping URl http://localhost:6504/ping
and you should receive response:
{
"message": "OK"
}
This section documents how to consume this service APIs, listed below all requests with request/response payloads examples.
The URL below contains all endpoints requests collection on postman: here
Used to register a drone
http://localhost:6504/drones/register
POST
{
"serial_number": "123455",
"model": "LIGHT-WEIGHT",
"weight_limit": 100,
"battery_capacity": 50
}
Assumption Registering a new drone will set it's status to 'IDLE'
{
"code": 200,
"message": "drone registered successfully",
"success": false
}
{
"code": 422,
"errors": {
"SerialNumber": "already registered"
},
"message": "invalid data",
"success": false
}
{
"code": 422,
"errors": {
"Model": "not allowed value, one of: 'LIGHT-WEIGHT' 'MIDDLE-WEIGHT' 'CRUISER-WEIGHT' 'HEAVY-WEIGHT'"
},
"message": "invalid data",
"success": false
}
{
"code": 422,
"errors": {
"BatteryCapacity": "exceeded the limit, max: 100"
},
"message": "invalid data",
"success": false
}
{
"code": 422,
"errors": {
"WeightLimit": "exceeded the limit, max: 500"
},
"message": "invalid data",
"success": false
}
This request used to load drone with list of medications
http://localhost:6504/drones/load
GET
{
"serial_number": "123455",
"medications": [
{
"code": "185459",
"name": "Ranny",
"weight": 10
}
]
}
{
"serial_number": "123455",
"medications": [
{
"code": "185459",
"name": "Ranny",
"weight": 10
}
]
}
{
"serial_number": "123455d",
"medications": [
{
"code": "1854599",
"name": "Ranny",
"weight": 10
}
]
}
{
"code": 422,
"errors": {
"Code": "already registered"
},
"message": "invalid data",
"success": false
}
{
"code": 422,
"errors": {
"Code": "invalid value pattern"
},
"message": "invalid data",
"success": false
}
{
"code": 422,
"message": "medications exceeds the max allowed weight limit.",
"success": false
}
Used to get loaded medications for a specific drone
http://localhost:6504/drones/:serialNumber/medications
GET
{
"code": 200,
"medications": [
{
"created_at": "2022-04-06T01:36:34.173265+02:00",
"drone_serial_number": "123455",
"name": "Ranny",
"weight": 5,
"code": "856945",
"image_url": "/storage/uploads/91947779410_1649201794__.png"
}
],
"message": "operation done successfully",
"success": false
}
{
"code": 404,
"message": "not registered drone",
"success": false
}
Used to fetch current drone battery capacity
http://localhost:6504/drones/:serialNumber/battery
GET
{
"battery_capacity": 50,
"code": 200,
"message": "operation done successfully",
"success": false
}
{
"code": 404,
"message": "not registered drone",
"success": false
}
Used to fetch drones with status IDLE
http://localhost:6504/drones/idle
GET
{
"code": 200,
"drones": [
{
"created_at": "2022-04-06T01:39:46.626267+02:00",
"serial_number": "123459",
"model": "LIGHT-WEIGHT",
"weight_limit": 400,
"battery_capacity": 50,
"status": "IDLE"
}
],
"message": "operation done successfully",
"success": false
}
Used to update drone status, one of: ('IDLE' 'LOADING' 'LOADED' 'DELIVERED' 'RETURNING')
PUT
{
"serial_number": "123455",
"status": "LOADED"
}
{
"code": 422,
"errors": {
"SerialNumber": "not exists in db",
"Status": "not allowed value, one of: 'IDLE' 'LOADING' 'LOADED' 'DELIVERED' 'RETURNING'"
},
"message": "invalid data",
"success": false
}
{
"code": 422,
"errors": {
"SerialNumber": "not exists in db",
"Status": "not allowed value, one of: 'IDLE' 'LOADING' 'LOADED' 'DELIVERED' 'RETURNING'"
},
"message": "invalid data",
"success": false
}
Below list states app possible enhancements I couldn't mount more time to implement.
- Return errors with keys json tags instead of struct keys.
- Enhance layers abstractions by implementing interfaces to support replacing app components easily.
- Add unit & integration tests
- Deploy an online demo.