67 lines
1.8 KiB
Go
67 lines
1.8 KiB
Go
|
|
package app
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
|
||
|
|
"github.com/geo-platform/tenant-api/internal/shared/auditlog"
|
||
|
|
sharedcache "github.com/geo-platform/tenant-api/internal/shared/cache"
|
||
|
|
"github.com/geo-platform/tenant-api/internal/shared/objectstorage"
|
||
|
|
"github.com/geo-platform/tenant-api/internal/shared/response"
|
||
|
|
"github.com/geo-platform/tenant-api/internal/tenant/repository"
|
||
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
||
|
|
)
|
||
|
|
|
||
|
|
type DesktopContentService struct {
|
||
|
|
articles *ArticleService
|
||
|
|
}
|
||
|
|
|
||
|
|
type DesktopArticleContentView struct {
|
||
|
|
ArticleID int64 `json:"article_id"`
|
||
|
|
Title string `json:"title"`
|
||
|
|
HTMLContent *string `json:"html_content"`
|
||
|
|
MarkdownContent *string `json:"markdown_content"`
|
||
|
|
CoverAssetURL *string `json:"cover_asset_url"`
|
||
|
|
}
|
||
|
|
|
||
|
|
func NewDesktopContentService(
|
||
|
|
pool *pgxpool.Pool,
|
||
|
|
auditLogs *auditlog.AsyncWriter,
|
||
|
|
objectStorage objectstorage.Client,
|
||
|
|
cache sharedcache.Cache,
|
||
|
|
) *DesktopContentService {
|
||
|
|
return &DesktopContentService{
|
||
|
|
articles: NewArticleService(pool, auditLogs, objectStorage).WithCache(cache),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (s *DesktopContentService) Article(
|
||
|
|
ctx context.Context,
|
||
|
|
client *repository.DesktopClient,
|
||
|
|
articleID int64,
|
||
|
|
) (*DesktopArticleContentView, error) {
|
||
|
|
if client == nil {
|
||
|
|
return nil, response.ErrUnauthorized(40108, "desktop_client_missing", "desktop client context is required")
|
||
|
|
}
|
||
|
|
|
||
|
|
detail, found, err := s.articles.loadArticleDetail(ctx, client.TenantID, articleID)
|
||
|
|
if err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
|
if !found || detail == nil {
|
||
|
|
return nil, response.ErrNotFound(40411, "article_not_found", "article not found")
|
||
|
|
}
|
||
|
|
|
||
|
|
title := ""
|
||
|
|
if detail.Title != nil {
|
||
|
|
title = *detail.Title
|
||
|
|
}
|
||
|
|
|
||
|
|
return &DesktopArticleContentView{
|
||
|
|
ArticleID: detail.ID,
|
||
|
|
Title: title,
|
||
|
|
HTMLContent: detail.HTMLContent,
|
||
|
|
MarkdownContent: detail.MarkdownContent,
|
||
|
|
CoverAssetURL: detail.CoverAssetURL,
|
||
|
|
}, nil
|
||
|
|
}
|