-
Notifications
You must be signed in to change notification settings - Fork 0
Base models and migrations #1
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| class ApplicationController < ActionController::API | ||
|
|
||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| class AttendeesController < ApplicationController | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| class RoomsController < ApplicationController | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| class VenuesController < ApplicationController | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| class Attendee < ApplicationRecord | ||
| belongs_to :room | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| class Room < ApplicationRecord | ||
| has_and_belongs_to_many :venues | ||
| has_many :attendees | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| class RoomVenue < ApplicationRecord | ||
| belongs_to :room | ||
| belongs_to :venue | ||
|
|
||
| has_many :votes | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| class Venue < ApplicationRecord | ||
| has_and_belongs_to_many :rooms | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| class Vote < ApplicationRecord | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,6 @@ | ||
| Rails.application.routes.draw do | ||
|
|
||
| # GET route to know that API is online. | ||
| # Limited to json requests - sends a 200 response with empty headers and empty response body | ||
| if Rails.env.development? | ||
| get '/', to: proc { [200, {}, ['']] }, constraints: { format: 'json' } | ||
| end | ||
|
|
||
|
|
||
|
|
||
| post '/rooms', to: 'rooms#create' | ||
| post 'rooms/:invite', to: 'rooms#join' | ||
| post '/venues', to: 'venues#create' | ||
| post '/attendees', to: 'attendees#create' | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| class CreateRoomsAndVenues < ActiveRecord::Migration[7.1] | ||
| def change | ||
| create_table :rooms do |t| | ||
| t.string :invite_code | ||
| t.integer :host_id | ||
| t.integer :status | ||
|
|
||
| t.timestamps | ||
| end | ||
|
|
||
| create_table :venues do |t| | ||
| t.integer :cost | ||
| t.string :menu_link | ||
| t.integer :rating | ||
| t.integer :category_id | ||
|
|
||
| t.timestamps | ||
| end | ||
|
|
||
| create_table :rooms_venues do |t| | ||
| # Intentionally keeping the id column to reference at vote time | ||
| t.belongs_to :room | ||
| t.belongs_to :venue | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| class CreateAttendees < ActiveRecord::Migration[7.1] | ||
| def change | ||
| create_table :attendees do |t| | ||
| t.references :room | ||
| t.string :name | ||
| t.timestamps | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| class CreateVotes < ActiveRecord::Migration[7.1] | ||
| def change | ||
| create_table :votes do |t| | ||
| t.references :rooms_venues, null: false, foreign_key: true | ||
| t.references :attendee, null: false, foreign_key: true | ||
| t.timestamps | ||
| end | ||
| end | ||
| end | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| FactoryBot.define do | ||
| factory :attendee do | ||
| name { Faker::Name.name } | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| FactoryBot.define do | ||
| factory :room_venue do | ||
| association :room | ||
| association :venue | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,7 @@ | ||||||||
| FactoryBot.define do | ||||||||
| factory :room do | ||||||||
| invite_code { SecureRandom.hex(10) } | ||||||||
| venue { venue } | ||||||||
|
||||||||
| venue { venue } | |
| association :venue |
Copilot
AI
Apr 10, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assigning 'host_id' with 'attendee' is ambiguous; if host_id is intended to reference an Attendee's id, use an association (e.g., 'association :attendee') or assign the proper value explicitly.
| host_id { attendee } | |
| association :attendee, factory: :attendee, strategy: :build | |
| host_id { attendee.id } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| FactoryBot.define do | ||
| factory :venue do | ||
| name { 'Venue Name' } | ||
| menu_link { 'http://menu.page.com' } | ||
| cost 100 | ||
| rating 5 | ||
| category_id 1 | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| FactoryBot.define do | ||
| factory :vote do | ||
| room_venue | ||
| category_id 1 | ||
| end | ||
| end |
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reference name 'rooms_venues' is plural; Rails conventions suggest using a singular name (e.g., 'room_venue') to properly define the belongs_to association in the Vote model.