Files
qitongxue-api/internal/logic/event_public.go
2026-09-29 10:57:01 +08:00

44 lines
1.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package logic
import (
"context"
"github.com/gogf/gf/v2/frame/g"
v1 "tool-api/api/user/v1"
"tool-api/internal/consts"
)
// ============================================================================
// 年会域:公开「可查询活动列表」(N4-A / E-list,免登录)
// 依据:增量架构 §4.3(E-list)、§2.3;PRD-02 查座入口。
//
// 契约:
// - 只返回已发布(status=published,即 can_query=true)的活动;
// - 无已发布活动 → {list:[]}(**非报错**,前端据此渲染空态);
// - 草稿(draft)/ 已结束(ended)**不出现**;
// - 只暴露最小字段(event_id / title / venue / event_time),不含任何组织 / 名单信息。
// ============================================================================
// EventPublicList 公开可查询活动列表。
func EventPublicList(ctx context.Context) (*v1.EventPublicListRes, error) {
records, err := g.Model(consts.TableAnnualEvents).
Where("status", consts.EventStatusPublished).
OrderDesc("id").
All()
if err != nil {
return nil, err
}
// 用 make(...,0,...) 保证空结果序列化为 [](而非 null)。
list := make([]v1.EventPublicItem, 0, len(records))
for _, r := range records {
list = append(list, v1.EventPublicItem{
EventId: r["id"].Int64(),
Title: r["title"].String(),
Venue: r["venue"].String(),
EventTime: formatGTime(r["event_time"].GTime()),
})
}
return &v1.EventPublicListRes{List: list}, nil
}