This commit is contained in:
@@ -46,7 +46,7 @@ class WikiPagesController < ApplicationController
|
||||
|
||||
def diff
|
||||
id = params[:id]
|
||||
return head :bad_request if id.blank?
|
||||
return render_bad_request('id は必須です.', field: :id) if id.blank?
|
||||
|
||||
from = params[:from].presence
|
||||
to = params[:to].presence
|
||||
@@ -56,7 +56,7 @@ class WikiPagesController < ApplicationController
|
||||
from_rev = from && page.wiki_revisions.find(from)
|
||||
to_rev = to ? page.wiki_revisions.find(to) : page.current_revision
|
||||
if ((from_rev && !(from_rev.content?)) || !(to_rev&.content?))
|
||||
return head :unprocessable_entity
|
||||
return render_unprocessable_entity('差分を表示できない版です.')
|
||||
end
|
||||
|
||||
diffs = Diff::LCS.sdiff(from_rev&.body&.lines || [], to_rev.body.lines)
|
||||
@@ -89,7 +89,8 @@ class WikiPagesController < ApplicationController
|
||||
body = params[:body].to_s
|
||||
message = params[:message].presence
|
||||
|
||||
return head :unprocessable_entity if title.blank? || body.blank?
|
||||
return render_unprocessable_entity('タイトルは必須です.', field: :title) if title.blank?
|
||||
return render_unprocessable_entity('本文は必須です.', field: :body) if body.blank?
|
||||
|
||||
tag_name = TagName.find_undiscard_or_create_by!(name: title)
|
||||
|
||||
@@ -101,8 +102,10 @@ class WikiPagesController < ApplicationController
|
||||
message:)
|
||||
|
||||
render json: WikiPageRepr.base(page), status: :created
|
||||
rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotUnique
|
||||
head :unprocessable_entity
|
||||
rescue ActiveRecord::RecordInvalid => e
|
||||
render_model_errors(e.record)
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
render_record_not_unique
|
||||
end
|
||||
|
||||
def update
|
||||
@@ -112,7 +115,8 @@ class WikiPagesController < ApplicationController
|
||||
title = params[:title]&.strip
|
||||
body = params[:body].to_s
|
||||
|
||||
return head :unprocessable_entity if title.blank? || body.blank?
|
||||
return render_unprocessable_entity('タイトルは必須です.', field: :title) if title.blank?
|
||||
return render_unprocessable_entity('本文は必須です.', field: :body) if body.blank?
|
||||
|
||||
page = WikiPage.find(params[:id])
|
||||
base_revision_id = params[:base_revision_id].presence
|
||||
|
||||
Reference in New Issue
Block a user