feat(help-center): expose public portal show
This commit is contained in:
@@ -65,6 +65,9 @@ func (h *ArticleHandler) PublicList(c *gin.Context) {
|
||||
response.AbortWithStatusError(c, http.StatusInternalServerError, response.ErrInternal, "failed to list articles")
|
||||
return
|
||||
}
|
||||
for i := range articles {
|
||||
articles[i].Portal = *portal
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"payload": publicArticlePayloads(articles, portal.Slug),
|
||||
@@ -747,14 +750,38 @@ func publicPortalPayload(portal *model.Portal) gin.H {
|
||||
if portal == nil {
|
||||
return gin.H{}
|
||||
}
|
||||
return gin.H{
|
||||
categories := make([]gin.H, 0, len(portal.Categories))
|
||||
for i := range portal.Categories {
|
||||
categories = append(categories, publicCategoryPayload(&portal.Categories[i]))
|
||||
}
|
||||
payload := gin.H{
|
||||
"custom_domain": portal.CustomDomain,
|
||||
"header_text": portal.HeaderText,
|
||||
"homepage_link": portal.HomepageLink,
|
||||
"name": portal.Name,
|
||||
"page_title": portal.PageTitle,
|
||||
"slug": portal.Slug,
|
||||
"categories": categories,
|
||||
"meta": gin.H{
|
||||
"articles_count": publicPortalPublishedArticleCount(portal.Articles),
|
||||
"categories_count": len(portal.Categories),
|
||||
"default_locale": portalDefaultLocale(portal),
|
||||
},
|
||||
}
|
||||
if portal.LogoURL != "" {
|
||||
payload["logo"] = gin.H{"file_url": portal.LogoURL, "portal_id": portal.ID, "account_id": portal.AccountID}
|
||||
}
|
||||
return payload
|
||||
}
|
||||
|
||||
func publicPortalPublishedArticleCount(articles []model.Article) int {
|
||||
count := 0
|
||||
for _, article := range articles {
|
||||
if article.Status == string(model.ArticleStatusPublished) {
|
||||
count++
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
func publicAuthorPayload(user *model.User) gin.H {
|
||||
|
||||
Reference in New Issue
Block a user