watermarkchurch/tessa

View on GitHub
app/controllers/uploads_controller.rb

Summary

Maintainability
A
0 mins
Test Coverage
class UploadsController < Sinatra::Base
  before do
    content_type "application/json"
  end

  UPLOAD_PARAMS = %w[
    strategy
    name
    size
    date
    mime_type
  ]

  post "/" do
    upload = Upload.new(upload_params)
    if upload.save
      upload.to_json
    else
      status 422
      {
        error: "Invalid options for new upload!",
      }.to_json
    end
  end

  def upload_params
    params
      .select { |k,v| UPLOAD_PARAMS.include?(k) }
      .merge(username: username)
  end

  def username
    request.env['REMOTE_USER']
  end
end