This commit is contained in:
2026-03-27 01:01:47 +09:00
parent e8be071064
commit e40f7a3620
4 changed files with 212 additions and 23 deletions
@@ -7,7 +7,7 @@ class WikiAssetsController < ApplicationController
page = WikiPage.find_by(id: page_id)
return head :not_found unless page
render json: page.assets
render json: WikiAssetRepr.many(page.assets)
end
def create
@@ -34,6 +34,6 @@ class WikiAssetsController < ApplicationController
page.update!(next_asset_no: no + 1)
end
render json: asset.as_json(only: [:wiki_page_id, :no], methods: [:url])
render json: WikiAssetRepr.base(asset)
end
end
@@ -0,0 +1,16 @@
# frozen_string_literal: true
module WikiAssetRepr
BASE = { only: [:wiki_page_id, :no], methods: [:url] }.freeze
module_function
def base wiki_asset
wiki_asset.as_json(BASE)
end
def many wiki_assets
wiki_assets.map { |a| base(a) }
end
end