diff --git a/.gitignore b/.gitignore index 7e6b54f..03a21a9 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,4 @@ # Ignore master key for decrypting credentials and more. /config/master.key +.idea \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index 4ea1d96..91f9caf 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -158,15 +158,7 @@ GEM net-smtp (0.4.0.1) net-protocol nio4r (2.7.0) - nokogiri (1.16.2-aarch64-linux) - racc (~> 1.4) - nokogiri (1.16.2-arm-linux) - racc (~> 1.4) - nokogiri (1.16.2-arm64-darwin) - racc (~> 1.4) - nokogiri (1.16.2-x86-linux) - racc (~> 1.4) - nokogiri (1.16.2-x86_64-darwin) + nokogiri (1.16.2-x64-mingw-ucrt) racc (~> 1.4) nokogiri (1.16.2-x86_64-linux) racc (~> 1.4) @@ -176,6 +168,7 @@ GEM ast (~> 2.4.1) racc pg (1.5.4) + pg (1.5.4-x64-mingw-ucrt) psych (5.1.2) stringio public_suffix (5.0.4) @@ -288,6 +281,8 @@ GEM timeout (0.4.1) tzinfo (2.0.6) concurrent-ruby (~> 1.0) + tzinfo-data (1.2024.1) + tzinfo (>= 1.0.0) unicode-display_width (2.5.0) warden (1.2.9) rack (>= 2.0.9) @@ -303,11 +298,7 @@ GEM zeitwerk (2.6.13) PLATFORMS - aarch64-linux - arm-linux - arm64-darwin - x86-linux - x86_64-darwin + x64-mingw-ucrt x86_64-linux DEPENDENCIES diff --git a/app/models/car.rb b/app/models/car.rb index ce30b91..7db191f 100644 --- a/app/models/car.rb +++ b/app/models/car.rb @@ -1,2 +1,9 @@ class Car < ApplicationRecord + has_many :reservations, dependent: :destroy + has_one :car_detail, dependent: :destroy + + accepts_nested_attributes_for :car_detail + + validates :name, presence: true, length: { minimum: 3, maximum: 255 } + validates :description, presence: true, length: { minimum: 10, maximum: 255 } end diff --git a/app/models/car_detail.rb b/app/models/car_detail.rb index d39d79e..762d54e 100644 --- a/app/models/car_detail.rb +++ b/app/models/car_detail.rb @@ -1,4 +1,9 @@ class CarDetail < ApplicationRecord belongs_to :car belongs_to :engine_type + + validates :horsepower, :torque, numericality: { only_integer: true, greater_than: 0 } + validates :fuel_economy, :seating_capacity, :cargo_space, :infotainment_system, :safety_rating, :tech_features, + :special_features, presence: true + validates :fuel_economy, :cargo_space, length: { maximum: 255 } end diff --git a/app/models/city.rb b/app/models/city.rb index f2188b0..ad609fe 100644 --- a/app/models/city.rb +++ b/app/models/city.rb @@ -1,2 +1,5 @@ class City < ApplicationRecord + has_many :reservations, dependent: :destroy + + validates :name, presence: true, length: { minimum: 1, maximum: 255 } end diff --git a/app/models/engine_type.rb b/app/models/engine_type.rb index 8f0986e..b8a7e2c 100644 --- a/app/models/engine_type.rb +++ b/app/models/engine_type.rb @@ -1,2 +1,5 @@ class EngineType < ApplicationRecord + has_many :car_details, dependent: :destroy + + validates :name, presence: true, length: { maximum: 255 } end diff --git a/app/models/reservation.rb b/app/models/reservation.rb index 206c0c1..3f3548c 100644 --- a/app/models/reservation.rb +++ b/app/models/reservation.rb @@ -2,4 +2,11 @@ class Reservation < ApplicationRecord belongs_to :city belongs_to :car belongs_to :user + + validates :date, presence: true + validate :date_cannot_be_in_the_past + + def date_cannot_be_in_the_past + errors.add(:date, "can't be in the past") if date.present? && date < Date.today + end end diff --git a/app/models/user.rb b/app/models/user.rb index 610c923..6da926b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,10 +1,11 @@ class User < ApplicationRecord + has_many :reservations, dependent: :destroy include Devise::JWT::RevocationStrategies::JTIMatcher devise :database_authenticatable, :registerable, :recoverable, :validatable, :jwt_authenticatable, jwt_revocation_strategy: self - has_many :reservations + has_many :reservations, dependent: :destroy enum role: { user: 0, admin: 1 }