-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from rubydevi/f/jet-show
Details show
- Loading branch information
Showing
2 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
class ReservationsController < ApplicationController | ||
before_action :set_reservation, only: %i[show update destroy] | ||
|
||
# GET /reservations | ||
def index | ||
@reservations = Reservation.all | ||
|
||
render json: @reservations | ||
end | ||
|
||
# GET /reservations/1 | ||
def show | ||
render json: @reservation | ||
end | ||
|
||
# POST /reservations | ||
def create | ||
@reservation = Reservation.new(reservation_params) | ||
|
||
if @reservation.save | ||
render json: @reservation, status: :created, location: @reservation | ||
else | ||
render json: @reservation.errors, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
# PATCH/PUT /reservations/1 | ||
def update | ||
if @reservation.update(reservation_params) | ||
render json: @reservation | ||
else | ||
render json: @reservation.errors, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
# DELETE /reservations/1 | ||
def destroy | ||
@reservation.destroy! | ||
end | ||
|
||
private | ||
|
||
# Use callbacks to share common setup or constraints between actions. | ||
def set_reservation | ||
@reservation = Reservation.find(params[:id]) | ||
end | ||
|
||
# Only allow a list of trusted parameters through. | ||
def reservation_params | ||
params.require(:reservation).permit(:reserved_date, :start_time, :end_time, :total_cost, :start_location, | ||
:destination, :user_id, :aeroplane_id) | ||
end | ||
end |