Files
Novault-backend/internal/models/user_streak.go

38 lines
1.4 KiB
Go

package models
import (
"time"
)
// UserStreak represents a user's consecutive recording streak
type UserStreak struct {
ID uint `gorm:"primarykey" json:"id"`
UserID uint `gorm:"uniqueIndex;not null" json:"user_id"`
CurrentStreak int `gorm:"default:0" json:"current_streak"` // 当前连续天数
LongestStreak int `gorm:"default:0" json:"longest_streak"` // 最长连续记录
LastRecordDate *time.Time `gorm:"type:date" json:"last_record_date"` // 最后记账日期
TotalRecordDays int `gorm:"default:0" json:"total_record_days"` // 累计记账天数
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// TableName specifies the table name for UserStreak
func (UserStreak) TableName() string {
return "user_streaks"
}
// StreakInfo represents the streak information returned to frontend
type StreakInfo struct {
CurrentStreak int `json:"current_streak"` // 当前连续天数
LongestStreak int `json:"longest_streak"` // 最长连续记录
TotalRecordDays int `json:"total_record_days"` // 累计记账天数
HasRecordToday bool `json:"has_record_today"` // 今天是否已记账
Message string `json:"message"` // 提示信息
}
// DailyContribution represents transaction count for a specific date
type DailyContribution struct {
Date string `json:"date"`
Count int `json:"count"`
}