增加公告图片编辑, 增加取消归档

This commit is contained in:
yml
2026-06-15 20:37:13 +08:00
parent 85f2d9b3b3
commit 9271f47553
16 changed files with 765 additions and 26 deletions
@@ -173,6 +173,22 @@ func (h *Handler) Archive(c *gin.Context) {
response.OK(c, gin.H{"message": "归档成功"})
}
// Unarchive 取消归档公告
func (h *Handler) Unarchive(c *gin.Context) {
id, err := parseID(c)
if err != nil {
response.BadRequest(c, "公告ID不正确")
return
}
if err := h.service.Unarchive(c.Request.Context(), id); err != nil {
response.InternalServerError(c, "取消归档公告失败")
return
}
response.OK(c, gin.H{"message": "取消归档成功"})
}
// Delete 删除公告
func (h *Handler) Delete(c *gin.Context) {
id, err := parseID(c)
@@ -179,6 +179,17 @@ func (r *Repository) Archive(ctx context.Context, id uint64) error {
Update("status", "archived").Error
}
// Unarchive 取消归档公告,恢复为已发布状态
func (r *Repository) Unarchive(ctx context.Context, id uint64) error {
now := time.Now()
return r.db.WithContext(ctx).Model(&model.Announcement{}).
Where("id = ?", id).
Updates(map[string]interface{}{
"status": "published",
"published_at": gorm.Expr("COALESCE(published_at, ?)", now),
}).Error
}
// Delete 删除公告
func (r *Repository) Delete(ctx context.Context, id uint64) error {
return r.db.WithContext(ctx).Where("id = ?", id).Delete(&model.Announcement{}).Error
@@ -95,6 +95,11 @@ func (s *Service) Archive(ctx context.Context, id uint64) error {
return s.repo.Archive(ctx, id)
}
// Unarchive 取消归档公告
func (s *Service) Unarchive(ctx context.Context, id uint64) error {
return s.repo.Unarchive(ctx, id)
}
// Delete 删除公告
func (s *Service) Delete(ctx context.Context, id uint64) error {
return s.repo.Delete(ctx, id)