Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jp/update #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,18 @@ Trip API™

## Send Data
- **Reserve a Spot on a Trip:**
- https://trektravel.herokuapp.com/trips/1/reserve
- required params: name, age, email
- https://trektravel.herokuapp.com/trips/1/reservations
- accepted params:
- name (string)
- age (integer)
- email (string)

- **Add a New Trip:**
- https://trektravel.herokuapp.com/trips/new
- required params: name, destination, continent, about, category, weeks, cost, available, expires
- accepted params:
- name (string)
- continent (string)
- about (string)
- category (string)
- weeks (integer)
- cost (float)
16 changes: 10 additions & 6 deletions app/controllers/trips_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ def create
)

if trip.save
render :json => trip.to_json, :callback => params['callback'],
render :json => trip.as_json(:only => [:id, :name, :continent, :about, :category, :weeks, :cost]), :callback => params['callback'],
:status => :ok
else
render :json => [], :callback => params['callback'], :status => :no_content
render :json => [], :callback => params['callback'], :status => :bad_request
end
end

Expand All @@ -35,26 +35,30 @@ def reserve
)

if reservation.save
render :json => trip.to_json, :callback => params['callback'],
render :json => reservation.as_json(:only => [:name, :email, :trip_id]), :callback => params['callback'],
:status => :ok
else
render :json => [], :callback => params['callback'], :status => :no_content
render :json => [], :callback => params['callback'], :status => :bad_request
end
end

def reservations
trip = Trip.find_by(id: params[:id])
reservations = trip.trip_reservations

render :json => reservations.as_json,
render :json => reservations.as_json(:only => [:id, :name, :email, :trip_id]),
:callback => params['callback'],
:status => :ok
end

def show
trip = Trip.find_by(id: params[:id])

render :json => trip, :callback => params['callback'], status => :okay
if trip
render :json => trip.as_json(:only => [:id, :name, :continent, :about, :category, :weeks, :cost]), :callback => params['callback'], status => :ok
else
render :json => [], :callback => params['callback'], :status => :no_content
end
end

def continent
Expand Down
3 changes: 1 addition & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
get 'trips/budget', to: 'trips#budget', as: 'trips_budget'
get 'trips/weeks', to: 'trips#weeks', as: 'trips_weeks'
get 'trips/category', to: 'trips#category', as: 'trips_category'
get 'trips/search', to: 'trips#search', as: 'trips_search'

post 'trips/:id/reserve', to: 'trips#reserve'
post 'trips/:id/reservations', to: 'trips#reserve'

get 'trips/:id/reservations', to: 'trips#reservations', as: 'trips_reservations'

Expand Down