diff --git a/internal/http/graph/user_resolvers.go b/internal/http/graph/user_resolvers.go index 3806a73..5b9d748 100644 --- a/internal/http/graph/user_resolvers.go +++ b/internal/http/graph/user_resolvers.go @@ -112,7 +112,9 @@ func (r *mutationResolver) Login(ctx context.Context, input domain.LoginInput) ( // Users is the resolver for the users field. func (r *queryResolver) Users(ctx context.Context) ([]*domain.User, error) { - users, err := r.Services.User.GetAll(ctx) + userID, err := getUserIDFromContext(ctx) + + users, err := r.Services.User.GetAll(ctx, userID) if err != nil { return nil, fmt.Errorf("failed to get users: %w", err) } diff --git a/internal/repository/user_repository.go b/internal/repository/user_repository.go index 4949b2a..52e8086 100644 --- a/internal/repository/user_repository.go +++ b/internal/repository/user_repository.go @@ -15,7 +15,7 @@ var ( type UserRepository interface { Create(ctx context.Context, user *domain.User) error GetByID(ctx context.Context, id int) (*domain.User, error) - GetAll(ctx context.Context) ([]*domain.User, error) + GetAll(ctx context.Context, id int) ([]*domain.User, error) GetByEmail(ctx context.Context, email string) (*domain.User, error) GetByConfirmationToken(ctx context.Context, token string) (*domain.User, error) Update(ctx context.Context, user *domain.User) error @@ -188,13 +188,14 @@ func (r *userRepository) Delete(ctx context.Context, id int) error { return err } -func (r *userRepository) GetAll(ctx context.Context) ([]*domain.User, error) { +func (r *userRepository) GetAll(ctx context.Context, id int) ([]*domain.User, error) { query := ` SELECT id, username, avatar FROM users + WHERE id != $1 ` - rows, err := r.db.QueryContext(ctx, query) + rows, err := r.db.QueryContext(ctx, query, id) if err != nil { return nil, err } diff --git a/internal/service/user_service.go b/internal/service/user_service.go index ee86cdd..b02152c 100644 --- a/internal/service/user_service.go +++ b/internal/service/user_service.go @@ -11,7 +11,7 @@ import ( type UserService interface { GetByID(ctx context.Context, id int) (*domain.User, error) - GetAll(ctx context.Context) ([]*domain.User, error) + GetAll(ctx context.Context, id int) ([]*domain.User, error) GetByEmail(ctx context.Context, email string) (*domain.User, error) UpdateProfile(ctx context.Context, id int, username, email, avatar string) (*domain.User, error) ChangePassword(ctx context.Context, id int, oldPassword, newPassword string) error @@ -99,8 +99,8 @@ func (s *userService) ChangePassword(ctx context.Context, id int, oldPassword, n return s.userRepo.Update(ctx, user) } -func (s *userService) GetAll(ctx context.Context) ([]*domain.User, error) { - users, err := s.userRepo.GetAll(ctx) +func (s *userService) GetAll(ctx context.Context, id int) ([]*domain.User, error) { + users, err := s.userRepo.GetAll(ctx, id) if err != nil { return nil, err }