You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.3 KiB
56 lines
1.3 KiB
module Api |
|
module Doctrine |
|
class AnnotationsController < ::Api::BaseController |
|
load_and_authorize_resource :doctrine, class: "Doctrine" |
|
load_and_authorize_resource :annotation, class: "Annotation", through: :doctrine |
|
|
|
def index |
|
respond_with @annotations |
|
end |
|
|
|
def show |
|
respond_with @annotation |
|
end |
|
|
|
def create |
|
attrs = resource_params.to_unsafe_h.deep_symbolize_keys |
|
subject_ids = attrs.delete(:subject_ids) |
|
|
|
@annotation = @doctrine.annotations.new(attrs) |
|
|
|
if @annotation.save |
|
@annotation.subject_ids = subject_ids if subject_ids.present? |
|
|
|
respond_with @annotation |
|
else |
|
render errors: @annotation.errors, status: 422 |
|
end |
|
end |
|
|
|
def update |
|
attrs = resource_params.to_unsafe_h.deep_symbolize_keys |
|
subject_ids = attrs.delete(:subject_ids) |
|
|
|
if @annotation.update(attrs) |
|
@annotation.subject_ids = subject_ids if subject_ids.present? |
|
|
|
respond_with @annotation |
|
else |
|
render errors: @annotation.errors, status: 422 |
|
end |
|
end |
|
|
|
def destroy |
|
@annotation.destroy |
|
|
|
respond_with @annotation |
|
end |
|
|
|
private |
|
|
|
def resource_params |
|
params.permit(:content, subject_ids: []) |
|
end |
|
end |
|
end |
|
end
|
|
|