如何避免重复代码?
resource 'api/publication/:publicationName' do
params do
requires :type, type: String, regexp: /^(static|dynamic)$/i
requires :name, type: String, regexp: /^[a-z0-9_\s]+$/i
requires :liveStartDate, type: String, regexp: dateRegexp
optional :liveEndDate, type: String, regexp: dateRegexp
requires :query, type: String
end
post '/dynamic' do
authenticate!
save_or_update(params)
end
params do
requires :type, type: String, regexp: /^(static|dynamic)$/i
requires :name, type: String, regexp: /^[a-z0-9_\s]+$/i
requires :liveStartDate, type: String, regexp: dateRegexp
optional :liveEndDate, type: String, regexp: dateRegexp
requires :query, type: String
end
put '/dynamic/:id' do
authenticate!
save_or_update(params)
end
end