v0.0.12 Добавлен avatar для пользователей, а также реализован резолвер получения всех пользователей
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
madipo2611 2025-08-05 11:13:58 +03:00
parent 0a7531bc1b
commit d0ff0eeadf
3 changed files with 10 additions and 7 deletions

View File

@ -112,7 +112,9 @@ func (r *mutationResolver) Login(ctx context.Context, input domain.LoginInput) (
// Users is the resolver for the users field. // Users is the resolver for the users field.
func (r *queryResolver) Users(ctx context.Context) ([]*domain.User, error) { 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 { if err != nil {
return nil, fmt.Errorf("failed to get users: %w", err) return nil, fmt.Errorf("failed to get users: %w", err)
} }

View File

@ -15,7 +15,7 @@ var (
type UserRepository interface { type UserRepository interface {
Create(ctx context.Context, user *domain.User) error Create(ctx context.Context, user *domain.User) error
GetByID(ctx context.Context, id int) (*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) GetByEmail(ctx context.Context, email string) (*domain.User, error)
GetByConfirmationToken(ctx context.Context, token string) (*domain.User, error) GetByConfirmationToken(ctx context.Context, token string) (*domain.User, error)
Update(ctx context.Context, user *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 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 := ` query := `
SELECT id, username, avatar SELECT id, username, avatar
FROM users FROM users
WHERE id != $1
` `
rows, err := r.db.QueryContext(ctx, query) rows, err := r.db.QueryContext(ctx, query, id)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -11,7 +11,7 @@ import (
type UserService interface { type UserService interface {
GetByID(ctx context.Context, id int) (*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) GetByEmail(ctx context.Context, email string) (*domain.User, error)
UpdateProfile(ctx context.Context, id int, username, email, avatar 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 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) return s.userRepo.Update(ctx, user)
} }
func (s *userService) GetAll(ctx context.Context) ([]*domain.User, error) { func (s *userService) GetAll(ctx context.Context, id int) ([]*domain.User, error) {
users, err := s.userRepo.GetAll(ctx) users, err := s.userRepo.GetAll(ctx, id)
if err != nil { if err != nil {
return nil, err return nil, err
} }