このコミットが含まれているのは:
2026-03-04 01:33:33 +09:00
コミット a74696fc43
9個のファイルの変更121行の追加2行の削除
+17
ファイルの表示
@@ -0,0 +1,17 @@
class DeerjikistsController < ApplicationController
def show
platform = params[:platform].to_s.strip
code = params[:code].to_s.strip
return head :bad_request if platform.blank? || code.blank?
deerjikist = Deerjikist
.joins(:tag)
.includes(:tag, tag: :tag_name)
.find_by(platform:, code:)
if deerjikist
render json: DeerjikistRepr.base(deerjikist)
else
head :not_found
end
end
end
+21
ファイルの表示
@@ -86,6 +86,27 @@ class TagsController < ApplicationController
end
end
def deerjikists
tag = Tag.joins(:tag_name)
.includes(:tag_name, tag_name: :wiki_page)
.find_by(id: params[:id])
return head :bad_request unless tag
render json: DeerjikistRepr.many(tag.deerjikists)
end
def deerjikists_by_name
name = params[:name].to_s.strip
return head :bad_request if name.blank?
tag = Tag.joins(:tag_name)
.includes(:tag_name, tag_name: :wiki_page)
.find_by(tag_names: { name: })
return head :not_found unless tag
render json: DeerjikistRepr.many(tag.deerjikists)
end
def update
return head :unauthorized unless current_user
return head :forbidden unless current_user.member?
+21
ファイルの表示
@@ -0,0 +1,21 @@
class Deerjikist < ApplicationRecord
self.primary_key = :platform, :code
belongs_to :tag
validates :platform, presence: true
validates :code, presence: true
validates :tag_id, presence: true
validate :tag_must_be_deerjikist
enum :platform, nico: 'nico', youtube: 'youtube'
private
def tag_must_be_deerjikist
if tag && !(tag.deerjikist?)
errors.add :tag, 'タグはニジラー・カテゴリである必要があります.'
end
end
end
+9
ファイルの表示
@@ -24,6 +24,8 @@ class Tag < ApplicationRecord
has_many :tag_similarities, dependent: :delete_all
has_many :deerjikists, dependent: :delete_all
belongs_to :tag_name
delegate :wiki_page, to: :tag_name
@@ -42,6 +44,7 @@ class Tag < ApplicationRecord
validate :nico_tag_name_must_start_with_nico
validate :tag_name_must_be_canonical
validate :category_must_be_deerjikist_with_deerjikists
scope :nico_tags, -> { where(category: :nico) }
@@ -149,4 +152,10 @@ class Tag < ApplicationRecord
errors.add :tag_name, 'tag_names へは実体を示す必要があります.'
end
end
def category_must_be_deerjikist_with_deerjikists
if !(deerjikist?) && deerjikists.exists?
errors.add :category, 'ニジラーと紐づいてゐるタグはニジラー・カテゴリである必要があります.'
end
end
end
+16
ファイルの表示
@@ -0,0 +1,16 @@
# frozen_string_literal: true
module DeerjikistRepr
BASE = { only: [:platform, :code], include: { tag: TagRepr::BASE } }.freeze
module_function
def base deerjikist
deerjikist.as_json(BASE)
end
def many deerjikists
deerjikists.map { |d| base(d) }
end
end