Class: V1::TagsController

Inherits:
ApiController show all
Defined in:
app/controllers/v1/tags_controller.rb

Overview

Tags controller Allows the API to show and modify tags

Constant Summary

Constants included from ApiController::Parameters

ApiController::Parameters::PARAMS

Instance Method Summary collapse

Methods inherited from ApiController

#check_params_required, #return_response, #version

Methods included from ApiController::Metadata

#meta_attributes, #meta_pagination

Methods included from ApiController::Pagination

#compile_page, #select_page

Methods included from ApiController::Parameters

#check_params, #expand_resources?, #numeric?, #true?

Instance Method Details

#indexObject

@api get /tags Request index of tags

@apiVersion 1.0.0
@apiName GetTags
@apiPermission none
@apiGroup Tags
@apiSuccess {Object[]} data
@apiSuccess {Integer} data.id ID of the tag
@apiSuccess {String} data.name Tag name
@apiSuccess {Date} data.created_at
@apiSuccess {Date} data.updated_at
@apiUse NoContent
@apiSuccessExample {json} Success

{ “data”:

 [
 {
    "id": 1,
    "name": "report",
    "created_at": "2018-01-26T12:18:11.959Z",
    "updated_at": "2018-01-26T12:18:11.959Z"
 },
 {
    "id": 2,
    "name": "playbook",
    "created_at": "2018-01-26T12:18:11.965Z",
    "updated_at": "2018-01-26T12:18:11.965Z"
 },
 {
    "id": 3,
    "name": "dialogue",
    "created_at": "2018-01-26T12:18:11.970Z",
    "updated_at": "2018-01-26T12:18:11.970Z"
 },
 {
     "id": 4,
     "name": "workflow",
     "created_at": "2018-01-26T12:18:11.974Z",
     "updated_at": "2018-01-26T12:18:11.974Z"
   }
]

}


50
51
52
53
54
55
56
57
58
# File 'app/controllers/v1/tags_controller.rb', line 50

def index
  logger.debug 'Returning tags index'
  @tags = Tag.where('name like ?', "%#{params[:query]&.parameterize}%" )
  if @tags.count.positive?
    return_response @tags, :ok, {}
  else
    render  status: :no_content
  end
end

#showObject

@api get /tags/:id Request tag info

@apiVersion 1.0.0
@apiName GetTagInfo
@apiPermission none
@apiGroup Tags
@apiParam {String} id Tag id or name
@apiSuccess {Object} data
@apiSuccess {Integer} data.id ID of the tag
@apiSuccess {String} data.name Tag name
@apiSuccess {Date} data.created_at
@apiSuccess {Date} data.updated_at
@apiUse NoContent
@apiSuccessExample {json} Success

{

"data": {
    "id": 1,
    "name": "report",
    "created_at": "2018-01-26T12:18:11.959Z",
    "updated_at": "2018-01-26T12:18:11.959Z"
}

}


82
83
84
85
86
87
88
89
90
91
# File 'app/controllers/v1/tags_controller.rb', line 82

def show
  return unless  check_params_required(:id)
  logger.debug 'Returning tag @tag.name'
  @tag = Tag.find_by(name: params[:id])
  if @tag
    return_response  @tag, :ok, {}
  else
    render_error_exchange(:tag_not_found, :not_found, { tag_id: parans[:id]})
  end
end