Class: Api::V1::PostsController

Inherits:
BaseController show all
Includes:
PostsHelper
Defined in:
app/controllers/api/v1/posts_controller.rb

Instance Attribute Summary

Attributes included from OpenidConnect::ProtectedResourceEndpoint

#current_token

Instance Method Summary collapse

Methods included from PostsHelper

#post_iframe_url, #post_page_title

Methods included from OpenidConnect::ProtectedResourceEndpoint

#access_token?, #require_access_token

Instance Method Details

#createObject


27
28
29
30
31
32
33
34
35
# File 'app/controllers/api/v1/posts_controller.rb', line 27

def create
  creation_params = normalized_create_params
  raise StandardError unless creation_params[:public] || private_modify?

  @status_message = creation_service.create(creation_params)
  render json: PostPresenter.new(@status_message, current_user).as_api_response
rescue StandardError
  render_error 422, "Failed to create the post"
end

#destroyObject


37
38
39
40
41
42
# File 'app/controllers/api/v1/posts_controller.rb', line 37

def destroy
  post_service.destroy(params[:id], private_modify?)
  head :no_content
rescue Diaspora::NotMine, Diaspora::NonPublic
  render_error 403, "Not allowed to delete the post"
end

#showObject

Raises:

  • (ActiveRecord::RecordNotFound)

20
21
22
23
24
25
# File 'app/controllers/api/v1/posts_controller.rb', line 20

def show
  post = post_service.find!(params[:id])
  raise ActiveRecord::RecordNotFound unless post.public? || private_read?

  render json: post_as_json(post)
end