ぼざクリ タグ広場 https://hub.nizika.monster
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

40 lines
1.1 KiB

  1. class WikiPagesController < ApplicationController
  2. def show
  3. wiki_page = WikiPage.find(params[:id])
  4. render json: wiki_page.as_json
  5. end
  6. def show_by_title
  7. wiki_page = WikiPage.find_by(title: params[:title])
  8. body = wiki_page&.body
  9. return head :not_found unless body
  10. render plain: body
  11. end
  12. def create
  13. return head :unauthorized unless current_user
  14. return head :forbidden unless ['admin', 'member'].include?(current_user.role)
  15. wiki_page = WikiPage.new(title: params[:title], created_user: current_user, updated_user: current_user)
  16. if wiki_page.save
  17. wiki_page.set_body params[:body], user: current_user
  18. render json: wiki_page, status: :created
  19. else
  20. render json: { errors: wiki_page.errors.full_messages }, status: :unprocessable_entity
  21. end
  22. end
  23. def update
  24. return head :unauthorized unless current_user
  25. wiki_page = WikiPage.find(params[:id])
  26. return head :not_found unless wiki_pages
  27. wiki_page.updated_user = current_user
  28. wiki_page.set_body params[:body], user: current_user
  29. wiki_page.save!
  30. head :ok
  31. end
  32. end