feat: implement Phase 2 - Equipment Management and Training Zones

This commit is contained in:
Cipher Vance
2025-11-22 19:51:16 -06:00
parent c680333ef6
commit d6b91acdda
9 changed files with 548 additions and 17 deletions

View File

@@ -2,6 +2,7 @@ package user
import (
"errors"
"log"
"rideaware/pkg/database"
"gorm.io/gorm"
)
@@ -40,17 +41,45 @@ func (r *Repository) GetUserByEmail(email string) (*User, error) {
func (r *Repository) GetUserByID(id uint) (*User, error) {
var user User
if err := database.DB.Preload("Profile").Where("id = ?", id).First(&user).Error; err != nil {
// Get the user
if err := database.DB.Where("id = ?", id).First(&user).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, errors.New("user not found")
}
return nil, err
}
// Manually load the profile
var profile Profile
if err := database.DB.Where("user_id = ?", id).First(&profile).Error; err != nil {
if !errors.Is(err, gorm.ErrRecordNotFound) {
log.Printf("Error loading profile: %v", err)
}
// Profile might not exist, that's okay
} else {
user.Profile = &profile
}
log.Printf("DEBUG: Loaded user %d, profile ID=%d, profile=%+v", id, profile.ID, user.Profile)
return &user, nil
}
func (r *Repository) UpdateUser(user *User) error {
return database.DB.Save(user).Error
// Update the user
if err := database.DB.Model(user).Updates(user).Error; err != nil {
return err
}
// Update the profile if it exists
if user.Profile != nil {
if err := database.DB.Model(user.Profile).Updates(user.Profile).Error; err != nil {
return err
}
}
return nil
}
func (r *Repository) UserExists(username, email string) (bool, error) {