80 lines
3.2 KiB
Go
80 lines
3.2 KiB
Go
|
|
package responses
|
||
|
|
|
||
|
|
import (
|
||
|
|
"time"
|
||
|
|
"tyapi-server/internal/domains/article/entities"
|
||
|
|
)
|
||
|
|
|
||
|
|
// AnnouncementInfoResponse 公告详情响应
|
||
|
|
type AnnouncementInfoResponse struct {
|
||
|
|
ID string `json:"id" comment:"公告ID"`
|
||
|
|
Title string `json:"title" comment:"公告标题"`
|
||
|
|
Content string `json:"content" comment:"公告内容"`
|
||
|
|
Status string `json:"status" comment:"公告状态"`
|
||
|
|
ScheduledAt *time.Time `json:"scheduled_at" comment:"定时发布时间"`
|
||
|
|
CreatedAt time.Time `json:"created_at" comment:"创建时间"`
|
||
|
|
UpdatedAt time.Time `json:"updated_at" comment:"更新时间"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// AnnouncementListItemResponse 公告列表项响应
|
||
|
|
type AnnouncementListItemResponse struct {
|
||
|
|
ID string `json:"id" comment:"公告ID"`
|
||
|
|
Title string `json:"title" comment:"公告标题"`
|
||
|
|
Content string `json:"content" comment:"公告内容"`
|
||
|
|
Status string `json:"status" comment:"公告状态"`
|
||
|
|
ScheduledAt *time.Time `json:"scheduled_at" comment:"定时发布时间"`
|
||
|
|
CreatedAt time.Time `json:"created_at" comment:"创建时间"`
|
||
|
|
UpdatedAt time.Time `json:"updated_at" comment:"更新时间"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// AnnouncementListResponse 公告列表响应
|
||
|
|
type AnnouncementListResponse struct {
|
||
|
|
Total int64 `json:"total" comment:"总数"`
|
||
|
|
Page int `json:"page" comment:"页码"`
|
||
|
|
Size int `json:"size" comment:"每页数量"`
|
||
|
|
Items []AnnouncementListItemResponse `json:"items" comment:"公告列表"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// AnnouncementStatsResponse 公告统计响应
|
||
|
|
type AnnouncementStatsResponse struct {
|
||
|
|
TotalAnnouncements int64 `json:"total_announcements" comment:"公告总数"`
|
||
|
|
PublishedAnnouncements int64 `json:"published_announcements" comment:"已发布公告数"`
|
||
|
|
DraftAnnouncements int64 `json:"draft_announcements" comment:"草稿公告数"`
|
||
|
|
ArchivedAnnouncements int64 `json:"archived_announcements" comment:"归档公告数"`
|
||
|
|
ScheduledAnnouncements int64 `json:"scheduled_announcements" comment:"定时发布公告数"`
|
||
|
|
}
|
||
|
|
|
||
|
|
// FromAnnouncementEntity 从公告实体转换为响应对象
|
||
|
|
func FromAnnouncementEntity(announcement *entities.Announcement) *AnnouncementInfoResponse {
|
||
|
|
if announcement == nil {
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
return &AnnouncementInfoResponse{
|
||
|
|
ID: announcement.ID,
|
||
|
|
Title: announcement.Title,
|
||
|
|
Content: announcement.Content,
|
||
|
|
Status: string(announcement.Status),
|
||
|
|
ScheduledAt: announcement.ScheduledAt,
|
||
|
|
CreatedAt: announcement.CreatedAt,
|
||
|
|
UpdatedAt: announcement.UpdatedAt,
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// FromAnnouncementEntityList 从公告实体列表转换为列表项响应
|
||
|
|
func FromAnnouncementEntityList(announcements []*entities.Announcement) []AnnouncementListItemResponse {
|
||
|
|
items := make([]AnnouncementListItemResponse, 0, len(announcements))
|
||
|
|
for _, announcement := range announcements {
|
||
|
|
items = append(items, AnnouncementListItemResponse{
|
||
|
|
ID: announcement.ID,
|
||
|
|
Title: announcement.Title,
|
||
|
|
Content: announcement.Content,
|
||
|
|
Status: string(announcement.Status),
|
||
|
|
ScheduledAt: announcement.ScheduledAt,
|
||
|
|
CreatedAt: announcement.CreatedAt,
|
||
|
|
UpdatedAt: announcement.UpdatedAt,
|
||
|
|
})
|
||
|
|
}
|
||
|
|
return items
|
||
|
|
}
|