docker-compose up -d --build
Now we have puma running on 0.0.0.0:3000 and postgresql configured
docker-compose exec api bundle exec rake db:create
docker-compose exec api bundle exec rake db:migrate
docker-compose exec api bundle exec rake db:seed
Now we have db default values all set
curl -0 -v -X POST http://localhost:3000/users \
-H "Accept: application/vnd.api+json" \
-H "Content-Type: application/vnd.api+json" \
-d @- <<'EOF'
{
"data": {
"type": "users",
"attributes": {
"email": "some@email.com",
"name": "Test user 1"
}
}
}
EOF
curl -0 -v -X POST http://localhost:3000/users \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d '{"user": {"email": "some@email.com", "name": "Test user 2"}}'
curl -H "Accept: application/json" http://localhost:3000/users/1
curl -H "Accept: application/json" http://localhost:3000/programs
Bonus task (term filtering):
curl -H "Accept: application/json" http://localhost:3000/programs?term=Train
You can do it 5 different ways
curl -0 -v -X POST http://localhost:3000/programs/1/subscriptions \
-H "Accept: application/vnd.api+json" \
-H "Content-Type: application/vnd.api+json" \
-d @- <<'EOF'
{
"data": {
"type": "subscriptions",
"relationships": {
"user": {
"data": {
"type": "users",
"id": "1"
}
}
}
}
}
EOF
curl -0 -v -X POST http://localhost:3000/users/1/subscriptions \
-H "Accept: application/vnd.api+json" \
-H "Content-Type: application/vnd.api+json" \
-d @- <<'EOF'
{
"data": {
"type": "subscriptions",
"relationships": {
"program": {
"data": {
"type": "programs",
"id": "2"
}
}
}
}
}
EOF
curl -0 -v -X POST http://localhost:3000/subscriptions \
-H "Accept: application/vnd.api+json" \
-H "Content-Type: application/vnd.api+json" \
-d @- <<'EOF'
{
"data": {
"type": "subscriptions",
"relationships": {
"user": {
"data": {
"type": "users",
"id": "1"
}
},
"program": {
"data": {
"type": "programs",
"id": "3"
}
}
}
}
}
EOF
curl -0 -v -X POST http://localhost:3000/users/1/subscriptions \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d '{"subscription": {"program_id": 4}}'
curl -0 -v -X POST http://localhost:3000/programs/5/subscriptions \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d '{"subscription": {"user_id": 1}}'
Additionally you may set 'banned' attribute to true in every type of subscription creation. Or update subscription with separate request:
curl -0 -v -X PATCH http://localhost:3000/subscriptions/1 \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d '{"subscription": {"banned": true}}'
This will make program hidden in user's programs list:
curl -H "Accept: application/json" http://localhost:3000/users/1/programs
If you want to run tests or use guard gem for automated testing run
docker-compose exec test bundle exec rake db:create
docker-compose exec test bundle exec rake db:migrate
after test container built and configured find out its id
docker container ls | grep travelpayouts_test
and run
docker attach <your test container id>
- Get your container id
docker container ls | grep travelpayouts_api
- Insert your byebug breakpoint
- run
docker attach <your api container id>
- ... PROFIT
- Press Ctrl+P then Ctrl+Q to detach after debugging is done