https://github.com/suddi/parkinglot-api
parkinglot API developed in Koa.js
https://github.com/suddi/parkinglot-api
api koa koajs mysql nodejs
Last synced: about 1 month ago
JSON representation
parkinglot API developed in Koa.js
- Host: GitHub
- URL: https://github.com/suddi/parkinglot-api
- Owner: suddi
- License: mit
- Created: 2016-11-22T22:49:02.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-11-27T14:25:33.000Z (over 1 year ago)
- Last Synced: 2024-04-14T12:29:17.227Z (about 1 year ago)
- Topics: api, koa, koajs, mysql, nodejs
- Language: JavaScript
- Homepage:
- Size: 545 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Parking Lot API
[](https://travis-ci.org/suddi/parkinglot-api)
[](https://codecov.io/gh/suddi/parkinglot-api)
[](https://www.codacy.com/app/Suddi/parkinglot-api?utm_source=github.com&utm_medium=referral&utm_content=suddi/parkinglot-api&utm_campaign=badger)
[](https://greenkeeper.io/)
[](https://david-dm.org/suddi/parkinglot-api)
[](https://david-dm.org/suddi/parkinglot-api?type=dev)
[](https://github.com/suddi/parkinglot/LICENSE)[](https://codecov.io/gh/suddi/parkinglot-api)
## Setup
To setup on Ubuntu 16.04 Xenial Xerus, setup scripts are provided, to run these:
````sh
. ./setup.sh
````This will install the following:
* docker
* nvm, node and npmYou will also need to mysql 5.7, to install all these manually, you may follow:
* [docker](https://docs.docker.com/engine/installation/)
* [nvm](https://github.com/creationix/nvm#install-script)
* [mysql](https://dev.mysql.com/doc/refman/5.7/en/installing.html)If you are not using the default configuration in mysql, you will need to update the DB config [here](/config/primitive/db.js) and testing config [here](/test/db_utils.js).
Please create a database in mysql and load the [SQL schema file](/scripts/schema.sql), this will create the necessary tables.
Once these have been installed, please run:
````sh
# This may be skipped if you used used setup.sh to setup node.js
npm install -g pm2# For development environment, can execute API with nodemon or pm2
npm install
````## Usage
To load fixtures, first add a fixture file to the `fixtures` directory.
There is already a sample fixture file provided [here](/fixtures/cars.xml), to load this into the DB:
````sh
# npm run load-fixturesnpm run load-fixtures cars.xml
````To startup `redis`, which is used for rate-limiting:
````sh
# To bring up redis
npm run docker-up# To take down redis
npm run docker-down
````To start up the API:
````sh
npm start
````You may also startup the API using PM2:
````sh
pm2 start scripts/startup/development.json
# or
pm2 start scripts/startup/production.json
````This will by default, start up the API on port 3000.
There are several endpoints provided:
* `GET /` and `GET /whoami`
* Health check endpoints
* `GET /parkinglots/:parkingLotId/cars/:hoursPassed`
* This will calculate the earning made on parked cars given a valid parking lot and number of hours in the future
* `GET /inventory/:hoursPassed`
* This will return the number of cars in all the parking lots and the earning made given the number of hours in the future
* `POST /parkinglots/:parkingLotId/cars`
* This will add a car to the parking lot
* You only need to provide the following: `brand`, `licencePlate` and `parkingTime` (will take current UTC time if not provided)To run the linter, tests and generate code coverage:
````sh
# To execute the linter separately
npm run lint# To execute linter, tests and generate code coverage
npm test
````## Outstanding Issues
There are a number of outstanding issues, that due to time limitation have not been included, to view these, please visit [OUTSTANDING_ISSUES.md](/OUTSTANDING_ISSUES.md).