feat: 戒烟成就、梦想图标预设、打卡统计与依赖注入调整
- 成就系统、连续打卡天数计算、管理后台成就 CRUD - 梦想目标图标预设 DreamPreset 与用户端 dream-presets 接口 - 管理后台梦想图标 CRUD;戒烟打卡 summary 修正 - 忽略根目录编译产物 /api Made-with: Cursor
This commit is contained in:
@@ -330,6 +330,16 @@ func (h *Handler) ListRelapses(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, model.Success(result))
|
||||
}
|
||||
|
||||
// ListDreamPresets 获取管理员预设的梦想目标列表。
|
||||
func (h *Handler) ListDreamPresets(c *gin.Context) {
|
||||
presets, err := h.service.ListDreamPresets(c.Request.Context())
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, model.Error(http.StatusInternalServerError, "获取预设目标失败"))
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, model.Success(gin.H{"items": presets}))
|
||||
}
|
||||
|
||||
// ListRewardGoals 获取梦想目标列表。
|
||||
// @Summary 获取梦想目标列表
|
||||
// @Description 按状态筛选梦想目标,用于梦想实验室页面展示。
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type DreamPreset struct {
|
||||
ID uint `gorm:"primaryKey;comment:主键" json:"id"`
|
||||
CreatedAt time.Time `gorm:"comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"comment:更新时间" json:"updated_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"-"`
|
||||
|
||||
Title string `gorm:"column:title;size:64;comment:图标名称" json:"title"`
|
||||
CoverImage string `gorm:"column:cover_image;size:500;comment:图标(emoji或图片URL)" json:"cover_image"`
|
||||
IsActive bool `gorm:"column:is_active;default:true;comment:是否启用" json:"is_active"`
|
||||
SortOrder int `gorm:"column:sort_order;default:0;comment:排序" json:"sort_order"`
|
||||
}
|
||||
|
||||
func (DreamPreset) TableName() string {
|
||||
return "fa_dream_goal_preset"
|
||||
}
|
||||
@@ -986,6 +986,9 @@ func (s *Service) computeSummary(ctx context.Context, uid int, profile quitmodel
|
||||
}
|
||||
|
||||
elapsedDays := daysBetween(normalizeDate(profile.QuitStartDate), today)
|
||||
if currentStreak > elapsedDays {
|
||||
elapsedDays = currentStreak
|
||||
}
|
||||
theoreticalCigs := elapsedDays * profile.BaselineCigsPerDay
|
||||
avoidedCigs := theoreticalCigs - totalRelapseNum
|
||||
if avoidedCigs < 0 {
|
||||
@@ -1129,6 +1132,18 @@ func SortRelapses(items []RelapseEventResult) {
|
||||
})
|
||||
}
|
||||
|
||||
// ListDreamPresets 返回启用的预设梦想目标列表。
|
||||
func (s *Service) ListDreamPresets(ctx context.Context) ([]quitmodel.DreamPreset, error) {
|
||||
var presets []quitmodel.DreamPreset
|
||||
if err := s.db.WithContext(ctx).
|
||||
Where("is_active = ?", true).
|
||||
Order("sort_order ASC, id ASC").
|
||||
Find(&presets).Error; err != nil {
|
||||
return nil, fmt.Errorf("list dream presets: %w", err)
|
||||
}
|
||||
return presets, nil
|
||||
}
|
||||
|
||||
func normalizeShowFields(items []string) []string {
|
||||
allowed := map[string]struct{}{
|
||||
"streak_days": {},
|
||||
|
||||
Reference in New Issue
Block a user