Skip to content

Commit 94a084c

Browse files
committed
fix(signage/triggers): playlist application
1 parent 2fe8e3b commit 94a084c

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

OPENAPI_DOC.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26633,6 +26633,11 @@ components:
2663326633
exec_enabled:
2663426634
type: boolean
2663526635
nullable: true
26636+
playlists:
26637+
type: array
26638+
items:
26639+
type: string
26640+
nullable: true
2663626641
NamedTuple_url__String_:
2663726642
type: object
2663826643
properties:

src/placeos-rest-api/controllers/system-triggers.cr

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ module PlaceOS::Api
101101
render_system_trigger(current_sys_trig, complete: complete)
102102
end
103103

104-
record UpdateParams, enabled : Bool?, important : Bool?, exec_enabled : Bool? do
104+
record UpdateParams, enabled : Bool?, important : Bool?, exec_enabled : Bool?, playlists : Array(String)? do
105105
include JSON::Serializable
106106
end
107107

@@ -113,6 +113,14 @@ module PlaceOS::Api
113113
current.enabled = args.enabled.as(Bool) unless args.enabled.nil?
114114
current.important = args.important.as(Bool) unless args.important.nil?
115115
current.exec_enabled = args.exec_enabled.as(Bool) unless args.exec_enabled.nil?
116+
# validate the playlist ids
117+
if playlists = args.playlists
118+
if playlists.empty?
119+
current.playlists = playlists
120+
else
121+
current.playlists = ::PlaceOS::Model::Playlist.find_all(playlists).map(&.id.as(String))
122+
end
123+
end
116124
raise Error::ModelValidation.new(current.errors) unless current.save
117125
current
118126
end
@@ -125,6 +133,9 @@ module PlaceOS::Api
125133
sys_id : String,
126134
) : ::PlaceOS::Model::TriggerInstance
127135
trig_inst.control_system_id = sys_id
136+
if (playlists = trig_inst.playlists) && !playlists.empty?
137+
trig_inst.playlists = ::PlaceOS::Model::Playlist.find_all(playlists).map(&.id.as(String))
138+
end
128139
raise Error::ModelValidation.new(trig_inst.errors) unless trig_inst.save
129140
trig_inst
130141
end

0 commit comments

Comments
 (0)