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

Feature/database migrations #41

Merged
merged 3 commits into from
Oct 26, 2023
Merged
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
2 changes: 1 addition & 1 deletion app/models/accommodation.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Accommodation < ApplicationRecord
belongs_to :details
belongs_to :accomodation_details

validates :name, presence: true, length: { minimum: 3, maximum: 255 }
validates :image_url, presence: true, format: { with: %r{\Ahttps?://\S+\z}, message: 'Invalid URL format' }
Expand Down
2 changes: 0 additions & 2 deletions app/models/accommodation_detail.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
class AccommodationDetail < ApplicationRecord
belongs_to :accommodation

validates :accommodation, presence: true
validates :accommodation_type, presence: true
validates :bedrooms, presence: true, numericality: { only_integer: true, greater_than_or_equal_to: 1 }
Expand Down
11 changes: 11 additions & 0 deletions app/models/reservation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,15 @@ class Reservation < ApplicationRecord
belongs_to :user
belongs_to :accommodation
belongs_to :city

validates_presence_of :user, :accommodation, :schedule_date, :city
validate :schedule_date_in_future

private

def schedule_date_in_future
return unless schedule_date.present? && schedule_date <= Date.today

errors.add(:schedule_date, 'must be in the future')
end
end
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
class CreateAccommodationDetails < ActiveRecord::Migration[7.1]
def change
create_table :accommodation_details do |t|
t.references :accommodation, null: false, foreign_key: true
t.string :acommodation_type
t.integer :bedrooms
t.integer :beds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class CreateAccommodations < ActiveRecord::Migration[7.1]
def change
create_table :accommodations do |t|
t.string :name
t.references :details, null: false, foreign_key: true
t.references :accommodation_details, null: false, foreign_key: true
t.string :image_url

t.timestamps
Expand Down
12 changes: 0 additions & 12 deletions db/migrate/20231026155958_create_reservations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,6 @@ def change
t.references :city, null: false, foreign_key: true

t.timestamps

# Validations
validates_presence_of :user, :accommodation, :schedule_date, :city
validate :schedule_date_in_future

private

def schedule_date_in_future
if schedule_date.present? && schedule_date <= Date.today
errors.add(:schedule_date, "must be in the future")
end
end
end
end
end
72 changes: 72 additions & 0 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading