π° drones
REST API that allows clients to communicate with drones (i.e. dispatch controller).
NOTE: Drones app has been tested on Ubuntu 18.04 and on Windows 10 with WSL and Golang 1.16 was used.
Table of Contents
βοΈAPI specification
The Drone API server provides the following API with communicating the DB:
Tag |
Title |
URL |
Query |
Method |
Auth |
user authentication (Using JWT) |
/api/v1/auth |
- |
POST |
Auth |
user logout |
/api/v1/auth/logout |
- |
GET |
Auth |
get user authenticated |
/api/v1/auth/user |
- |
GET |
Database |
Populate DB with fake data |
/api/v1/database/populate |
- |
POST |
Drones |
Get all drones or filters for State |
/api/v1/drones |
?state= |
GET |
Drones |
Registers or update a drone |
/api/v1/drones |
- |
POST |
Drones |
Get a drone by serialNumber |
/api/v1/drones/:serialNumber |
- |
GET |
Logs |
Get event logs |
/api/v1/logs |
- |
GET |
Medications |
Get medications |
/api/v1/medications |
- |
GET |
Medications |
Checking loaded items for a drone |
/api/v1/medications/items/:serialNumber |
- |
GET |
Medications |
Load a drone with medication items |
/api/v1/medications/items/:serialNumber |
- |
POST |
To see the API specifications in more detail, run the app and visit the swagger docs:
http://localhost:7001/swagger/index.html
π Assigned tasks
Done |
Task |
Endpoint |
β
|
registering a drone; |
ππΎ endpoint: /api/v1/drones [POST] |
β
|
loading a drone with medication items; |
ππΎ endpoint: /api/v1/medicationsitems/:serialNumber [POST] |
β
|
checking loaded medication items for a given drone; |
ππΎ endpoint: /api/v1/medicationsitems/:serialNumber [GET] |
β
|
checking available drones for loading; |
ππΎ endpoint: /api/v1/drones?state=1 [GET] |
β
|
check drone battery level for a given drone; |
ππΎ endpoint: /api/v1/drones/:serialNumber [GET], Get a drone by serialNumber |
The endpoints /api/v1/drones [POST]
and /api/v1/medicationsitems/:serialNumber [POST]
can also be used to update.
Done |
Functional and Non-functional requirements |
β
|
periodic task to check drones battery levels and create event log; |
β
|
prevent the drone from being loaded with more weight that it can carry; |
β
|
prevent the drone from being in LOADING state if the battery level is below 25%; |
β
|
Your project must be buildable and runnable; |
β
|
Your project must have a README file with build/run/test instructions (use DB file); |
β
|
Required data must be preloaded in the database. |
β
|
a bit of unit and end-to-end testing |
β
|
show us how you work through your commit history. |
π οΈοΈ Configuration file (conf.yaml)
ππΎ The config file
Param |
Description |
default value |
APIDocIP |
IP to expose the api (unused) |
127.0.0.1 |
DappPort |
app PORT |
7001 |
StoreDBPath |
DB file location |
./db/data.db |
CronEnabled |
active the cron job |
true |
LogDBPath |
DB file event logs |
./db/event_log.db |
EveryTime |
time interval (in seconds) that the cron task is executed |
300 seconds (every 5 minutes) |
By default, StoreDBPath generates the database file in the /db folder at the root of the project.
The server exposes the /api/v1/database/populate
POST endpoint to generate and repopulate the database whenever necessary.
β‘ Get Started
Download the drones.restapi project and move to root of project:
git clone https://github.com/kmilodenisglez/drones.restapi.git && cd drones.restapi
π Deployment ways (2 ways)
You can start the server in 2 ways, the first is using docker and docker-compose and the second is manually
π¦ Docker way
You will need docker and docker-compose in your system.
To builds Docker image from Dockerfile, run:
docker build --no-cache --force-rm --tag drones_restapi .
Use docker-compose to start the container:
docker-compose up
π§ Manual way
Run:
go mod download
go mod vendor
go build
π Environment variables
The environment variable is exported with the location of the server configuration file.
If you have π§Linux or πDash, run:
export SERVER_CONFIG=$PWD/conf/conf.yaml
but if it is in the windows cmd, then run:
set SERVER_CONFIG=%cd%/conf/conf.yaml
ππ½ββοΈ Start the server
Before it is recommended that you read more about the server configuration file in the section ππΎ .
Run the server:
./drones.restapi
and visit the swagger docs:
http://localhost:7001/swagger/index.html
The first endpoint to execute must be /api/v1/database/populate [POST], to populate the database. That endpoint does not need authentication.
You can then authenticate and test the remaining endpoints.
π§ͺ Unit or End-To-End Testing
Run:
go test -v
π¨ Tech and packages
π Architecture
This project has 3 layer :
- Controller Layer (Presentation)
- Service Layer (Business)
- Repository Layer (Persistence)