Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions app/controllers/departments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ def index

# GET /departments/1
def show
render json: @department
end

private
# Use callbacks to share common setup or constraints between actions.
def set_department
@department = Department.find(params.expect(:id))
id = params.expect(:id)
if id.match(/[0-9]/)
@department = Department.find(id)
else
@department = Department.find_by(slug: id)
end
end
end
1 change: 0 additions & 1 deletion app/controllers/promises_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ def index

def show
@promise = Promise.find(params[:id])
render json: @promise
end
end
4 changes: 3 additions & 1 deletion app/models/department.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class Department < ApplicationRecord
belongs_to :government
has_many :ministers
has_many :officials, class_name: "Minister", dependent: :destroy
has_one :minister, -> { where(role: "Minister") }, class_name: "Minister"


has_many :department_promises, dependent: :destroy
has_many :promises, through: :department_promises
Expand Down
14 changes: 14 additions & 0 deletions app/views/departments/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

json.(@department, :slug, :display_name, :official_name, :priority)

json.minister do
if @department.minister.present?
json.partial! @department.minister, as: :minister
else
json.null!
end
end

json.promises do
json.partial! "promises/promise_listing", collection: @department.lead_promises, as: :promise
end
10 changes: 10 additions & 0 deletions app/views/ministers/_minister.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
json.(minister,
:order_of_precedence,
:started_at,
:ended_at,
:first_name,
:last_name,
:last_name,
:title,
:avatar_url,
:person_short_honorific)
25 changes: 25 additions & 0 deletions app/views/promises/_promise_listing.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Need: status, last_update, title, description, build_canada_alignment, impact,
#


json.(promise,
:id,
:concise_title,
:description,
:text
)

# TODO: cache this on promise so we don't have to query the database every time
json.last_evidence_at promise.evidences.order(updated_at: :desc).first&.updated_at&.strftime("%Y-%m-%d")

json.(promise,
:bc_promise_direction,
:bc_promise_rank,
:bc_promise_rank_rationale
)

json.(promise,
:progress_score,
:progress_summary,

)
16 changes: 16 additions & 0 deletions app/views/promises/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

json.(@promise,
:id,
:text,
:description,
:commitment_history_rationale,
:what_it_means_for_canadians,
:concise_title,
:progress_score,
:progress_summary,
:source_type,
:date_issued,
)

# TODO: cache this on promise so we don't have to query the database every time
json.last_evidence_at @promise.evidences.order(updated_at: :desc).first&.updated_at&.strftime("%Y-%m-%d")
Loading