Class: NewsmastMastodon::Api::V1::DraftedStatusesController

Inherits:
Api::BaseController
  • Object
show all
Includes:
Authorization
Defined in:
app/controllers/newsmast_mastodon/api/v1/drafted_statuses_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/newsmast_mastodon/api/v1/drafted_statuses_controller.rb', line 16

def create 
  @status = post_status_service
  
  render json: @status, serializer: LongPost::DraftedStatusSerializer
rescue PostStatusService::UnexpectedMentionsError => e
  unexpected_accounts = ActiveModel::Serializer::CollectionSerializer.new(
    e.accounts,
    serializer: REST::AccountSerializer
  )
  render json: { error: e.message, unexpected_accounts: unexpected_accounts }, status: 422
end

#destroyObject



49
50
51
52
# File 'app/controllers/newsmast_mastodon/api/v1/drafted_statuses_controller.rb', line 49

def destroy
  @status.destroy!
  render_empty
end

#indexObject



28
29
30
# File 'app/controllers/newsmast_mastodon/api/v1/drafted_statuses_controller.rb', line 28

def index
  render json: render_custom_grouped_dates
end

#publishObject



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/newsmast_mastodon/api/v1/drafted_statuses_controller.rb', line 54

def publish
  @status.destroy!

  @status = post_status_service(is_draft: false)
  
  render json: @status, serializer: @status.is_a?(ScheduledStatus) ? REST::ScheduledStatusSerializer : REST::StatusSerializer
rescue PostStatusService::UnexpectedMentionsError => e
unexpected_accounts = ActiveModel::Serializer::CollectionSerializer.new(
  e.accounts,
  serializer: REST::AccountSerializer
)
render json: { error: e.message, unexpected_accounts: unexpected_accounts }, status: 422
end

#showObject



32
33
34
# File 'app/controllers/newsmast_mastodon/api/v1/drafted_statuses_controller.rb', line 32

def show
  render json: @status, serializer: LongPost::DraftedStatusSerializer
end

#updateObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/newsmast_mastodon/api/v1/drafted_statuses_controller.rb', line 36

def update 
  @status.destroy!
  @status = post_status_service
  
  render json: @status, serializer: LongPost::DraftedStatusSerializer
rescue PostStatusService::UnexpectedMentionsError => e
  unexpected_accounts = ActiveModel::Serializer::CollectionSerializer.new(
    e.accounts,
    serializer: REST::AccountSerializer
  )
  render json: { error: e.message, unexpected_accounts: unexpected_accounts }, status: 422
end