d193c9a53c
* add starred to maps API and endpoint to create/delete * add token to requests without token param * add minor version number to api version * metacode/user use uri in schema * make code climate happier
29 lines
737 B
Ruby
29 lines
737 B
Ruby
# frozen_string_literal: true
|
|
module Api
|
|
module V2
|
|
class StarsController < RestfulController
|
|
skip_before_action :load_resource
|
|
|
|
def create
|
|
@map = Map.find(params[:id])
|
|
@star = Star.new(user: current_user, map: @map)
|
|
authorize @map, :star?
|
|
create_action
|
|
|
|
if @star.errors.empty?
|
|
render json: @map, scope: default_scope, serializer: MapSerializer, root: serializer_root
|
|
else
|
|
respond_with_errors
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
@map = Map.find(params[:id])
|
|
authorize @map, :unstar?
|
|
@star = @map.stars.find_by(user: current_user)
|
|
@star.destroy if @star.present?
|
|
head :no_content
|
|
end
|
|
end
|
|
end
|
|
end
|