feat: connect portal content and banner carousel
This commit is contained in:
@@ -53,6 +53,7 @@ type Notice struct {
|
||||
ID int64 `json:"id"`
|
||||
Title string `json:"title"`
|
||||
Content string `json:"content"`
|
||||
BodyHTML string `json:"body_html,omitempty"`
|
||||
SourceType string `json:"source_type"`
|
||||
StartAt string `json:"start_at"`
|
||||
EndAt string `json:"end_at"`
|
||||
@@ -207,13 +208,16 @@ func (s *Service) Notices(ctx context.Context, tenantID, memberID int64, page, p
|
||||
}
|
||||
|
||||
func (s *Service) PopupNotice(ctx context.Context, tenantID, memberID int64) (*Notice, error) {
|
||||
row, err := s.repository.LatestPopupNotice(ctx, tenantID, memberID)
|
||||
if err != nil || row == nil {
|
||||
row, err := s.repository.PublishedContent(ctx, tenantID, "home_popup_content")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Notice{ID: row.ID, Title: row.Title, Content: row.Content,
|
||||
SourceType: noticeSourceName(row.SourceType), StartAt: row.StartAt, EndAt: row.EndAt,
|
||||
CreatedAt: row.CreatedAt}, nil
|
||||
content := strings.TrimSpace(row.BodyText)
|
||||
if content == "" {
|
||||
content = strings.TrimSpace(row.Summary)
|
||||
}
|
||||
return &Notice{ID: 0, Title: row.Title, Content: content, BodyHTML: row.BodyHTML,
|
||||
SourceType: "managed_content", CreatedAt: row.PublishedAt}, nil
|
||||
}
|
||||
|
||||
func (s *Service) MarkNoticeRead(ctx context.Context, tenantID, memberID, noticeID int64) error {
|
||||
@@ -225,6 +229,20 @@ func (s *Service) Content(ctx context.Context, tenantID int64, key string) (*Con
|
||||
if !contentKeyPattern.MatchString(key) {
|
||||
return nil, ErrContentKeyInvalid
|
||||
}
|
||||
requestedKey := key
|
||||
titleOverride := ""
|
||||
switch key {
|
||||
case "platform_intro", "user_agreement":
|
||||
key = "platform_introduction"
|
||||
if requestedKey == "user_agreement" {
|
||||
titleOverride = "用户协议"
|
||||
}
|
||||
case "privacy_policy":
|
||||
// 当前后台只维护原型的 12 条正式文本,隐私条款沿用平台协议正文,
|
||||
// 避免为了前端路由额外制造一条无法在原型中对应的初始化数据。
|
||||
key = "platform_introduction"
|
||||
titleOverride = "隐私政策"
|
||||
}
|
||||
row, err := s.repository.PublishedContent(ctx, tenantID, key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -233,7 +251,11 @@ func (s *Service) Content(ctx context.Context, tenantID int64, key string) (*Con
|
||||
if row.AssetIDs.Valid && strings.TrimSpace(row.AssetIDs.String) != "" {
|
||||
_ = json.Unmarshal([]byte(row.AssetIDs.String), &assetIDs)
|
||||
}
|
||||
return &Content{ContentKey: row.ContentKey, ContentType: row.ContentType, Title: row.Title,
|
||||
title := row.Title
|
||||
if titleOverride != "" {
|
||||
title = titleOverride
|
||||
}
|
||||
return &Content{ContentKey: requestedKey, ContentType: row.ContentType, Title: title,
|
||||
Summary: row.Summary, BodyHTML: row.BodyHTML, BodyText: row.BodyText, CoverURL: row.CoverURL,
|
||||
AssetIDs: assetIDs, Version: row.Version, PublishedAt: row.PublishedAt}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user