feat: Portal and Category public APIs (#4946)

This commit is contained in:
Tejaswini Chile
2022-07-05 17:15:38 +05:30
committed by GitHub
parent ae59d0a343
commit 029209a634
18 changed files with 154 additions and 9 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View 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