Complete lab2 grade 4 implementation and report
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user