Skip to content
Draft

Tags #49

Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion app/controllers/videos_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def update
authorize! :update, Item
item = Item.find_by!(video_id: params[:id], user: current_user)
authorize! :update, item
attributes = ActiveModelSerializers::Deserialization.jsonapi_parse(params, only: [:state, :progress])
attributes = ActiveModelSerializers::Deserialization.jsonapi_parse(params, only: [:state, :progress, :tags])
if item.update(attributes)
head :no_content
else
Expand Down
1 change: 1 addition & 0 deletions app/models/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# updated_at :datetime not null
# user_id :integer not null
# progress :integer default(0), not null
# tags :text default([]), not null, is an Array
#
# Indexes
#
Expand Down
4 changes: 4 additions & 0 deletions app/serializers/video_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ class VideoSerializer < ActiveModel::Serializer
Item.find_by(video: object, user: scope).progress
end

attribute :tags do
Item.find_by(video: object, user: scope).tags
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could make item a method or instance var at this point

end

belongs_to :channel
end
5 changes: 5 additions & 0 deletions db/migrate/20240323040259_add_tags_to_items.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddTagsToItems < ActiveRecord::Migration[6.1]
def change
add_column :items, :tags, :text, array: true, null: false, default: []
end
end
6 changes: 4 additions & 2 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ CREATE TABLE public.items (
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
user_id integer NOT NULL,
progress integer DEFAULT 0 NOT NULL
progress integer DEFAULT 0 NOT NULL,
tags text[] DEFAULT '{}'::text[] NOT NULL
);


Expand Down Expand Up @@ -457,6 +458,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20220501124525'),
('20220529012334'),
('20220912113632'),
('20240301110411');
('20240301110411'),
('20240323040259');