Skip to content

Commit

Permalink
Merge pull request #15 from TelosLabs/improvements-modeling
Browse files Browse the repository at this point in the history
Improvements | Modeling
  • Loading branch information
LuigiR0jas authored Jul 8, 2024
2 parents f626c6c + 1e78ce7 commit f31cca5
Show file tree
Hide file tree
Showing 39 changed files with 747 additions and 84 deletions.
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ gem "action_policy", "~> 0.7.0"
gem "bootsnap", require: false
gem "puma", ">= 5.0"
gem "tzinfo-data", platforms: %i[windows jruby]
gem "validates_timeliness", "~> 7.0.0.beta1"

group :development, :test do
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
Expand All @@ -39,6 +40,7 @@ group :development, :test do
gem "debug", platforms: %i[mri windows]
gem "dotenv"
gem "erb_lint", require: false
gem "factory_bot_rails"
gem "letter_opener"
gem "pry-byebug"
gem "rspec-rails"
Expand All @@ -52,6 +54,8 @@ group :development, :test do
end

group :development do
gem "annotate"
gem "faker"
gem "rack-mini-profiler"
gem "web-console"
end
Expand Down
18 changes: 18 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ GEM
tzinfo (~> 2.0)
addressable (2.8.7)
public_suffix (>= 2.0.2, < 7.0)
annotate (3.2.0)
activerecord (>= 3.2, < 8.0)
rake (>= 10.4, < 14.0)
ast (2.4.2)
axiom-types (0.1.1)
descendants_tracker (~> 0.0.4)
Expand Down Expand Up @@ -183,6 +186,13 @@ GEM
erubi (1.13.0)
et-orbi (1.2.11)
tzinfo
factory_bot (6.4.6)
activesupport (>= 5.0.0)
factory_bot_rails (6.4.3)
factory_bot (~> 6.4)
railties (>= 5.0.0)
faker (3.4.1)
i18n (>= 1.8.11, < 2)
ferrum (0.15)
addressable (~> 2.5)
concurrent-ruby (~> 1.1)
Expand Down Expand Up @@ -443,6 +453,7 @@ GEM
railties (>= 7.0.0)
thor (1.3.1)
thread_safe (0.3.6)
timeliness (0.4.5)
timeout (0.4.1)
tty-which (0.5.0)
turbo-rails (2.0.5)
Expand All @@ -452,6 +463,9 @@ GEM
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
validates_timeliness (7.0.0.beta2)
activemodel (>= 7.0.0, < 8)
timeliness (>= 0.3.10, < 1)
virtus (2.0.0)
axiom-types (~> 0.1)
coercible (~> 1.0)
Expand All @@ -477,6 +491,7 @@ PLATFORMS
DEPENDENCIES
action_policy (~> 0.7.0)
activerecord-enhancedsqlite3-adapter (~> 0.8.0)
annotate
better_errors
binding_of_caller
bootsnap
Expand All @@ -488,6 +503,8 @@ DEPENDENCIES
debug
dotenv
erb_lint
factory_bot_rails
faker
fuubar
importmap-rails
letter_opener
Expand All @@ -513,6 +530,7 @@ DEPENDENCIES
tailwindcss-rails (~> 2.6)
turbo-rails
tzinfo-data
validates_timeliness (~> 7.0.0.beta1)
web-console

RUBY VERSION
Expand Down
13 changes: 12 additions & 1 deletion app/models/conference.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
# == Schema Information
#
# Table name: conferences
#
# id :integer not null, primary key
# name :string not null
# created_at :datetime not null
# updated_at :datetime not null
#
class Conference < ApplicationRecord
has_many :events, dependent: :destroy
has_many :locations, dependent: :destroy
has_many :events, dependent: :destroy

validates :name, presence: true
end
33 changes: 28 additions & 5 deletions app/models/event.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
# == Schema Information
#
# Table name: events
#
# id :integer not null, primary key
# description :string
# ends_at :datetime not null
# starts_at :datetime not null
# title :string not null
# created_at :datetime not null
# updated_at :datetime not null
# conference_id :integer not null
# location_id :integer not null
#
# Indexes
#
# index_events_on_conference_id (conference_id)
# index_events_on_location_id (location_id)
#
class Event < ApplicationRecord
belongs_to :location
belongs_to :conference

has_many :event_tags, dependent: :destroy
has_many :saved_events, dependent: :destroy
has_many :speakers, dependent: :destroy
has_many :tags, through: :event_tags
has_many :users, through: :saved_events
has_and_belongs_to_many :speakers
has_and_belongs_to_many :users # attendees
has_and_belongs_to_many :tags

validates :title, presence: true
validates :starts_at, presence: true
validates :ends_at, presence: true

validates_datetime :ends_at, after: :starts_at
end
4 changes: 0 additions & 4 deletions app/models/event_tag.rb

This file was deleted.

17 changes: 17 additions & 0 deletions app/models/location.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# == Schema Information
#
# Table name: locations
#
# id :integer not null, primary key
# name :string not null
# created_at :datetime not null
# updated_at :datetime not null
# conference_id :integer not null
#
# Indexes
#
# index_locations_on_conference_id (conference_id)
# index_locations_on_name_and_conference_id (name,conference_id) UNIQUE
#
class Location < ApplicationRecord
belongs_to :conference

has_many :events, dependent: :destroy

validates :name, presence: true, uniqueness: {scope: :conference_id}
end
21 changes: 21 additions & 0 deletions app/models/profile.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
# == Schema Information
#
# Table name: profiles
#
# id :integer not null, primary key
# bio :string
# github_url :string
# is_public :boolean default(FALSE), not null
# linkedin_url :string
# location :string
# name :string
# profileable_type :string not null
# twitter_url :string
# created_at :datetime not null
# updated_at :datetime not null
# profileable_id :integer not null
#
# Indexes
#
# index_profiles_on_profileable (profileable_type,profileable_id)
#
class Profile < ApplicationRecord
belongs_to :profileable, polymorphic: true

