-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make it possible for ProductVideo to be loaded by Admin
- Loading branch information
1 parent
b0914d4
commit 0c42365
Showing
15 changed files
with
126 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
module V1 | ||
module Admin | ||
class ProductVideosController < V1::AdminController | ||
def index | ||
allow_index | ||
end | ||
|
||
def show | ||
allow_show | ||
end | ||
|
||
def create | ||
allow_create | ||
end | ||
|
||
def update | ||
allow_update | ||
end | ||
|
||
def destroy | ||
allow_destroy | ||
end | ||
|
||
private | ||
|
||
def model_class | ||
ProductVideo | ||
end | ||
|
||
def serializer_class | ||
V1::Admin::ProductVideoSerializer | ||
end | ||
|
||
def creatable_attributes | ||
%i[ | ||
rank | ||
public | ||
] | ||
end | ||
|
||
def creatable_relationships | ||
%i[ | ||
product | ||
video | ||
] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,8 @@ def serializer_class | |
def permitted_includes | ||
%i[ | ||
webinar | ||
products | ||
product_videos | ||
] | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,4 @@ | ||
class ProductVideo < ApplicationRecord | ||
# Relate to a model | ||
# belongs_to :company | ||
# belongs_to :main_group, class_name: 'ProductGroup', foreign_key: 'main_group_id' | ||
# belongs_to :sub_group, class_name: 'ProductGroup', foreign_key: 'sub_group_id' | ||
|
||
# Relate to many of another model | ||
# Requires intermediary model ProductRelatedArticle | ||
# has_many :related_articles_association, class_name: 'ProductRelatedArticle' | ||
# has_many :related_articles, through: :related_articles_association, source: :article | ||
|
||
# Relate to many of same model | ||
# Requires intermediary model ProductRelatedProduct | ||
# has_many :related_products_association, class_name: 'ProductRelatedProduct' | ||
# has_many :related_products, through: :related_products_association, source: :related_product | ||
# has_many :inverse_related_products_association, class_name: 'ProductRelatedProduct', foreign_key: 'related_product_id' | ||
# has_many :inverse_related_products, through: :inverse_related_products_association, source: :product | ||
|
||
# validates :name, presence: true, uniqueness: true | ||
|
||
# If foo `belongs_to :bar`, then the foos table has a bar_id column. | ||
# If foo `has_one :bar`, then the bars table has a foo_id column. | ||
belongs_to :product | ||
belongs_to :video | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
class Video < ApplicationRecord | ||
belongs_to :webinar, optional: true | ||
has_many :product_videos, dependent: :destroy | ||
has_many :products, through: :product_videos, source: :product | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module V1 | ||
module Admin | ||
class ProductVideoSerializer < ApplicationSerializer | ||
attributes :rank, | ||
:public | ||
|
||
belongs_to :product | ||
belongs_to :video | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,11 @@ | ||
module V1 | ||
module Public | ||
class ProductVideoSerializer < ApplicationSerializer | ||
# attributes :slug, | ||
# :name, | ||
# :public | ||
attributes :rank, | ||
:public | ||
|
||
# belongs_to :thing | ||
# belongs_to :main_group, record_type: :product_group, serializer: :product_group | ||
# belongs_to :sub_group, record_type: :product_group, serializer: :product_group | ||
|
||
# has_many :things | ||
# has_many :related_products, record_type: :product, serializer: :related_products | ||
# has_many :related_articles, record_type: :article, serializer: :related_articles | ||
belongs_to :product | ||
belongs_to :video | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
db/migrate/20231229041605_add_rank_public_to_product_video.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class AddRankPublicToProductVideo < ActiveRecord::Migration[6.1] | ||
def change | ||
add_column :product_videos, :rank, :integer | ||
add_column :product_videos, :public, :boolean | ||
|
||
remove_index :product_videos, name: 'index_product_videos_on_product_id' | ||
remove_index :product_videos, name: 'index_product_videos_on_video_id' | ||
|
||
remove_column :product_videos, :created_at | ||
remove_column :product_videos, :updated_at | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class ChangeProductVideoUuids < ActiveRecord::Migration[6.1] | ||
def change | ||
change_column(:product_videos, :product_id, :string) | ||
change_column(:product_videos, :video_id, :string) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters