diff --git a/app/controllers/host_applications_controller.rb b/app/controllers/host_applications_controller.rb index f26844e2..7624c666 100644 --- a/app/controllers/host_applications_controller.rb +++ b/app/controllers/host_applications_controller.rb @@ -5,6 +5,13 @@ class HostApplicationsController < ApplicationController def index # authorize! :manage, HostApplication @host_applications = @current_radio.host_applications + respond_to do |format| + format.html + format.json { + response.headers["Access-Control-Allow-Origin"] = "*" # This is a public API, maybe I should namespace it later + render json: @host_applications + } + end end def create diff --git a/app/models/host_application.rb b/app/models/host_application.rb index 900d72ab..62a960bc 100644 --- a/app/models/host_application.rb +++ b/app/models/host_application.rb @@ -1,5 +1,6 @@ class HostApplication < ApplicationRecord belongs_to :radio + has_many :host_application_votes validates :email, presence: true validates :username, presence: true diff --git a/app/models/host_application_vote.rb b/app/models/host_application_vote.rb new file mode 100644 index 00000000..34ae3536 --- /dev/null +++ b/app/models/host_application_vote.rb @@ -0,0 +1,4 @@ +class HostApplicationVote < ApplicationRecord + belongs_to :host_application + belongs_to :user +end diff --git a/app/models/user.rb b/app/models/user.rb index 4579d09a..2f056329 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -12,6 +12,7 @@ class User < ActiveRecord::Base has_many :performers, through: :scheduled_show_performers, source: :user has_many :scheduled_shows, -> { includes :tracks }, through: :scheduled_show_performers has_many :tracks, through: :scheduled_shows + has_many :host_application_votes has_attached_file :image, styles: { :thumb => "150x150#", :medium => "250x250#" }, path: ":attachment/:style/:basename.:extension" diff --git a/app/serializers/host_application_serializer.rb b/app/serializers/host_application_serializer.rb index f30f035d..a90ca46a 100644 --- a/app/serializers/host_application_serializer.rb +++ b/app/serializers/host_application_serializer.rb @@ -1,3 +1,3 @@ class HostApplicationSerializer < ActiveModel::Serializer - attributes :id, :email, :username, :link, :homepage_url, :desired_time, :interval, :other_comment + attributes :id, :email, :username, :link, :homepage_url, :desired_time, :interval, :other_comment, :approved, :created_at end diff --git a/app/serializers/host_application_vote_serializer.rb b/app/serializers/host_application_vote_serializer.rb new file mode 100644 index 00000000..dd3d5ea7 --- /dev/null +++ b/app/serializers/host_application_vote_serializer.rb @@ -0,0 +1,3 @@ +class HostApplicationVoteSerializer < ActiveModel::Serializer + attributes :id, :approve +end diff --git a/db/migrate/20201116011656_create_host_application_votes.rb b/db/migrate/20201116011656_create_host_application_votes.rb new file mode 100644 index 00000000..bb4db413 --- /dev/null +++ b/db/migrate/20201116011656_create_host_application_votes.rb @@ -0,0 +1,11 @@ +class CreateHostApplicationVotes < ActiveRecord::Migration[5.0] + def change + create_table :host_application_votes do |t| + t.references :host_application, null: false, index: true + t.references :user, null: false, index: true + t.boolean :approve, null: false + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 397ce29b..3f04e98b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20200731081550) do +ActiveRecord::Schema.define(version: 20201116011656) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -57,6 +57,16 @@ t.index ["sluggable_type"], name: "index_friendly_id_slugs_on_sluggable_type", using: :btree end + create_table "host_application_votes", force: :cascade do |t| + t.integer "host_application_id", null: false + t.integer "user_id", null: false + t.boolean "approve", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["host_application_id"], name: "index_host_application_votes_on_host_application_id", using: :btree + t.index ["user_id"], name: "index_host_application_votes_on_user_id", using: :btree + end + create_table "host_applications", force: :cascade do |t| t.integer "radio_id", null: false t.string "email", null: false @@ -241,6 +251,7 @@ t.string "title" t.string "time_zone" t.string "slug" + t.boolean "notify_twitter", default: false, null: false t.index ["dj_id"], name: "index_scheduled_shows_on_dj_id", using: :btree t.index ["playlist_id"], name: "index_scheduled_shows_on_playlist_id", using: :btree t.index ["radio_id"], name: "index_scheduled_shows_on_radio_id", using: :btree