Class: Railscope::Api::EntriesController

Inherits:
Railscope::ApplicationController show all
Defined in:
app/controllers/railscope/api/entries_controller.rb

Instance Method Summary collapse

Instance Method Details

#batch ⇒ Object



34
35
36
37
38
39
40
# File 'app/controllers/railscope/api/entries_controller.rb', line 34

def batch
  entries = storage.for_batch(params[:batch_id])

  render json: {
    data: entries.map { |e| serialize_entry(e) }
  }
end

#destroy ⇒ Object



57
58
59
60
# File 'app/controllers/railscope/api/entries_controller.rb', line 57

def destroy
  storage.destroy_all!
  render json: { success: true }
end

#family ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/railscope/api/entries_controller.rb', line 42

def family
  entries = storage.for_family(params[:family_hash], page: current_page, per_page: per_page)
  total_count = storage.family_count(params[:family_hash])

  render json: {
    data: entries.map { |e| serialize_entry(e) },
    meta: {
      current_page: current_page,
      total_pages: (total_count.to_f / per_page).ceil,
      total_count: total_count,
      per_page: per_page
    }
  }
end

#index ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/railscope/api/entries_controller.rb', line 8

def index
  filters = extract_filters
  entries = storage.all(filters: filters, page: current_page, per_page: per_page)
  total_count = storage.count(filters: filters)

  render json: {
    data: entries.map { |e| serialize_entry(e) },
    meta: {
      current_page: current_page,
      total_pages: (total_count.to_f / per_page).ceil,
      total_count: total_count,
      per_page: per_page
    }
  }
end

#show ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'app/controllers/railscope/api/entries_controller.rb', line 24

def show
  entry = storage.find!(params[:id])
  batch_entries = storage.for_batch(entry.batch_id).reject { |e| e.uuid == entry.uuid }.first(100)

  render json: {
    data: serialize_entry(entry, include_family_count: true),
    batch: batch_entries.map { |e| serialize_entry(e) }
  }
end