mirror of
https://github.com/fspc/BikeShed-1.git
synced 2026-09-16 16:31:38 -04:00
WIP, adding api/bikes_controller#create
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
class Api::V1::BikesController < Api::V1::BaseController
|
||||
CANNOT_MANAGE = "You do not have permission to manage bikes."
|
||||
EXPECTED_BIKE = "Expected bike in submitted data"
|
||||
|
||||
before_filter :check_bike_permission
|
||||
|
||||
def create
|
||||
puts params.inspect
|
||||
|
||||
if bike = params[:bike]
|
||||
|
||||
b = Bike.new(bike)
|
||||
if !b.save
|
||||
render json: { errors: b.errors }, status: 409 and return
|
||||
else
|
||||
render json: { bike: b.as_json }, status: 200 and return
|
||||
end
|
||||
|
||||
else
|
||||
render json: { errors: ["Expected bike in submitted data" ]}, status: 400 and return
|
||||
end
|
||||
render json: {}, status: 200 and return
|
||||
end
|
||||
|
||||
private
|
||||
def check_bike_permission
|
||||
if cannot? :manage, Bike
|
||||
render json: { errors: [CANNOT_MANAGE]}, status: 403 and return
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user