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/models association #17

Merged
merged 25 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4c5e8aa
Update gemfileloc to contain the credential settings
M-Anwar-Hussaini Feb 15, 2024
c71fed9
Add user association to have many reservations
M-Anwar-Hussaini Feb 15, 2024
cce1160
Add city association to have many reservations
M-Anwar-Hussaini Feb 15, 2024
501e9dc
Add car association to have many reservations
M-Anwar-Hussaini Feb 15, 2024
2ea0e84
Add car association to have many car_details
M-Anwar-Hussaini Feb 15, 2024
dfdb1d8
Add engine_type association to have many car_details
M-Anwar-Hussaini Feb 15, 2024
9a4b6af
Set models to be deleted while their independent elements are removed.
M-Anwar-Hussaini Feb 15, 2024
84e1717
Validate city model
M-Anwar-Hussaini Feb 15, 2024
ea96741
Create validation to the car model
M-Anwar-Hussaini Feb 15, 2024
c755b27
Create validation to the reservation model
M-Anwar-Hussaini Feb 15, 2024
2b5beb2
Create validation to the car_detail model
M-Anwar-Hussaini Feb 15, 2024
0f47780
Update .gitignore file to hide the editor settings from being shown i…
M-Anwar-Hussaini Feb 15, 2024
80420a9
Update Gemfile lock
fmanimashaun Feb 15, 2024
2156c9f
Update user model
fmanimashaun Feb 15, 2024
f6426bb
Refactor car model so it has one to one association with car_detail a…
Estete9 Feb 15, 2024
f0c88fb
Refactor car_details model with more validations
Estete9 Feb 15, 2024
d493e31
Refactor engine_details model with more validations
Estete9 Feb 15, 2024
e451ede
Refactor reservation model with more validations
Estete9 Feb 15, 2024
a6cc589
Refactor city model with more validations
Estete9 Feb 15, 2024
0cd52b5
Merge branch 'feature/models-association' of https://github.com/fmani…
Estete9 Feb 15, 2024
ed9028b
Merge branch 'feature/models-association' of https://github.com/fmani…
Estete9 Feb 15, 2024
d037d50
Merge branch 'feature/models-association' of https://github.com/fmani…
Estete9 Feb 15, 2024
01e21a1
Add maximum length to car model\
Estete9 Feb 15, 2024
2359282
Add maximum length to city model
Estete9 Feb 15, 2024
8c316b2
Minor adjustment to model association validation
fmanimashaun Feb 15, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@

# Ignore master key for decrypting credentials and more.
/config/master.key
.idea
19 changes: 5 additions & 14 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions app/models/car.rb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions app/models/car_detail.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions app/models/city.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
class City < ApplicationRecord
has_many :reservations, dependent: :destroy

validates :name, presence: true, length: { minimum: 1, maximum: 255 }
end
3 changes: 3 additions & 0 deletions app/models/engine_type.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
class EngineType < ApplicationRecord
has_many :car_details, dependent: :destroy

validates :name, presence: true, length: { maximum: 255 }
end
7 changes: 7 additions & 0 deletions app/models/reservation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
@@ -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 }

Expand Down
Loading