Class: Annotot::AnnotationsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/annotot/annotations_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /annotations



13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/annotot/annotations_controller.rb', line 13

def create
  @annotation = Annotation.new(annotation_params)

  if @annotation.save
    render json: @annotation.data
  else
    render status: :bad_request, json: {
      message: 'An annotation could not be created'
    }
  end
end

#destroyObject

DELETE /annotations/1



38
39
40
41
42
43
# File 'app/controllers/annotot/annotations_controller.rb', line 38

def destroy
  @annotation.destroy
  render status: :ok, json: {
    message: 'Annotation was successfully destroyed.'
  }
end

#indexObject

GET /annotations



8
9
10
# File 'app/controllers/annotot/annotations_controller.rb', line 8

def index
  @annotations = Annotation.where(canvas: annotation_search_params)
end

#updateObject

PATCH/PUT /annotations/1



26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/annotot/annotations_controller.rb', line 26

def update
  if @annotation.update(annotation_params)
    render status: :ok, json: @annotation.data
  else
    render status: :bad_request, json: {
      message: 'Annotation could not be updated.',
      status: :bad_request
    }
  end
end