Expand Down
4 changes: 0 additions & 4 deletions app/models/saved_event.rb

This file was deleted.

14 changes: 12 additions & 2 deletions app/models/speaker.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# == Schema Information
#
# Table name: speakers
#
# id :integer not null, primary key
# created_at :datetime not null
# updated_at :datetime not null
#
class Speaker < ApplicationRecord
belongs_to :event

has_one :profile, as: :profileable, dependent: :destroy

has_and_belongs_to_many :events

accepts_nested_attributes_for :profile
end
18 changes: 16 additions & 2 deletions app/models/tag.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
# == Schema Information
#
# Table name: tags
#
# id :integer not null, primary key
# name :string not null
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_tags_on_name (name) UNIQUE
#
class Tag < ApplicationRecord
has_many :event_tags, dependent: :destroy
has_many :events, through: :event_tags
has_and_belongs_to_many :events

validates :name, presence: true, uniqueness: true
end
23 changes: 21 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
# == Schema Information
#
# Table name: users
#
# id :integer not null, primary key
# email :string not null
# in_app_notifications_enabled :boolean default(TRUE), not null
# mail_notifications_enabled :boolean default(TRUE), not null
# role :string
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_users_on_email (email) UNIQUE
#
class User < ApplicationRecord
normalizes :email, with: ->(email) { email.strip.downcase }

has_one :profile, as: :profileable, dependent: :destroy

has_many :saved_events, dependent: :destroy
has_many :events, through: :saved_events
has_and_belongs_to_many :events

validates :email, presence: true, uniqueness: true
end
40 changes: 40 additions & 0 deletions config/initializers/validates_timeliness.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
ValidatesTimeliness.setup do |config|
# Extend ORM/ODMs for full support (:active_record included).
config.extend_orms = [:active_record]
#
# Default timezone
# config.default_timezone = :utc
#
# Set the dummy date part for a time type values.
# config.dummy_date_for_time_type = [ 2000, 1, 1 ]
#
# Ignore errors when restriction options are evaluated
# config.ignore_restriction_errors = false
#
# Re-display invalid values in date/time selects
# config.enable_date_time_select_extension!
#
# Handle multiparameter date/time values strictly
# config.enable_multiparameter_extension!
#
# Shorthand date and time symbols for restrictions
# config.restriction_shorthand_symbols.update(
# :now => lambda { Time.current },
# :today => lambda { Date.current }
# )
#
# Use the plugin date/time parser which is stricter and extendable
# config.use_plugin_parser = false
#
# Add one or more formats making them valid. e.g. add_formats(:date, 'd(st|rd|th) of mmm, yyyy')
# config.parser.add_formats()
#
# Remove one or more formats making them invalid. e.g. remove_formats(:date, 'dd/mm/yyy')
# config.parser.remove_formats()
#
# Change the ambiguous year threshold when parsing a 2 digit year
# config.parser.ambiguous_year_threshold = 30
#
# Treat ambiguous dates, such as 01/02/1950, as a Non-US date.
# config.parser.remove_us_formats
end
16 changes: 16 additions & 0 deletions config/locales/validates_timeliness.en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
en:
errors:
messages:
invalid_date: "is not a valid date"
invalid_time: "is not a valid time"
invalid_datetime: "is not a valid datetime"
is_at: "must be at %{restriction}"
before: "must be before %{restriction}"
on_or_before: "must be on or before %{restriction}"
after: "must be after %{restriction}"
on_or_after: "must be on or after %{restriction}"
validates_timeliness:
error_value_formats:
date: '%Y-%m-%d'
time: '%H:%M:%S'
datetime: '%Y-%m-%d %H:%M:%S'
2 changes: 1 addition & 1 deletion db/migrate/20240628201158_create_conferences.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class CreateConferences < ActiveRecord::Migration[7.1]
def change
create_table :conferences do |t|
t.string :name
t.string :name, null: false

t.timestamps
end
Expand Down
4 changes: 3 additions & 1 deletion db/migrate/20240628201344_create_locations.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
class CreateLocations < ActiveRecord::Migration[7.1]
def change
create_table :locations do |t|
t.string :name
t.string :name, null: false
t.references :conference, null: false, foreign_key: true

t.timestamps

t.index %i[name conference_id], unique: true
end
end
end
4 changes: 3 additions & 1 deletion db/migrate/20240628201414_create_tags.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
class CreateTags < ActiveRecord::Migration[7.1]
def change
create_table :tags do |t|
t.string :name
t.string :name, null: false

t.timestamps

t.index :name, unique: true
end
end
end
8 changes: 4 additions & 4 deletions db/migrate/20240628204535_create_events.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
class CreateEvents < ActiveRecord::Migration[7.1]
def change
create_table :events do |t|
t.string :title, null: false
t.string :description
t.datetime :starts_at, null: false
t.datetime :ends_at, null: false
t.references :location, null: false, foreign_key: true
t.references :conference, null: false, foreign_key: true
t.string :title
t.string :description
t.datetime :start_datetime
t.datetime :end_datetime

t.timestamps
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
class CreateEventTags < ActiveRecord::Migration[7.1]
class CreateEventsTags < ActiveRecord::Migration[7.1]
def change
create_table :event_tags do |t|
create_table :events_tags do |t|
t.references :event, null: false, foreign_key: true
t.references :tag, null: false, foreign_key: true

t.timestamps

t.index %i[event_id tag_id], unique: true
end
end
end
Loading

0 comments on commit f31cca5

Please sign in to comment.