feat: 戒烟成就、梦想图标预设、打卡统计与依赖注入调整
- 成就系统、连续打卡天数计算、管理后台成就 CRUD - 梦想目标图标预设 DreamPreset 与用户端 dream-presets 接口 - 管理后台梦想图标 CRUD;戒烟打卡 summary 修正 - 忽略根目录编译产物 /api Made-with: Cursor
This commit is contained in:
@@ -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