tsk-34: Update last login of user (#37)

Closes #34

Reviewed-on: phoenix/textsender-auth#37
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
This commit is contained in:
phoenix
2025-12-31 23:13:02 +00:00
committed by phoenix
parent d34cad033d
commit de171b790d
10 changed files with 101 additions and 12 deletions
+11
View File
@@ -3,6 +3,7 @@ package store
import (
"context"
"fmt"
"time"
"github.com/google/uuid"
"github.com/jackc/pgx/v5"
@@ -18,6 +19,7 @@ type UserStore interface {
GetAllUsers(ctx context.Context) ([]*user.User, error)
UserExists(ctx context.Context, username string) (bool, error)
UpdatePassword(ctx context.Context, id uuid.UUID, password string) (int64, error)
UpdateLastLogin(ctx context.Context, id uuid.UUID, lastLogin time.Time) (int64, error)
}
type PGUserStore struct {
@@ -123,3 +125,12 @@ func (s *PGUserStore) UpdatePassword(ctx context.Context, id uuid.UUID, password
return affected.RowsAffected(), nil
}
}
func (s *PGUserStore) UpdateLastLogin(ctx context.Context, id uuid.UUID, lastLogin time.Time) (int64, error) {
query := `UPDATE users SET last_login = $1 WHERE id = $2`
if affected, err := s.db.Exec(ctx, query, lastLogin, id); err != nil {
return 0, err
} else {
return affected.RowsAffected(), nil
}
}