Remove timezone from User model and pass as request parameter

Timezone is now sent from the client on each request that needs it,
instead of storing it in the database. This simplifies the model and
allows timezone to be dynamic (useful for traveling users).

Changes:
- Remove timezone field from User entity
- Remove timezone from user registration
- GET /habits/today now requires ?timezone= query param
- Add migration to drop timezone column from database
- Update related tests
This commit is contained in:
2025-11-29 16:18:04 +01:00
parent a2aa8b2a76
commit 5d92820591
21 changed files with 75 additions and 153 deletions
+1 -6
View File
@@ -6,7 +6,6 @@ type User struct {
ID string
Email string
PasswordHash string
Timezone string
EmailVerified bool
EmailVerificationToken *string
EmailVerificationExpiry *time.Time
@@ -14,15 +13,11 @@ type User struct {
UpdatedAt time.Time
}
func NewUser(email, passwordHash, timezone string) *User {
func NewUser(email, passwordHash string) *User {
now := time.Now()
if timezone == "" {
timezone = "UTC"
}
return &User{
Email: email,
PasswordHash: passwordHash,
Timezone: timezone,
CreatedAt: now,
UpdatedAt: now,
}
+1 -14
View File
@@ -8,9 +8,8 @@ import (
func TestNewUser(t *testing.T) {
email := "test@example.com"
passwordHash := "hashed_password_123"
timezone := "Europe/Madrid"
user := NewUser(email, passwordHash, timezone)
user := NewUser(email, passwordHash)
if user.Email != email {
t.Errorf("Expected email %s, got %s", email, user.Email)
@@ -20,10 +19,6 @@ func TestNewUser(t *testing.T) {
t.Errorf("Expected password hash %s, got %s", passwordHash, user.PasswordHash)
}
if user.Timezone != timezone {
t.Errorf("Expected timezone %s, got %s", timezone, user.Timezone)
}
if user.CreatedAt.IsZero() {
t.Error("CreatedAt should not be zero")
}
@@ -37,11 +32,3 @@ func TestNewUser(t *testing.T) {
t.Errorf("CreatedAt and UpdatedAt should be nearly identical, diff: %v", diff)
}
}
func TestUser_DefaultTimezone(t *testing.T) {
user := NewUser("test@example.com", "hash", "")
if user.Timezone != "UTC" {
t.Errorf("Expected default timezone UTC, got %s", user.Timezone)
}
}