Class: Api::PinnedSearchesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/api/pinned_searches_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

Create a pinned search

  • :query - The search query string

  • :name - The display name of the search

Example

POST api/pinned_searchesjson

{ "pinned_search" : { "query" : "owner:octobox inbox:true", "name" : "Work" } }

{
  "id" : 35778,
  "user_id" : 11741,
  "query" : "owner:octobox inbox:true",
  "name" : "Work",
  "count" : 0,
  "created_at" : "2021-11-23T19:48:39.953Z",
  "updated_at" : "2021-11-23T19:48:39.953Z"
}


22
23
24
25
26
27
28
29
# File 'app/controllers/api/pinned_searches_controller.rb', line 22

def create
  @pinned_search = current_user.pinned_searches.build(pinned_search_params)
  if @pinned_search.save
    render 'show'
  else
    render json: { errors: @pinned_search.errors.full_messages.to_sentence }, status: :unprocessable_entity
  end
end

#destroyObject

Delete a pinned search

Example

DELETE api/pinned_searches/:id.json

HEAD OK


67
68
69
70
71
# File 'app/controllers/api/pinned_searches_controller.rb', line 67

def destroy
  @pinned_search = current_user.pinned_searches.find(params[:id])
  @pinned_search.destroy
  head :ok
end

#indexObject

List users pinned searches

Example

GET api/pinned_searches.json

{

"pinned_searches":[
  {
    "id":35794,
    "user_id":11746,
    "query":"state:closed,merged archived:false",
    "name":"Archivable",
    "count":0,
    "created_at":"2021-11-23T19:52:19.097Z",
    "updated_at":"2021-11-23T19:52:19.097Z"
  }
]

}



93
94
95
# File 'app/controllers/api/pinned_searches_controller.rb', line 93

def index
  @pinned_searches = current_user.pinned_searches
end

#showObject

Get a single pinned search

Example

GET api/pinned_searches/:id.json

{
  "id" : 35778,
  "user_id" : 11741,
  "query" : "owner:octobox inbox:true",
  "name" : "Work",
  "count" : 0,
  "created_at" : "2021-11-23T19:48:39.953Z",
  "updated_at" : "2021-11-23T19:48:39.953Z"
}


113
114
115
# File 'app/controllers/api/pinned_searches_controller.rb', line 113

def show
  @pinned_search = current_user.pinned_searches.find(params[:id])
end

#updateObject

Update a pinned search

  • :query - The search query string

  • :name - The display name of the search

Example

PATCH api/pinned_searches/:id.json

{ "pinned_search" : { "query" : "owner:octobox inbox:true", "name" : "Work" } }

{
  "id" : 35778,
  "user_id" : 11741,
  "query" : "owner:octobox inbox:true",
  "name" : "Work",
  "count" : 0,
  "created_at" : "2021-11-23T19:48:39.953Z",
  "updated_at" : "2021-11-23T19:48:39.953Z"
}


51
52
53
54
55
56
57
58
# File 'app/controllers/api/pinned_searches_controller.rb', line 51

def update
  @pinned_search = current_user.pinned_searches.find(params[:id])
  if @pinned_search.update(pinned_search_params)
    render 'show'
  else
    render json: { errors: @pinned_search.errors.full_messages.to_sentence }, status: :unprocessable_entity
  end
end