-
Notifications
You must be signed in to change notification settings - Fork 193
/
Copy pathfatality_notice_presenter.rb
72 lines (62 loc) · 2.09 KB
/
fatality_notice_presenter.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
module PublishingApi
class FatalityNoticePresenter
include Presenters::PublishingApi::UpdateTypeHelper
attr_reader :update_type
def initialize(item, update_type: nil)
@item = item
@update_type = update_type || default_update_type(item)
end
delegate :content_id, to: :item
def content
{}.tap do |content|
content.merge!(BaseItemPresenter.new(item, update_type:).base_attributes)
content.merge!(PayloadBuilder::PublicDocumentPath.for(item))
content.merge!(
description: item.summary,
document_type:,
public_updated_at: item.public_timestamp || item.updated_at,
rendering_app: item.rendering_app,
schema_name: "fatality_notice",
details:,
links: edition_links,
auth_bypass_ids: [item.auth_bypass_id],
)
content.merge!(PayloadBuilder::AccessLimitation.for(item))
content.merge!(PayloadBuilder::FirstPublishedAt.for(item))
end
end
def links
# TODO: Previously, this presenter was sending all links to the
# Publishing API at both the document level, and edition
# level. This is probably redundant, and hopefully can be
# improved.
edition_links
end
def edition_links
PayloadBuilder::Links.for(item).extract(
%i[organisations],
).merge(
field_of_operation: [item.operational_field.content_id],
).merge(
PayloadBuilder::People.for(item),
).merge(
PayloadBuilder::Roles.for(item),
)
end
def document_type
"fatality_notice"
end
private
attr_reader :item
def details
details_hash = {
body: Whitehall::GovspeakRenderer.new.govspeak_edition_to_html(item),
casualties: item.fatality_notice_casualties.map(&:personal_details),
change_history: item.change_history.as_json,
emphasised_organisations: item.lead_organisations.map(&:content_id),
roll_call_introduction: item.roll_call_introduction,
}
details_hash.merge!(PayloadBuilder::FirstPublicAt.for(item))
end
end
end