drones.restapi

command module
v0.0.0-...-3356bae Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 27, 2022 License: LGPL-2.1 Imports: 13 Imported by: 0

README ΒΆ

πŸ›° 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

swagger ui

πŸ“ 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.

swagger ui

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)
Tag Path Layer
Auth end_auth.go Controller
Drones end_drones.go Controller
EventLog end_eventlog.go Controller
Auth svc_authentication.go Service
Drones svc_drones.go Service
EventLog svc_eventlog.go Service
Auth repo_drones.go Repository
Drones repo_drones.go Repository
EventLog repo_eventlog.go Repository

Documentation ΒΆ

The Go Gopher

There is no documentation for this package.

Directories ΒΆ

Path Synopsis
api
repo
db
dto

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL