Skip to content

Commit

Permalink
Merge branch 'calculators-constructor' into new_calc_specs
Browse files Browse the repository at this point in the history
  • Loading branch information
ktpe committed Nov 27, 2024
2 parents 2eedb17 + 9130d91 commit 0d8eb31
Show file tree
Hide file tree
Showing 52 changed files with 244 additions and 998 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ jobs:
bundler-cache: true

- name: Install system dependencies
run: sudo apt-get install -y libvips42 libvips-dev imagemagick
run: |
sudo apt-get update
sudo apt-get install -y libvips42 libvips-dev imagemagick
- uses: actions/setup-node@v1
with:
Expand Down
9 changes: 0 additions & 9 deletions app/controllers/api/v2/calculators_controller.rb

This file was deleted.

23 changes: 0 additions & 23 deletions app/lib/calculation_resolver.rb

This file was deleted.

62 changes: 0 additions & 62 deletions app/lib/calculator_resolver.rb

This file was deleted.

29 changes: 0 additions & 29 deletions app/models/calculation.rb

This file was deleted.

8 changes: 4 additions & 4 deletions app/models/calculator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
# Table name: calculators
#
# id :bigint not null, primary key
# en_name :string not null
# en_name :string default(""), not null
# slug :string
# uk_name :string not null
# uk_name :string default(""), not null
# created_at :datetime not null
# updated_at :datetime not null
#
Expand All @@ -27,8 +27,8 @@ class Calculator < ApplicationRecord
has_many :fields, dependent: :destroy
has_many :formulas, dependent: :destroy

accepts_nested_attributes_for :fields, reject_if: :all_blank, allow_destroy: true
accepts_nested_attributes_for :formulas, reject_if: :all_blank, allow_destroy: true
accepts_nested_attributes_for :fields, allow_destroy: true
accepts_nested_attributes_for :formulas, allow_destroy: true

scope :ordered_by_name, -> { order(:en_name) }

Expand Down
25 changes: 20 additions & 5 deletions app/models/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,39 @@
# Table name: categories
#
# id :bigint not null, primary key
# name :string
# en_name :string
# preferable :boolean default(FALSE), not null
# price :decimal(10, 2) default(0.0), not null
# priority :integer default(0), not null
# uk_name :string
# created_at :datetime not null
# updated_at :datetime not null
# preferable :boolean default: false
# field_id :bigint not null
#
# Indexes
#
# index_categories_on_field_id (field_id)
#
# Foreign Keys
#
# fk_rails_... (field_id => fields.id)
#
class Category < ApplicationRecord
include Translatable
translates :name

belongs_to :field
PRIORITY_RANGE = 0..10

translates :name
belongs_to :field, optional: true
has_many :diapers_periods, dependent: :destroy
has_many :category_categoryables, dependent: :restrict_with_exception

enum :preferable, { not_preferable: false, preferable: true }

validates :uk_name, :en_name, presence: true
validates :uk_name, :en_name,
length: { minimum: 3, maximum: 30 },
format: { with: /\A[\p{L}0-9\s'-]+\z/i },
uniqueness: { case_sensitive: false },
allow_blank: true
validates :priority, numericality: { greater_than_or_equal_to: 0 }

Expand Down
25 changes: 17 additions & 8 deletions app/models/diapers_period.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,23 @@
#
# Table name: diapers_periods
#
# category_id :bigint null: false
# price :decimal precision: 8, scale: 2
# period_start :integer null: false
# period_end :integer null: false
# usage_amount :integer null: false
# created_at :datetime null: false
# updated_at :datetime null: false
# index ["category_id"], name: "index_diapers_periods_on_category_id"
# id :bigint not null, primary key
# period_end :integer not null
# period_start :integer not null
# price :decimal(8, 2) not null
# usage_amount :integer not null
# created_at :datetime not null
# updated_at :datetime not null
# category_id :bigint not null
#
# Indexes
#
# index_diapers_periods_on_category_id (category_id)
#
# Foreign Keys
#
# fk_rails_... (category_id => categories.id)
#

class DiapersPeriod < ApplicationRecord
belongs_to :category
Expand Down
18 changes: 8 additions & 10 deletions app/models/field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,22 @@
# Table name: fields
#
# id :bigint not null, primary key
# from :integer
# kind :integer not null
# label :string
# name :string
# selector :string not null
# to :integer
# type :string not null
# en_label :string default(""), not null
# kind :string not null
# uk_label :string default(""), not null
# unit :integer default("day")
# uuid :uuid not null
# value :string
# var_name :string default(""), not null
# created_at :datetime not null
# updated_at :datetime not null
# calculator_id :bigint not null
#
# Indexes
#
# index_fields_on_calculator_id (calculator_id)
# index_fields_on_uuid (uuid) UNIQUE
#
# Foreign Keys
#
# fk_rails_... (calculator_id => calculators.id)
#
class Field < ApplicationRecord
include Translatable
Expand Down
23 changes: 23 additions & 0 deletions app/models/formula.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
# == Schema Information
#
# Table name: formulas
#
# id :bigint not null, primary key
# en_label :string default(""), not null
# en_unit :string
# expression :string default(""), not null
# priority :integer default(0), not null
# uk_label :string default(""), not null
# uk_unit :string
# created_at :datetime not null
# updated_at :datetime not null
# calculator_id :bigint not null
#
# Indexes
#
# index_formulas_on_calculator_id (calculator_id)
#
# Foreign Keys
#
# fk_rails_... (calculator_id => calculators.id)
#
class Formula < ApplicationRecord
belongs_to :calculator

Expand Down
30 changes: 0 additions & 30 deletions app/models/named_value.rb

This file was deleted.

6 changes: 3 additions & 3 deletions app/models/price.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
#
# Indexes
#
# index_prices_on_category_id (category_id)
# index_prices_on_category_id_and_priceable_id_and_priceable_type (category_id,priceable_id,priceable_type) UNIQUE
# index_prices_on_priceable (priceable_type,priceable_id)
# idx_on_category_id_priceable_id_priceable_type_1fa9ce7f24 (category_id,priceable_id,priceable_type) UNIQUE
# index_prices_on_category_id (category_id)
# index_prices_on_priceable (priceable_type,priceable_id)
#
class Price < ApplicationRecord
belongs_to :priceable, polymorphic: true
Expand Down
1 change: 1 addition & 0 deletions app/models/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# Indexes
#
# index_products_on_product_type_id (product_type_id)
# index_products_on_title (title) UNIQUE
# index_products_on_uuid (uuid) UNIQUE
#
class Product < ApplicationRecord
Expand Down
30 changes: 0 additions & 30 deletions app/models/range_field.rb

This file was deleted.

Loading

0 comments on commit 0d8eb31

Please sign in to comment.