2016-08-25 19:34:01 -04:00
|
|
|
module API
|
|
|
|
class BroadcastMessages < Grape::API
|
2016-11-21 14:15:46 -05:00
|
|
|
include PaginationParams
|
|
|
|
|
2016-08-25 19:34:01 -04:00
|
|
|
before { authenticate! }
|
|
|
|
before { authenticated_as_admin! }
|
|
|
|
|
|
|
|
resource :broadcast_messages do
|
|
|
|
helpers do
|
|
|
|
def find_message
|
|
|
|
BroadcastMessage.find(params[:id])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Get all broadcast messages' do
|
|
|
|
detail 'This feature was introduced in GitLab 8.12.'
|
|
|
|
success Entities::BroadcastMessage
|
|
|
|
end
|
|
|
|
params do
|
2016-11-21 14:15:46 -05:00
|
|
|
use :pagination
|
2016-08-25 19:34:01 -04:00
|
|
|
end
|
|
|
|
get do
|
|
|
|
messages = BroadcastMessage.all
|
|
|
|
|
|
|
|
present paginate(messages), with: Entities::BroadcastMessage
|
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Create a broadcast message' do
|
|
|
|
detail 'This feature was introduced in GitLab 8.12.'
|
|
|
|
success Entities::BroadcastMessage
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :message, type: String, desc: 'Message to display'
|
|
|
|
optional :starts_at, type: DateTime, desc: 'Starting time', default: -> { Time.zone.now }
|
|
|
|
optional :ends_at, type: DateTime, desc: 'Ending time', default: -> { 1.hour.from_now }
|
|
|
|
optional :color, type: String, desc: 'Background color'
|
|
|
|
optional :font, type: String, desc: 'Foreground color'
|
|
|
|
end
|
|
|
|
post do
|
2016-11-14 08:44:27 -05:00
|
|
|
message = BroadcastMessage.create(declared_params(include_missing: false))
|
2016-08-25 19:34:01 -04:00
|
|
|
|
|
|
|
if message.persisted?
|
|
|
|
present message, with: Entities::BroadcastMessage
|
|
|
|
else
|
|
|
|
render_validation_error!(message)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Get a specific broadcast message' do
|
|
|
|
detail 'This feature was introduced in GitLab 8.12.'
|
|
|
|
success Entities::BroadcastMessage
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :id, type: Integer, desc: 'Broadcast message ID'
|
|
|
|
end
|
|
|
|
get ':id' do
|
|
|
|
message = find_message
|
|
|
|
|
|
|
|
present message, with: Entities::BroadcastMessage
|
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Update a broadcast message' do
|
|
|
|
detail 'This feature was introduced in GitLab 8.12.'
|
|
|
|
success Entities::BroadcastMessage
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :id, type: Integer, desc: 'Broadcast message ID'
|
|
|
|
optional :message, type: String, desc: 'Message to display'
|
|
|
|
optional :starts_at, type: DateTime, desc: 'Starting time'
|
|
|
|
optional :ends_at, type: DateTime, desc: 'Ending time'
|
|
|
|
optional :color, type: String, desc: 'Background color'
|
|
|
|
optional :font, type: String, desc: 'Foreground color'
|
|
|
|
end
|
|
|
|
put ':id' do
|
|
|
|
message = find_message
|
|
|
|
|
2016-11-14 08:44:27 -05:00
|
|
|
if message.update(declared_params(include_missing: false))
|
2016-08-25 19:34:01 -04:00
|
|
|
present message, with: Entities::BroadcastMessage
|
|
|
|
else
|
|
|
|
render_validation_error!(message)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Delete a broadcast message' do
|
|
|
|
detail 'This feature was introduced in GitLab 8.12.'
|
|
|
|
success Entities::BroadcastMessage
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :id, type: Integer, desc: 'Broadcast message ID'
|
|
|
|
end
|
|
|
|
delete ':id' do
|
|
|
|
message = find_message
|
|
|
|
|
2017-03-02 07:14:13 -05:00
|
|
|
destroy_conditionally!(message)
|
2016-08-25 19:34:01 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|