v0.0.12 Добавлен avatar для пользователей, а также реализован резолвер получения всех пользователей
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
0a7531bc1b
commit
d0ff0eeadf
@ -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)
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user