Thanks to visit codestin.com
Credit goes to github.com

Skip to content

czaaru/elevators-api

Repository files navigation

Elevators API Build Status

Heroku preview

Table of Contents

Core Concepts

Elevators is split into three layers. Service, simulation and state.

  • Service layer is a koa app with router and middlewares handling requests.

  • Simulation layer handles all business logic of elevators.

    NOTE: Elevator algorithm is simple FIFO, but the design should make it easy to improve.

  • State layer handles data. It could be replaced with database to keep the data persistent between server resets.

Getting started

Clone repo and go inside it:

git clone [email protected]:czaaru/elevators-api.git
cd elevators-api

Make sure node is running correct version and install dependencies:

nvm use
yarn

Start in dev mode:

yarn start:watch

Run tests in watch mode:

yarn jest --watch

API

All request return list of elevators following type:

enum Direction {
  UP = 1,
  DOWN = -1,
  NONE = 0,
}

interface Elevator {
  currentFloor: number;
  destinations: number[];
  direction: Direction;
}

type ResponseBody = Record<number, Elevator>;
  • GET /elevators - return current state of application
  • POST /elevators - create elevator with id posted in body
  • POST /elevators/pickup - add floor to destination of one of the elevators
  • PUT /elevators/:id - update elevator of id with posted body
  • POST /simiulation/step - do a step in a simulation
  • DELETE /simulation/reset/ - reset elevators to initial state

Continous Integration & Deployment

This repository uses travis to test and typecheck the application before deploying automatically to Heroku.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published