Store date_of_birth (DATE) instead of a static age integer so that age is always computed dynamically from the stored date of birth. - Migration 011: adds date_of_birth, backfills from age, drops age - AgeFromDOB helper computes current age from YYYY-MM-DD string - User model, repository SQL, and service validation updated - Flutter: User.age becomes a computed getter; profile edit screen uses a date picker bounded to [today-120y, today-10y] Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
45 lines
1.6 KiB
Go
45 lines
1.6 KiB
Go
package user
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
)
|
|
|
|
type User struct {
|
|
ID string `json:"id"`
|
|
FirebaseUID string `json:"-"`
|
|
Email string `json:"email"`
|
|
Name string `json:"name"`
|
|
AvatarURL *string `json:"avatar_url"`
|
|
HeightCM *int `json:"height_cm"`
|
|
WeightKG *float64 `json:"weight_kg"`
|
|
DateOfBirth *string `json:"date_of_birth"`
|
|
Gender *string `json:"gender"`
|
|
Activity *string `json:"activity"`
|
|
Goal *string `json:"goal"`
|
|
DailyCalories *int `json:"daily_calories"`
|
|
Plan string `json:"plan"`
|
|
Preferences json.RawMessage `json:"preferences"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
type UpdateProfileRequest struct {
|
|
Name *string `json:"name"`
|
|
HeightCM *int `json:"height_cm"`
|
|
WeightKG *float64 `json:"weight_kg"`
|
|
DateOfBirth *string `json:"date_of_birth"`
|
|
Gender *string `json:"gender"`
|
|
Activity *string `json:"activity"`
|
|
Goal *string `json:"goal"`
|
|
Preferences *json.RawMessage `json:"preferences"`
|
|
DailyCalories *int `json:"-"` // internal, set by service
|
|
}
|
|
|
|
// HasBodyParams returns true if any body parameter is being updated
|
|
// that would require recalculation of daily calories.
|
|
func (r *UpdateProfileRequest) HasBodyParams() bool {
|
|
return r.HeightCM != nil || r.WeightKG != nil || r.DateOfBirth != nil ||
|
|
r.Gender != nil || r.Activity != nil || r.Goal != nil
|
|
}
|