Skip to content

Commit 8ba4dec

Browse files
authored
Reviews Endpoint Initial Scaffold (#296)
1 parent ced9841 commit 8ba4dec

25 files changed

+420
-1
lines changed

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ gem 'opentelemetry-sdk'
6969
gem 'opentelemetry-exporter-otlp'
7070
gem 'opentelemetry-instrumentation-all'
7171

72+
# for review imports from NRDBc
73+
gem 'reverse_markdown'
74+
7275
group :development, :test do
7376
gem "brakeman", "~> 5.2"
7477
gem "bundler-audit", "~> 0.9.0"

Gemfile.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,8 @@ GEM
450450
responders (3.1.1)
451451
actionpack (>= 5.2)
452452
railties (>= 5.2)
453+
reverse_markdown (2.1.1)
454+
nokogiri
453455
rexml (3.3.2)
454456
strscan
455457
rspec (3.12.0)
@@ -572,6 +574,7 @@ DEPENDENCIES
572574
rack-cors (= 2.0.0)
573575
rails (>= 7.0.7.1)
574576
responders
577+
reverse_markdown
575578
rspec-rails
576579
rspec_api_documentation
577580
rubocop

app/controllers/reviews_controller.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# frozen_string_literal: true
2+
3+
# Controller for the Review resource.
4+
class ReviewsController < ApplicationController
5+
def index
6+
reviews = ReviewResource.all(params)
7+
respond_with(reviews)
8+
end
9+
10+
def show
11+
reviews = ReviewResource.find(params)
12+
respond_with(reviews)
13+
end
14+
end

app/models/card.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def restrictions
4949
class_name: 'RawPrinting',
5050
primary_key: :id
5151

52+
has_many :reviews
5253
has_many :printings,
5354
primary_key: :id
5455

app/models/review.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Review < ApplicationRecord
2+
belongs_to :card
3+
has_many :review_comments
4+
has_many :review_votes
5+
6+
def votes
7+
review_votes.count
8+
end
9+
10+
def comments
11+
review_comments
12+
end
13+
end

app/models/review_comment.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class ReviewComment < ApplicationRecord
2+
belongs_to :review
3+
end

app/models/review_vote.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class ReviewVote < ApplicationRecord
2+
belongs_to :review
3+
end

app/resources/card_resource.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ class CardResource < ApplicationResource # rubocop:disable Metrics/ClassLength
110110
end
111111
end
112112
has_many :rulings
113+
has_many :reviews
113114
belongs_to :side
114115

115116
many_to_many :decklists do

app/resources/review_resource.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# frozen_string_literal: true
2+
3+
# Resource for the Review object (currently imported from NRDBc)
4+
class ReviewResource < ApplicationResource
5+
primary_endpoint '/reviews', %i[index show]
6+
7+
attribute :id, :integer
8+
attribute :username, :string do
9+
@object.user_id
10+
end
11+
attribute :body, :string
12+
attribute :card, :string do
13+
@object.card.title
14+
end
15+
attribute :card_id, :string
16+
attribute :created_at, :datetime
17+
attribute :updated_at, :datetime
18+
attribute :votes, :integer
19+
20+
belongs_to :card
21+
22+
attribute :comments, :array do
23+
@object.comments.map do |comment|
24+
{
25+
id: comment.id,
26+
body: comment.body,
27+
user: comment.user_id,
28+
created_at: comment.created_at,
29+
updated_at: comment.updated_at
30+
}
31+
end
32+
end
33+
end

config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
resources :illustrators, only: %i[index show]
2020
resources :printings, only: %i[index show]
2121
resources :restrictions, only: %i[index show]
22+
resources :reviews, only: %i[index show]
2223
resources :rulings, only: %i[index show]
2324
resources :sides, only: %i[index show]
2425
resources :snapshots, only: %i[index show]

0 commit comments

Comments
 (0)