feat: add /api/user/me endpoint for session restoration
This commit is contained in:
@@ -227,3 +227,24 @@ func (r *UserRepository) UpdateUserRole(ctx context.Context, userID int, newRole
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetUserByID находит пользователя по его ID.
|
||||
func (r *UserRepository) GetUserByID(ctx context.Context, userID int) (*models.User, error) {
|
||||
user := &models.User{}
|
||||
var userUUID string
|
||||
|
||||
query := "SELECT id, uuid, username, email, password_hash, role, created_at, updated_at FROM users WHERE id = $1"
|
||||
err := r.DB.QueryRow(ctx, query, userID).Scan(
|
||||
&user.ID, &userUUID, &user.Username, &user.Email, &user.PasswordHash, &user.Role, &user.CreatedAt, &user.UpdatedAt,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return nil, ErrUserNotFound
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
user.UUID, _ = uuid.Parse(userUUID)
|
||||
return user, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user