213 lines
7.3 KiB
Go
213 lines
7.3 KiB
Go
package model
|
|
|
|
import "time"
|
|
|
|
type User struct {
|
|
ID int64 `json:"id"`
|
|
Username string `json:"username"`
|
|
PasswordHash string `json:"-"`
|
|
Nickname string `json:"nickname"`
|
|
AvatarURL string `json:"avatar_url"`
|
|
Bio string `json:"bio"`
|
|
IsAdmin bool `json:"is_admin"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
|
|
// 减重纪元
|
|
type WeightEpoch struct {
|
|
ID int64 `json:"id"`
|
|
UserID int64 `json:"user_id"`
|
|
Name string `json:"name"`
|
|
InitialWeight float64 `json:"initial_weight"`
|
|
TargetWeight float64 `json:"target_weight"`
|
|
StartDate string `json:"start_date"`
|
|
EndDate string `json:"end_date"`
|
|
FinalWeight *float64 `json:"final_weight"`
|
|
IsActive bool `json:"is_active"`
|
|
IsCompleted bool `json:"is_completed"`
|
|
CreatedAt string `json:"created_at"`
|
|
}
|
|
|
|
// 纪元详情(包含统计)
|
|
type EpochDetail struct {
|
|
Epoch *WeightEpoch `json:"epoch"`
|
|
YearDaysPassed int `json:"year_days_passed"` // 今年已过天数
|
|
EpochDaysPassed int `json:"epoch_days_passed"` // 纪元已过天数
|
|
DaysRemaining int `json:"days_remaining"` // 剩余天数
|
|
CurrentWeight *float64 `json:"current_weight"` // 当前体重(最新记录)
|
|
ActualChange *float64 `json:"actual_change"` // 实际减重
|
|
DistanceToGoal *float64 `json:"distance_to_goal"` // 距离目标
|
|
IsQualified bool `json:"is_qualified"` // 是否合格
|
|
EpochTotalLoss *float64 `json:"epoch_total_loss"` // 本纪元总减重
|
|
YearTotalLoss *float64 `json:"year_total_loss"` // 本年度总减重
|
|
AllTimeTotalLoss *float64 `json:"all_time_total_loss"` // 累计总减重
|
|
}
|
|
|
|
// 每周计划
|
|
type WeeklyPlan struct {
|
|
ID int64 `json:"id"`
|
|
EpochID int64 `json:"epoch_id"`
|
|
UserID int64 `json:"user_id"`
|
|
Year int `json:"year"`
|
|
Week int `json:"week"`
|
|
StartDate string `json:"start_date"`
|
|
EndDate string `json:"end_date"`
|
|
InitialWeight *float64 `json:"initial_weight"` // 周初始体重
|
|
TargetWeight *float64 `json:"target_weight"` // 周目标体重
|
|
FinalWeight *float64 `json:"final_weight"` // 周最终体重
|
|
Note string `json:"note"`
|
|
CreatedAt string `json:"created_at"`
|
|
}
|
|
|
|
// 周计划详情
|
|
type WeeklyPlanDetail struct {
|
|
Plan *WeeklyPlan `json:"plan"`
|
|
WeightChange *float64 `json:"weight_change"` // 本周减重
|
|
IsQualified bool `json:"is_qualified"` // 是否达标
|
|
IsPast bool `json:"is_past"` // 是否已过
|
|
InitialWeightEditable bool `json:"initial_weight_editable"` // 初始体重是否可编辑
|
|
}
|
|
|
|
// 体重目标 (保留兼容)
|
|
type WeightGoal struct {
|
|
ID int64 `json:"id"`
|
|
UserID int64 `json:"user_id"`
|
|
TargetWeight float64 `json:"target_weight"`
|
|
StartDate string `json:"start_date"`
|
|
CreatedAt string `json:"created_at"`
|
|
}
|
|
|
|
// 体重记录
|
|
type WeightRecord struct {
|
|
ID int64 `json:"id"`
|
|
UserID int64 `json:"user_id"`
|
|
Weight float64 `json:"weight"`
|
|
Year int `json:"year"`
|
|
Week int `json:"week"`
|
|
RecordDate string `json:"record_date"`
|
|
Note string `json:"note"`
|
|
CreatedAt string `json:"created_at"`
|
|
}
|
|
|
|
// 周数据(包含对比信息)
|
|
type WeekWeightData struct {
|
|
Year int `json:"year"`
|
|
Week int `json:"week"`
|
|
StartDate string `json:"start_date"`
|
|
EndDate string `json:"end_date"`
|
|
InitialWeight *float64 `json:"initial_weight"` // 本周初始体重(上周最终体重)
|
|
Weight *float64 `json:"weight"` // 本周最终体重
|
|
PrevWeight *float64 `json:"prev_weight"`
|
|
WeightChange *float64 `json:"weight_change"` // 本周实际减重 = 初始体重 - 最终体重
|
|
HasRecord bool `json:"has_record"`
|
|
}
|
|
|
|
// 体重统计
|
|
type WeightStats struct {
|
|
TotalWeeks int `json:"total_weeks"`
|
|
TotalChange *float64 `json:"total_change"`
|
|
FirstWeight *float64 `json:"first_weight"`
|
|
LatestWeight *float64 `json:"latest_weight"`
|
|
TargetWeight *float64 `json:"target_weight"`
|
|
StartDate *string `json:"start_date"`
|
|
}
|
|
|
|
// 请求/响应结构
|
|
type RegisterRequest struct {
|
|
Username string `json:"username" binding:"required,min=3,max=20"`
|
|
Password string `json:"password" binding:"required,min=6"`
|
|
Nickname string `json:"nickname" binding:"required,min=1,max=50"`
|
|
}
|
|
|
|
type LoginRequest struct {
|
|
Username string `json:"username" binding:"required"`
|
|
Password string `json:"password" binding:"required"`
|
|
}
|
|
|
|
type LoginResponse struct {
|
|
Token string `json:"token"`
|
|
User *User `json:"user"`
|
|
}
|
|
|
|
type UpdateProfileRequest struct {
|
|
Nickname string `json:"nickname" binding:"max=50"`
|
|
Bio string `json:"bio" binding:"max=200"`
|
|
}
|
|
|
|
type ProfileResponse struct {
|
|
User *User `json:"user"`
|
|
CreatedAt string `json:"created_at"`
|
|
}
|
|
|
|
// 纪元相关请求
|
|
type CreateEpochRequest struct {
|
|
Name string `json:"name"`
|
|
InitialWeight float64 `json:"initial_weight" binding:"required,gt=0"`
|
|
TargetWeight float64 `json:"target_weight" binding:"required,gt=0"`
|
|
StartDate string `json:"start_date" binding:"required"`
|
|
EndDate string `json:"end_date" binding:"required"`
|
|
}
|
|
|
|
type UpdateWeeklyPlanRequest struct {
|
|
InitialWeight *float64 `json:"initial_weight"`
|
|
TargetWeight *float64 `json:"target_weight"`
|
|
FinalWeight *float64 `json:"final_weight"`
|
|
Note string `json:"note"`
|
|
}
|
|
|
|
type UpdateEpochRequest struct {
|
|
Name *string `json:"name"`
|
|
InitialWeight *float64 `json:"initial_weight"`
|
|
TargetWeight *float64 `json:"target_weight"`
|
|
StartDate *string `json:"start_date"`
|
|
EndDate *string `json:"end_date"`
|
|
}
|
|
|
|
// 体重相关请求 (保留兼容)
|
|
type SetWeightGoalRequest struct {
|
|
TargetWeight float64 `json:"target_weight" binding:"required,gt=0"`
|
|
StartDate string `json:"start_date" binding:"required"`
|
|
}
|
|
|
|
type RecordWeightRequest struct {
|
|
Weight float64 `json:"weight" binding:"required,gt=0"`
|
|
Year int `json:"year" binding:"required"`
|
|
Week int `json:"week" binding:"required,min=1,max=53"`
|
|
Note string `json:"note"`
|
|
}
|
|
|
|
|
|
// 运动打卡
|
|
type ExerciseCheckin struct {
|
|
ID int64 `json:"id"`
|
|
UserID int64 `json:"user_id"`
|
|
CheckinDate string `json:"checkin_date"`
|
|
ExerciseType string `json:"exercise_type"` // "aerobic" 或 "anaerobic"
|
|
BodyPart string `json:"body_part"` // 无氧运动部位: "leg", "chest", "back", "abs"
|
|
Duration int `json:"duration"` // 有氧运动时长(分钟)
|
|
Note string `json:"note"`
|
|
CreatedAt string `json:"created_at"`
|
|
}
|
|
|
|
type CreateExerciseCheckinRequest struct {
|
|
CheckinDate string `json:"checkin_date" binding:"required"`
|
|
ExerciseType string `json:"exercise_type" binding:"required"`
|
|
BodyPart string `json:"body_part"`
|
|
Duration int `json:"duration"`
|
|
Note string `json:"note"`
|
|
}
|
|
|
|
type ExerciseHeatmapData struct {
|
|
Date string `json:"date"`
|
|
Count int `json:"count"`
|
|
}
|
|
|
|
type ExerciseStats struct {
|
|
TotalCheckins int `json:"total_checkins"`
|
|
CurrentStreak int `json:"current_streak"`
|
|
LongestStreak int `json:"longest_streak"`
|
|
ThisMonth int `json:"this_month"`
|
|
ThisWeek int `json:"this_week"`
|
|
ThisYearDays int `json:"this_year_days"`
|
|
}
|