SpaceBook 🚀
Usage
Project contains Taskfile with available actions. To use Taskfile, you need to install task:
brew install go-task/tap/go-task
More information: https://taskfile.dev/#/installation
To view all available tasks just type:
task
Development environment
To run development environment run:
task dev
Tests
To execute tests, run:
task test
Production
To run project for production, use:
docker run -p 8080:8080 \
-e DATABASE_HOST=postgres \
-e DATABASE_PORT=5432 \
-e DATABASE_USER=sb \
-e DATABASE_PASSWORD=password \
-e DATABASE_NAME=sb \
drymek/spacebook:latest
Usage examples
Book
echo '{ "id": "1234", "firstname": "John", "lastname": "Doe", "gender": "Male", "birthday": "2000-07-21", "launchpadID": "5e9e4501f5090910d4566f83", "destinationID": "Mars", "launchDate": "2022-01-17"}' | http POST :8080/bookings
HTTP/1.1 200 OK
Access-Control-Allow-Headers: Origin, Content-Type
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Origin: *
Content-Length: 14
Content-Type: text/plain; charset=utf-8
Date: Sat, 16 Apr 2022 01:44:43 GMT
{
"id": "1234"
}
Booking error
$ echo '{ "id": "1234", "firstname": "John", "lastname": "Doe", "gender": "Male", "birthday": "2000-07-21", "launchpadID": "5e9e4502f509094188566f88", "destinationID": "Asteroid Belt", "launchDate": "2022-07-01"}' | http POST :8080/bookings
HTTP/1.1 400 Bad Request
Access-Control-Allow-Headers: Origin, Content-Type
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Origin: *
Content-Length: 75
Content-Type: text/plain; charset=utf-8
Date: Sat, 16 Apr 2022 13:39:46 GMT
{
"error": "booking service error: SpaceX already has a launch on this date"
}
Get all bookings
http :8080/bookings
HTTP/1.1 200 OK
Access-Control-Allow-Headers: Origin, Content-Type
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Origin: *
Content-Length: 192
Content-Type: text/plain; charset=utf-8
Date: Sat, 16 Apr 2022 01:46:35 GMT
{
"items": [
{
"birthday": "2000-07-21",
"destinationID": "Mars",
"firstname": "John",
"gender": "Male",
"id": "1234",
"lastname": "Doe",
"launchDate": "2022-01-17",
"launchpadID": "5e9e4501f5090910d4566f83"
}
]
}
Delete
http DELETE :8080/bookings/123
HTTP/1.1 204 No Content
Access-Control-Allow-Headers: Origin, Content-Type
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Origin: *
Date: Sat, 16 Apr 2022 21:27:53 GMT