Files
mce/internal/service/announcement_service.go
Victor_Jay fc57ed17d4 feat: 公告系统 — Phase 2 完成
- Model/Repo/Service/Controller 全栈实现
- CRUD + ListActive(生效时间范围过滤)
- 管理后台独立页面 /admin/announcements(列表+弹窗CRUD)
- 前台首页 Hero 下方公告栏(info/success/warning/error 四色)
- Moderator+ 权限可管理公告
2026-06-22 00:00:21 +08:00

60 lines
1.5 KiB
Go
Raw Permalink 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 service
import "metazone.cc/mce/internal/model"
// AnnouncementTypes 公告类型及其显示名称和颜色
var AnnouncementTypes = map[string]struct {
Label string
Color string
}{
"info": {"信息", "#3b82f6"},
"success": {"成功", "#22c55e"},
"warning": {"警告", "#f59e0b"},
"error": {"错误", "#ef4444"},
}
// AnnouncementStore 公告仓库接口ISP
type AnnouncementStore interface {
Create(a *model.Announcement) error
Update(a *model.Announcement) error
Delete(id uint) error
FindByID(id uint) (*model.Announcement, error)
List(offset, limit int) ([]model.Announcement, int64, error)
ListActive() ([]model.Announcement, error)
}
// AnnouncementService 公告业务逻辑
type AnnouncementService struct {
repo AnnouncementStore
}
// NewAnnouncementService 构造函数
func NewAnnouncementService(repo AnnouncementStore) *AnnouncementService {
return &AnnouncementService{repo: repo}
}
// Create 创建公告
func (s *AnnouncementService) Create(a *model.Announcement) error {
return s.repo.Create(a)
}
// Update 更新公告
func (s *AnnouncementService) Update(a *model.Announcement) error {
return s.repo.Update(a)
}
// Delete 删除公告
func (s *AnnouncementService) Delete(id uint) error {
return s.repo.Delete(id)
}
// List 分页列表
func (s *AnnouncementService) List(offset, limit int) ([]model.Announcement, int64, error) {
return s.repo.List(offset, limit)
}
// ListActive 生效中的公告
func (s *AnnouncementService) ListActive() ([]model.Announcement, error) {
return s.repo.ListActive()
}