lots of stuff, don't truly remember

This commit is contained in:
Blake Ridgway
2026-05-17 20:39:47 -05:00
parent 178ffb3425
commit dc4fe558b7
35 changed files with 3501 additions and 112 deletions

View File

@@ -35,8 +35,6 @@ func (h *Handler) GetProfile(w http.ResponseWriter, r *http.Request) {
return
}
log.Printf("DEBUG GetProfile: User ID=%d, Profile=%+v", user.ID, user.Profile)
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(GetProfileResponse{
User: user,
@@ -48,13 +46,21 @@ func (h *Handler) UpdateProfile(w http.ResponseWriter, r *http.Request) {
claims := r.Context().Value(middleware.UserContextKey).(*config.CustomClaims)
var req struct {
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Bio string `json:"bio"`
FTP int `json:"ftp"`
MaxHR int `json:"max_hr"`
RestingHR int `json:"resting_hr"`
Weight float64 `json:"weight"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Bio string `json:"bio"`
FTP int `json:"ftp"`
MaxHR int `json:"max_hr"`
RestingHR int `json:"resting_hr"`
Weight float64 `json:"weight"`
Height float64 `json:"height"`
Age int `json:"age"`
Gender string `json:"gender"`
NutritionGoal string `json:"nutrition_goal"`
TargetWeight float64 `json:"target_weight"`
ActivityLevel string `json:"activity_level"`
DietaryPref string `json:"dietary_preference"`
Units string `json:"units"`
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
@@ -72,8 +78,6 @@ func (h *Handler) UpdateProfile(w http.ResponseWriter, r *http.Request) {
return
}
log.Printf("DEBUG UpdateProfile: Before - Profile=%+v", user.Profile)
if user.Profile != nil {
user.Profile.FirstName = req.FirstName
user.Profile.LastName = req.LastName
@@ -82,11 +86,19 @@ func (h *Handler) UpdateProfile(w http.ResponseWriter, r *http.Request) {
user.Profile.MaxHR = req.MaxHR
user.Profile.RestingHR = req.RestingHR
user.Profile.Weight = req.Weight
log.Printf("DEBUG UpdateProfile: After - Profile=%+v", user.Profile)
user.Profile.Height = req.Height
user.Profile.Age = req.Age
user.Profile.Gender = req.Gender
user.Profile.NutritionGoal = req.NutritionGoal
user.Profile.TargetWeight = req.TargetWeight
user.Profile.ActivityLevel = req.ActivityLevel
user.Profile.DietaryPref = req.DietaryPref
if req.Units == "imperial" || req.Units == "metric" {
user.Profile.Units = req.Units
}
if err := h.service.UpdateUser(user); err != nil {
log.Printf("DEBUG UpdateProfile: Error updating - %v", err)
log.Printf("UpdateProfile: error saving - %v", err)
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusInternalServerError)
json.NewEncoder(w).Encode(map[string]string{"error": "failed to update profile"})
@@ -95,7 +107,7 @@ func (h *Handler) UpdateProfile(w http.ResponseWriter, r *http.Request) {
user, err = h.service.GetUserByID(claims.UserID)
if err != nil {
log.Printf("DEBUG UpdateProfile: Error reloading - %v", err)
log.Printf("UpdateProfile: error reloading user - %v", err)
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusInternalServerError)
json.NewEncoder(w).Encode(map[string]string{"error": "failed to load profile"})
@@ -103,8 +115,6 @@ func (h *Handler) UpdateProfile(w http.ResponseWriter, r *http.Request) {
}
}
log.Printf("DEBUG UpdateProfile: Final - Profile=%+v", user.Profile)
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(GetProfileResponse{
User: user,