Skip to content

Commit

Permalink
Merge pull request #24 from rubydevi/f/jet-show
Browse files Browse the repository at this point in the history
Details show
  • Loading branch information
Yonashenok authored Nov 4, 2023
2 parents 1e60880 + ef34d29 commit 25f70db
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
43 changes: 43 additions & 0 deletions app/controllers/api/v1/aeroplanes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,47 @@ def index

render json: { aeroplanes: @aeroplanes }
end

# GET /aeroplanes/1
def show
@aeroplane = Aeroplane.find(params[:id])
render json: @aeroplane
end

def create
@aeroplane = Aeroplane.new(aeroplane_params)

if @aeroplane.save
render json: @aeroplane, status: :created, location: @aeroplane
else
render json: @aeroplane.errors, status: :unprocessable_entity
end
end

# PATCH/PUT /aeroplanes/1
def update
if @aeroplane.update(aeroplane_params)
render json: @aeroplane
else
render json: @aeroplane.errors, status: :unprocessable_entity
end
end

# DELETE /aeroplanes/1
def destroy
@aeroplane.destroy!
end

private

# Use callbacks to share common setup or constraints between actions.
def set_aeroplane
@aeroplane = Aeroplane.find(params[:id])
end

# Only allow a list of trusted parameters through.
def aeroplane_params
params.require(:aeroplane).permit(:name, :model, :image, :description, :number_of_seats, :location, :fee,
:reserved)
end
end
53 changes: 53 additions & 0 deletions app/controllers/api/v1/reservations_controller.rb
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

0 comments on commit 25f70db

Please sign in to comment.