Class: FrontEndBuilds::AppsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/front_end_builds/apps_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#error!, #respond_with_json

Instance Method Details

#createObject



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

def create
  @app = FrontEndBuilds::App.new( app_create_params )

  if @app.save
    respond_with_json(
      { app: @app.serialize },
      location: nil
    )
  else
    respond_with_json(
      { errors: @app.errors },
      status: :unprocessable_entity
    )
  end
end

#destroyObject



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/controllers/front_end_builds/apps_controller.rb', line 61

def destroy
  if @app.destroy
    respond_with_json(
      { app: { id: @app.id } },
      location: nil
    )
  else
    respond_with_json(
      { errors: @app.errors },
      status: :unprocessable_entity
    )
  end
end

#indexObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/front_end_builds/apps_controller.rb', line 7

def index
  # this should be the most recent 10 builds for each app

  # DO NOT use `App.includes(:recent_builds)`
  # b/c it mucks up the grouping logic and only gives the most
  # recent 10 for ALL apps not 10 per app
  apps = App.all

  respond_with_json({
    apps: apps.map(&:serialize),
    builds: apps.map(&:recent_builds)
              .flat_map(&:to_a)
              .map(&:serialize)
  })
end

#showObject



23
24
25
26
27
28
# File 'app/controllers/front_end_builds/apps_controller.rb', line 23

def show
  respond_with_json({
    app: @app.serialize,
    builds: @app.recent_builds.map(&:serialize)
  })
end

#updateObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/controllers/front_end_builds/apps_controller.rb', line 46

def update
  if @app.update_attributes( app_update_params )

    respond_with_json(
      { app: @app.serialize },
      location: nil
    )
  else
    respond_with_json(
      { errors: @app.errors },
      status: :unprocessable_entity
    )
  end
end