Class: Wco::Api::NewspartialsController

Inherits:
Wco::ApiController
  • Object
show all
Defined in:
app/controllers/wco/api/newspartials_controller.rb

Instance Method Summary collapse

Instance Method Details

#add_configObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/wco/api/newspartials_controller.rb', line 9

def add_config
  puts! params, 'api newspartials#add_config params'

  @newspartial = Wco::Newspartial.find params[:id]
  authorize! :create, @newspartial

  raw_payload = request.raw_post
  # parsed_payload = JSON.parse(raw_payload)
  @newspartial.config_json = raw_payload

  if @newspartial.save
    puts! @newspartial, 'added config to a newspartial.'
    flash[:notice] = 'Success'
    render json: { status: :ok, message: 'added config to a newspartial.' }
  else
    flash[:alert] = 'No luck'
    render json: { status: :not_ok, message: "Could not add config to newspartial: #{@newspartial.errors.full_messages.join(', ')}." }
  end
end

#createObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/wco/api/newspartials_controller.rb', line 30

def create
  puts! params, 'api newspartials#create params'

  @newspartial = Wco::Newspartial.new params[:newspartial].permit!
  @newspartial.author = Wco::Profile.find_by email: current_user.email
  authorize! :create, @newspartial

  if @newspartial.save
    puts! @newspartial, 'Created a newspartial.'
    flash[:notice] = 'Success'
    render json: { status: :ok, message: @newspartial.attributes }
  else
    flash[:alert] = 'No luck'
    render json: { status: :not_ok, message: "Could not create a newspartial: #{@newspartial.errors.full_messages.join(', ')}." }
  end
end

#show_configObject



47
48
49
50
# File 'app/controllers/wco/api/newspartials_controller.rb', line 47

def show_config
  @newspartial = Wco::Newspartial.find params[:id]
  render json: @newspartial.speech_json
end