Here's the solution for the suggested exercise using Rails 5 to build a tiny API.
The main difference between this solution and the description provided is that I'm modeling GroupEvent
here intended to be a Group
with many events on it and an additional User entity was introduced to reflect what I think that should be something more close to a tiny but useful first version.
Here's how the models relationship looks like:
============== ============== ==============
| | | | | |
| User | 1 => N | GroupEvent | 1 => N | Event |
| | | | | |
============== ============== ==============
Additionally, instead of Rspec the tests was intentionally written using the Minitest (included by default on Rails 5) and all test can be found in the /test folder.
Questions or feedbacks about this solution are very welcome at any time.
Regards, Tailor Fontela.
2.4.0
5.0.0.1
bundle install
rake db:setup
rake test
curl -d "user[name]=Lucas" http://localhost:3000/users
curl http://localhost:3000/users/#{user_id}
curl http://localhost:3000/users/
curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d ' {"group_event":{"title":"Canada Trip","days_duration":"20", "user_id":"1"}}' http://localhost:3000/group_events
curl http://localhost:3000/group_events
curl http://localhost:3000/group_events/#{group_event_id}
curl -H "Accept: application/json" -H "Content-type: application/json" -d '{"group_event":{"title":"Brazil Trip"}}' -X PATCH http://localhost:3000/group_events/#{group_event_id}
curl -H "Accept: application/json" -H "Content-type: application/json" -d ' {"event":{"name":"Passport","description":"renew the passport", "location":"São Paulo", "start_date":"10-10-2016", "end_date":"12-10-2016", "group_event_id": "1"}}' http://localhost:3000/events
curl http://localhost:3000/events/#{event_id}
curl http://localhost:3000/events/
curl -H "Accept: application/json" -H "Content-type: application/json" -d '{"event":{"name":"bubble fish"}}' -X PATCH http://localhost:3000/events/#{event_id}
curl -X DELETE http://localhost:3000/events/#{event_id}