Sign inSign up

lyanthropos/hw1_api

By lyanthropos

Updated over 4 years ago

A simple transit card server that can store rides and passes for multiple unique users

Image
0

1.1K

lyanthropos/hw1_api repository overview

Transit Server

Docker commands

The commands below detail the usage of this container assuming you have docker installed. By default, the Transit Server is hosted at 127.0.0.1 on port 8081, but this can be configured by replacing either the IP or port values in the spin-up command below.

Spin-up (first time)

docker run --name "transit_server" -p 127.0.0.1:8081:8099 lyanthropos/hw1_api

Stop

docker stop transit_server

Start

docker start transit_server

Remove (will require spin-up to run again)

docker rm tranist_server

Getting Started

The transit server allows a developer to create and track multiple users ride cards. Each card is associated with a unique userId which is required for all transactions. This id can be obtained when creating a new user.

Note: The responsibility of tracking these ids is left to the developer. Losing an id means losing access to the linked record.

All new users start with zero rides and a without a pass. Rides can be added and removed, whiles passes are a permanent activation. Detailed in the next section are each of the actions that can be taken for an account.

Available actions

Each of these actions can be performed by sending the specified request to 127.0.0.1:8099 with the matching query parameters or JSON body

Add User

Creates a new user in the transit server. The value of the userId field in the response JSON should be saved as it is required for all interactions with that user's account.

  • Relative URL: /account/addUser
  • Method: POST
  • JSON body: { "name": "<name>"}
  • JSON response: {"userId": "<userId>"}
Get Status

Returns the status of the user's card, consisting of name, available rides, pass status, and a log of all executed transactions.

  • Relative URL: /account/getStatus
  • Method: GET
  • Query Params: userId=<userId>
  • JSON response: {"name": "<name>", "rides":"<number of remaining rides>", "pass":"<boolean if pass is active>","transactions":"<array of transactions>"}
Add Ride

Add a ride to a user's card.

  • Relative URL: /account/addRide
  • Method: POST
  • JSON body: { "userId": "<userId>"}
  • JSON response: {"success": "<boolean>", "rides": "<number of remaining rides>"}
Remove Ride

Remove a ride from a user's card. Will error if a user has 0 rides remaining.

  • Relative URL: /account/removeRide
  • Method: POST
  • JSON body: { "userId": "<userId>"}
  • JSON response: {"success": "<boolean>", "rides": "<number of remaining rides>"}
Activate Pass

Activates the infinite transit pass for a user's card.

  • Relative URL: /account/addPass
  • Method: POST
  • JSON body: { "userId": "<userId>"}
  • JSON response: {"success": "<boolean>"}

Tag summary

Content type

Image

Digest

Size

52.6 MB

Last updated

over 4 years ago

docker pull lyanthropos/hw1_api