Skip to content

Commit 604f6c5

Browse files
authored
Merge PS005 into master
feat: implement vod review module
2 parents c4210d1 + b7d4a57 commit 604f6c5

12 files changed

Lines changed: 1063 additions & 11 deletions

app/controllers/api/v1/vod_reviews_controller.rb

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@ class Api::V1::VodReviewsController < Api::V1::BaseController
22
before_action :set_vod_review, only: [:show, :update, :destroy]
33

44
def index
5-
vod_reviews = organization_scoped(VodReview).includes(:match, :reviewed_by)
5+
authorize VodReview
6+
vod_reviews = organization_scoped(VodReview).includes(:match, :reviewer)
67

78
# Apply filters
89
vod_reviews = vod_reviews.where(status: params[:status]) if params[:status].present?
9-
vod_reviews = vod_reviews.where(vod_platform: params[:platform]) if params[:platform].present?
1010

1111
# Match filter
1212
vod_reviews = vod_reviews.where(match_id: params[:match_id]) if params[:match_id].present?
1313

1414
# Reviewed by filter
15-
vod_reviews = vod_reviews.where(reviewed_by_id: params[:reviewed_by_id]) if params[:reviewed_by_id].present?
15+
vod_reviews = vod_reviews.where(reviewer_id: params[:reviewer_id]) if params[:reviewer_id].present?
1616

1717
# Search by title
1818
if params[:search].present?
@@ -35,6 +35,7 @@ def index
3535
end
3636

3737
def show
38+
authorize @vod_review
3839
vod_review_data = VodReviewSerializer.render_as_hash(@vod_review)
3940
timestamps = VodTimestampSerializer.render_as_hash(
4041
@vod_review.vod_timestamps.includes(:target_player, :created_by).order(:timestamp_seconds)
@@ -47,9 +48,10 @@ def show
4748
end
4849

4950
def create
51+
authorize VodReview
5052
vod_review = organization_scoped(VodReview).new(vod_review_params)
5153
vod_review.organization = current_organization
52-
vod_review.reviewed_by = current_user
54+
vod_review.reviewer = current_user
5355

5456
if vod_review.save
5557
log_user_action(
@@ -73,6 +75,7 @@ def create
7375
end
7476

7577
def update
78+
authorize @vod_review
7679
old_values = @vod_review.attributes.dup
7780

7881
if @vod_review.update(vod_review_params)
@@ -98,6 +101,7 @@ def update
98101
end
99102

100103
def destroy
104+
authorize @vod_review
101105
if @vod_review.destroy
102106
log_user_action(
103107
action: 'delete',
@@ -124,8 +128,10 @@ def set_vod_review
124128

125129
def vod_review_params
126130
params.require(:vod_review).permit(
127-
:title, :vod_url, :vod_platform, :game_start_timestamp,
128-
:status, :notes, :match_id
131+
:title, :description, :review_type, :review_date,
132+
:video_url, :thumbnail_url, :duration,
133+
:status, :is_public, :match_id,
134+
tags: [], shared_with_players: []
129135
)
130136
end
131137
end

app/controllers/api/v1/vod_timestamps_controller.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ class Api::V1::VodTimestampsController < Api::V1::BaseController
33
before_action :set_vod_timestamp, only: [:update, :destroy]
44

55
def index
6+
authorize @vod_review, :show?
67
timestamps = @vod_review.vod_timestamps
78
.includes(:target_player, :created_by)
89
.order(:timestamp_seconds)
@@ -18,6 +19,7 @@ def index
1819
end
1920

2021
def create
22+
authorize @vod_review, :update?
2123
timestamp = @vod_review.vod_timestamps.new(vod_timestamp_params)
2224
timestamp.created_by = current_user
2325

@@ -43,6 +45,7 @@ def create
4345
end
4446

4547
def update
48+
authorize @timestamp.vod_review, :update?
4649
old_values = @timestamp.attributes.dup
4750

4851
if @timestamp.update(vod_timestamp_params)
@@ -68,6 +71,7 @@ def update
6871
end
6972

7073
def destroy
74+
authorize @timestamp.vod_review, :update?
7175
if @timestamp.destroy
7276
log_user_action(
7377
action: 'delete',
@@ -101,7 +105,7 @@ def set_vod_timestamp
101105
def vod_timestamp_params
102106
params.require(:vod_timestamp).permit(
103107
:timestamp_seconds, :category, :importance,
104-
:title, :description, :target_player_id
108+
:title, :description, :target_type, :target_player_id
105109
)
106110
end
107111
end
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
class VodReviewSerializer < Blueprinter::Base
22
identifier :id
33

4-
fields :title, :vod_url, :vod_platform, :game_start_timestamp,
5-
:status, :notes, :created_at, :updated_at
4+
fields :title, :description, :review_type, :review_date,
5+
:video_url, :thumbnail_url, :duration,
6+
:is_public, :share_link, :shared_with_players,
7+
:status, :tags, :metadata,
8+
:created_at, :updated_at
69

710
field :timestamps_count do |vod_review, options|
811
options[:include_timestamps_count] ? vod_review.vod_timestamps.count : nil
912
end
1013

1114
association :organization, blueprint: OrganizationSerializer
1215
association :match, blueprint: MatchSerializer
13-
association :reviewed_by, blueprint: UserSerializer
16+
association :reviewer, blueprint: UserSerializer
1417
end

spec/factories/vod_reviews.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
FactoryBot.define do
2+
factory :vod_review do
3+
association :organization
4+
association :reviewer, factory: :user
5+
association :match, factory: :match
6+
7+
title { Faker::Lorem.sentence(word_count: 3) }
8+
description { Faker::Lorem.paragraph }
9+
review_type { %w[team individual opponent].sample }
10+
review_date { Faker::Time.between(from: 30.days.ago, to: Time.current) }
11+
video_url { "https://www.youtube.com/watch?v=#{Faker::Alphanumeric.alpha(number: 11)}" }
12+
thumbnail_url { Faker::Internet.url }
13+
duration { rand(1800..3600) }
14+
status { 'draft' }
15+
is_public { false }
16+
tags { %w[scrim review analysis].sample(2) }
17+
18+
trait :published do
19+
status { 'published' }
20+
end
21+
22+
trait :archived do
23+
status { 'archived' }
24+
end
25+
26+
trait :public do
27+
is_public { true }
28+
share_link { SecureRandom.urlsafe_base64(16) }
29+
end
30+
31+
trait :with_timestamps do
32+
after(:create) do |vod_review|
33+
create_list(:vod_timestamp, 3, vod_review: vod_review)
34+
end
35+
end
36+
end
37+
end

spec/factories/vod_timestamps.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
FactoryBot.define do
2+
factory :vod_timestamp do
3+
association :vod_review
4+
association :target_player, factory: :player
5+
association :created_by, factory: :user
6+
7+
timestamp_seconds { rand(60..3600) }
8+
title { Faker::Lorem.sentence(word_count: 3) }
9+
description { Faker::Lorem.paragraph }
10+
category { %w[mistake good_play team_fight objective laning].sample }
11+
importance { %w[low normal high critical].sample }
12+
target_type { %w[player team opponent].sample }
13+
14+
trait :mistake do
15+
category { 'mistake' }
16+
importance { %w[high critical].sample }
17+
end
18+
19+
trait :good_play do
20+
category { 'good_play' }
21+
end
22+
23+
trait :critical do
24+
importance { 'critical' }
25+
end
26+
27+
trait :important do
28+
importance { 'high' }
29+
end
30+
end
31+
end

0 commit comments

Comments
 (0)