Skip to content

Commit

Permalink
Merge pull request #23 from rubydevi/f/add-aeroplane
Browse files Browse the repository at this point in the history
Updated controller and models:params and validations and routes.
  • Loading branch information
RileyManda authored Nov 3, 2023
2 parents 72cc8ff + 631b8fe commit 1e60880
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
4 changes: 3 additions & 1 deletion app/controllers/aeroplanes_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class AeroplanesController < ApplicationController
before_action :set_aeroplane, only: %i[show update destroy]
before_action :authenticate_user!

# GET /aeroplanes
def index
Expand All @@ -16,11 +17,12 @@ def show
# POST /aeroplanes
def create
@aeroplane = Aeroplane.new(aeroplane_params)
# @aeroplane.user = User.id

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

Expand Down
6 changes: 5 additions & 1 deletion app/models/aeroplane.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ class Aeroplane < ApplicationRecord
has_many :reservations, dependent: :destroy

validates :name, presence: true
validates :model, presence: true
validates :image, presence: true
validates :fee, numericality: { greater_than_or_equal_to: 0.0 }
validates :description, presence: true
validates :number_of_seats, presence: true
validates :location, presence: true
validates :fee, numericality: { greater_than_or_equal_to: 0 }
end
7 changes: 4 additions & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
sessions: 'users/sessions',
registrations: 'users/registrations'
}

namespace :api do
namespace :v1 do
resources :users do
resources :reservations
resources :aeroplanes
resources :reservations
resources :aeroplanes
end
end
end
resources :aeroplanes
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html

# Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
Expand Down

0 comments on commit 1e60880

Please sign in to comment.