Complete lab2 grade 4 implementation and report
Application checks / application (pull_request) Canceled after 0s
Skeleton contracts / contracts (pull_request) Canceled after 0s

This commit is contained in:
Daria0w0
2026-10-10 00:28:43 +03:00
parent 83e3810d33
commit c0ca56f208
24 changed files with 1107 additions and 137 deletions
+5 -6
View File
@@ -42,18 +42,17 @@ func (s *PostgresStore) CreateSession(ctx context.Context, hash []byte, userID s
func (s *PostgresStore) SessionUser(ctx context.Context, hash []byte) (model.User, error) {
ctx, cancel := context.WithTimeout(ctx, 3*time.Second)
defer cancel()
var user model.User
err := s.pool.QueryRow(ctx, `SELECT u.id::text, u.username, u.display_name, u.created_at
FROM sessions s JOIN users u ON u.id=s.user_id
WHERE s.token_hash=$1 AND s.expires_at > clock_timestamp()`, hash).Scan(&user.ID, &user.Username, &user.DisplayName, &user.CreatedAt)
var userID string
// Validate the session in the source of truth BEFORE consulting any cache.
err := s.pool.QueryRow(ctx, `SELECT user_id::text FROM sessions
WHERE token_hash=$1 AND expires_at > clock_timestamp()`, hash).Scan(&userID)
if errors.Is(err, pgx.ErrNoRows) {
return model.User{}, ErrSessionNotFound
}
if err != nil {
return model.User{}, ErrUnavailable
}
user.CreatedAt = user.CreatedAt.UTC()
return user, nil
return s.profile(ctx, userID)
}
func (s *PostgresStore) DeleteSession(ctx context.Context, hash []byte) error {