feat: Portal and Category public APIs (#4946)
This commit is contained in:
@@ -11,6 +11,7 @@ class Api::V1::Accounts::ArticlesController < Api::V1::Accounts::BaseController
|
||||
def create
|
||||
@article = @portal.articles.create!(article_params)
|
||||
@article.associate_root_article(article_params[:associated_article_id])
|
||||
@article.draft!
|
||||
render json: { error: @article.errors.messages }, status: :unprocessable_entity and return unless @article.valid?
|
||||
end
|
||||
|
||||
@@ -39,7 +40,7 @@ class Api::V1::Accounts::ArticlesController < Api::V1::Accounts::BaseController
|
||||
|
||||
def article_params
|
||||
params.require(:article).permit(
|
||||
:title, :content, :description, :position, :category_id, :author_id, :associated_article_id
|
||||
:title, :content, :description, :position, :category_id, :author_id, :associated_article_id, :status
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
@@ -26,6 +26,11 @@ class Api::V1::Accounts::PortalsController < Api::V1::Accounts::BaseController
|
||||
head :ok
|
||||
end
|
||||
|
||||
def archive
|
||||
@portal.update(archive: true)
|
||||
head :ok
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def fetch_portal
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
class Public::Api::V1::Portals::CategoriesController < PublicController
|
||||
before_action :set_portal
|
||||
before_action :set_category, only: [:show]
|
||||
|
||||
def index
|
||||
@categories = @portal.categories
|
||||
end
|
||||
|
||||
def show; end
|
||||
|
||||
private
|
||||
|
||||
def set_category
|
||||
@category = @portal.categories.find_by!(slug: params[:slug])
|
||||
end
|
||||
|
||||
def set_portal
|
||||
@portal = ::Portal.find_by!(slug: params[:portal_slug], archived: false)
|
||||
end
|
||||
end
|
||||
11
app/controllers/public/api/v1/portals_controller.rb
Normal file
11
app/controllers/public/api/v1/portals_controller.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
class Public::Api::V1::PortalsController < PublicController
|
||||
before_action :set_portal
|
||||
|
||||
def show; end
|
||||
|
||||
private
|
||||
|
||||
def set_portal
|
||||
@portal = ::Portal.find_by!(slug: params[:slug], archived: false)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user