Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
github.com/daniortiz11/table-booking
The purpose of this API is to provide a table-occupancy service as people arrive at the restaurant. The API is built with Go and PostgreSQL.
In this service, we assume that groups of diners arrive at the restaurant and have to be assigned a table. On the other hand, the tables have several seats available. So if a table has enough seats available it could accommodate a group of customers.
People requests tables in groups of 1 to 6. People in the same group want to eat on the same table. You can take any group at any table that has enough empty seats for them. If it's not possible to accommodate them, they're willing to wait until there's a table available for them. Once a table is available for a group that is waiting, they should eat.
Once they get a table assigned, they will eat until they leave the restaurant, you cannot ask them to sit at another table (i.e. you cannot swap them to another table to make space for another group). In terms of fairness: groups are served in the order they arrive, but they eat opportunistically.
For example, a group of 6 is waiting for a table and there are 4 empty seats at a table for 6; if a group of 2 requests a table you may take them in the table for 6 but only if you have nowhere else to make them eat. This may mean that the group of 6 waits a long time, possibly until they become frustrated and leave the restaurant.
This API must comply with the following contract:
Indicate the service has started up correctly and is ready to accept requests.
Responses:
Load the list of available tables in the service and remove all previous data (existing bookings and tables). This method may be called more than once during the life cycle of the service.
Body required The list of tables to load.
Content Type application/json
Sample:
[
{
"id": 1,
"seats": 4
},
{
"id": 2,
"seats": 6
}
]
Responses:
A group of people requests to perform a booking.
Body required The group of people that wants to perform the booking
Content Type application/json
Sample:
{
"id": 1,
"people": 4
}
Responses:
A group of people asks for the restaurant bill to leave.
Body required A form with the group ID, such that ID=X
Content Type application/x-www-form-urlencoded
Responses:
Given a group ID such that ID=X
, return the table the group is eating with, or no table if they are still waiting to be seated.
Body required A url encoded form with the group ID such that ID=X
Content Type application/x-www-form-urlencoded
Accept application/json
Responses:
The Go Programming Language by The Go Authors - https://blog.golang.org/go-brand
Golang is the main language of this application and is necessary for its development and deployment. To install Golang all we have to do is follow their official documentation, it will only take a few moments.
Docker brand - https://github.com/docker
Docker is used to providing a container to our application and database. At the same time, it provides a quick way to deploy the API. To install Docker we go to their official site and select our operating system.
Postman brand - https://github.com/postmanlabs
A JSON Postman collection
is provided in the repository for the purpose of testing operations once the API is deployed, although it is not mandatory to test operations in this way. To install Postman we go to their official site and select our operating system.
The first step is to clone or download the repository. Once done, we open a console and browse to it.
A Makefile is provided in the repository so starting to use the API is very simple:
MBP-Dani:table-booking daniortiz$ make
Welcome to Table-booking API!
Prerequisites:
1. Golang
2. Docker
3. Unix based os
Options:
help: Show this help.
table-booking-up: Command to run the application.
table-booking-down: Command to shut down the application.
Once you have checked that you have Go installed and daemon Docker is running to start the service you just have to choose the right option:
MBP-Dani:table-booking daniortiz$ make table-booking-up
...
...
Creating table-booking_rest_1 ... done
Creating table-booking_db_1 ... done
Attaching to table-booking_rest_1, table-booking_db_1
rest_1 | 2020/04/11 18:46:28 Starting server...
...
...
db_1 | 2020-04-11 18:46:29.848 UTC [1] LOG: database system is ready to accept connections
The first thing the operation does is to build the Go executable and then execute our docker-compose
. This docker-compose starts the Go service and a PostgreSQL database that is initialized with the table-booking_dump.sql
script.
So the API is now ready to receive requests. To check that everything is correct, use operation "/healthcheck".
To turn off the service we have to open a new console and execute the other command in the make file:
MBP-Dani:table-booking daniortiz$ make table-booking-down
docker-compose -f docker-compose.yml down
Stopping table-booking_db_1 ... done
Stopping table-booking_rest_1 ... done
Removing table-booking_db_1 ... done
Removing table-booking_rest_1 ... done
Removing network table-booking_default
All other files are covered by the MIT license, see LICENSE
.
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.