このコミットが含まれているのは:
@@ -0,0 +1,74 @@
|
||||
class TagDescriptionsController < ApplicationController
|
||||
def show
|
||||
description = TagDescription.find_by(tag_id: params[:id], language_code: 'ja')
|
||||
return head :not_found unless description
|
||||
|
||||
render json: representation(description)
|
||||
end
|
||||
|
||||
def show_by_title
|
||||
tag_name = TagName.find_by(language_code: 'ja', name: params[:name].to_s.strip)
|
||||
description = tag_name&.tag && TagDescription.find_by(tag: tag_name.tag, language_code: 'ja')
|
||||
return head :not_found unless description
|
||||
|
||||
render json: representation(description)
|
||||
end
|
||||
|
||||
def create
|
||||
return head :unauthorized unless current_user
|
||||
return head :forbidden unless current_user.gte_member?
|
||||
|
||||
body = params[:body].to_s
|
||||
return render_unprocessable_entity('本文は必須です.', field: :body) if body.blank?
|
||||
|
||||
tag = Tag.find_by(id: params[:id])
|
||||
return head :not_found unless tag
|
||||
|
||||
if TagDescription.exists?(tag:, language_code: 'ja')
|
||||
return render_unprocessable_entity('説明はすでに存在します.')
|
||||
end
|
||||
|
||||
TagDescriptionOperation.create!(tag:, body:, created_by_user: current_user)
|
||||
description = TagDescription.find_by!(tag:, language_code: 'ja')
|
||||
|
||||
render json: representation(description), status: :created
|
||||
rescue ActiveRecord::RecordInvalid => e
|
||||
render_validation_error e.record
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
render_record_not_unique
|
||||
end
|
||||
|
||||
def update
|
||||
return head :unauthorized unless current_user
|
||||
return head :forbidden unless current_user.gte_member?
|
||||
|
||||
body = params[:body].to_s
|
||||
return render_unprocessable_entity('本文は必須です.', field: :body) if body.blank?
|
||||
|
||||
description = TagDescription.find_by(tag_id: params[:id], language_code: 'ja')
|
||||
return head :not_found unless description
|
||||
|
||||
page = WikiPage.find(description.id)
|
||||
TagDescriptionOperation.update!(
|
||||
description:, page:, body:, updated_by_user: current_user)
|
||||
description.reload
|
||||
|
||||
render json: representation(description)
|
||||
rescue ActiveRecord::RecordInvalid => e
|
||||
render_validation_error e.record
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def representation description
|
||||
description.as_json(only: [
|
||||
:tag_id,
|
||||
:language_code,
|
||||
:body,
|
||||
:version_no,
|
||||
:created_by_user_id,
|
||||
:updated_by_user_id,
|
||||
:created_at,
|
||||
:updated_at])
|
||||
end
|
||||
end
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする