Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP dj application voting #47

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/controllers/host_applications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions app/models/host_application.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class HostApplication < ApplicationRecord
belongs_to :radio
has_many :host_application_votes

validates :email, presence: true
validates :username, presence: true
Expand Down
4 changes: 4 additions & 0 deletions app/models/host_application_vote.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class HostApplicationVote < ApplicationRecord
belongs_to :host_application
belongs_to :user
end
1 change: 1 addition & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/host_application_serializer.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions app/serializers/host_application_vote_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class HostApplicationVoteSerializer < ActiveModel::Serializer
attributes :id, :approve
end
11 changes: 11 additions & 0 deletions db/migrate/20201116011656_create_host_application_votes.rb
Original file line number Diff line number Diff line change
@@ -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
13 changes: 12 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down