Class: Api::V1::ResharesController

Inherits:
BaseController show all
Defined in:
app/controllers/api/v1/reshares_controller.rb

Instance Attribute Summary

Attributes included from OpenidConnect::ProtectedResourceEndpoint

#current_token

Instance Method Summary collapse

Methods included from OpenidConnect::ProtectedResourceEndpoint

#access_token?, #require_access_token

Instance Method Details

#createObject


35
36
37
38
39
40
41
42
43
# File 'app/controllers/api/v1/reshares_controller.rb', line 35

def create
  reshare = reshare_service.create(params.require(:post_id))
rescue ActiveRecord::RecordInvalid
  render_error 409, "Reshare already exists"
rescue ActiveRecord::RecordNotFound, RuntimeError
  render_error 422, "Failed to reshare"
else
  render json: PostPresenter.new(reshare, current_user).as_api_response
end

#showObject


22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/api/v1/reshares_controller.rb', line 22

def show
  reshares_query = reshare_service.find_for_post(params.require(:post_id))
  reshares_page = index_pager(reshares_query).response
  reshares_page[:data] = reshares_page[:data].map do |r|
    {
      guid:   r.guid,
      created_at: r.created_at,
      author: PersonPresenter.new(r.author).as_api_json
    }
  end
  render_paged_api_response reshares_page
end