From 5a054d250e2a6d4e7979afac7ddb5798e402d6b3 Mon Sep 17 00:00:00 2001 From: mkelvers Date: Tue, 26 May 2026 22:41:29 +0200 Subject: [PATCH] refactor: domain auth types --- internal/auth/repository/repository.go | 12 ++++++------ internal/domain/auth.go | 14 +++++++++++--- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/internal/auth/repository/repository.go b/internal/auth/repository/repository.go index 74524e4..8b67d98 100644 --- a/internal/auth/repository/repository.go +++ b/internal/auth/repository/repository.go @@ -27,7 +27,7 @@ func (r *authRepository) GetUserByUsername(ctx context.Context, username string) } return nil, err } - return &u, nil + return &domain.User{User: u}, nil } func (r *authRepository) GetUserByID(ctx context.Context, id string) (*domain.User, error) { @@ -38,7 +38,7 @@ func (r *authRepository) GetUserByID(ctx context.Context, id string) (*domain.Us } return nil, err } - return &u, nil + return &domain.User{User: u}, nil } func (r *authRepository) CreateSession(ctx context.Context, userID string, sessionID string) (*domain.Session, error) { @@ -50,7 +50,7 @@ func (r *authRepository) CreateSession(ctx context.Context, userID string, sessi if err != nil { return nil, err } - return &s, nil + return &domain.Session{Session: s}, nil } func (r *authRepository) GetSession(ctx context.Context, sessionID string) (*domain.Session, error) { @@ -61,7 +61,7 @@ func (r *authRepository) GetSession(ctx context.Context, sessionID string) (*dom } return nil, err } - return &s, nil + return &domain.Session{Session: s}, nil } func (r *authRepository) RefreshSession(ctx context.Context, sessionID string, expiresAt time.Time) error { @@ -85,7 +85,7 @@ func (r *authRepository) CreateAPIToken(ctx context.Context, userID, tokenHash, if err != nil { return nil, err } - return &t, nil + return &domain.APIToken{ApiToken: t}, nil } func (r *authRepository) GetAPITokenByHash(ctx context.Context, tokenHash string) (*domain.APIToken, error) { @@ -96,7 +96,7 @@ func (r *authRepository) GetAPITokenByHash(ctx context.Context, tokenHash string } return nil, err } - return &t, nil + return &domain.APIToken{ApiToken: t}, nil } func (r *authRepository) TouchAPITokenLastUsedAt(ctx context.Context, tokenID string) error { diff --git a/internal/domain/auth.go b/internal/domain/auth.go index 71bf372..e89a0d2 100644 --- a/internal/domain/auth.go +++ b/internal/domain/auth.go @@ -6,9 +6,17 @@ import ( "time" ) -type User = db.User -type Session = db.Session -type APIToken = db.ApiToken +type User struct { + db.User +} + +type Session struct { + db.Session +} + +type APIToken struct { + db.ApiToken +} const SessionLifetime = 90 * 24 * time.Hour