From 91ce0699381f2dad21432174259a09fd642a4a3d Mon Sep 17 00:00:00 2001 From: Kosmatoff Date: Mon, 25 Dec 2023 01:26:31 +0300 Subject: [PATCH] deploy --- .../microservices/transaction/delivery/http/handlers.go | 2 +- .../microservices/user/repository/postgresql/postgres.go | 8 ++++---- internal/microservices/user/usecase/user_usecase.go | 2 +- internal/microservices/user/user.go | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/microservices/transaction/delivery/http/handlers.go b/internal/microservices/transaction/delivery/http/handlers.go index 16305c1..7d88dce 100644 --- a/internal/microservices/transaction/delivery/http/handlers.go +++ b/internal/microservices/transaction/delivery/http/handlers.go @@ -119,7 +119,7 @@ func (h *Handler) GetFeed(w http.ResponseWriter, r *http.Request) { var dataResponse []models.TransactionTransfer - var userT models.User + var userT *models.User for _, transaction := range dataFeed { userT, err = h.userService.GetUser(r.Context(), transaction.UserID) dataResponse = append(dataResponse, models.InitTransactionTransfer(transaction, userT.Login)) diff --git a/internal/microservices/user/repository/postgresql/postgres.go b/internal/microservices/user/repository/postgresql/postgres.go index c5a639c..7628f5b 100644 --- a/internal/microservices/user/repository/postgresql/postgres.go +++ b/internal/microservices/user/repository/postgresql/postgres.go @@ -72,19 +72,19 @@ func (r *UserRep) CreateUser(ctx context.Context, u models.User) (uuid.UUID, err return id, nil } -func (r *UserRep) GetByID(ctx context.Context, userID uuid.UUID) (models.User, error) { +func (r *UserRep) GetByID(ctx context.Context, userID uuid.UUID) (*models.User, error) { row := r.db.QueryRow(ctx, UserIDGetByID, userID) var u models.User err := row.Scan(&u.ID, &u.Login, &u.Username, &u.Password, &u.PlannedBudget, &u.AvatarURL) if errors.Is(err, sql.ErrNoRows) { - return u, fmt.Errorf("[repo] %w: %v", &models.NoSuchUserError{UserID: userID}, err) + return nil, fmt.Errorf("[repo] %w: %v", &models.NoSuchUserError{UserID: userID}, err) } else if err != nil { - return u, + return nil, fmt.Errorf("failed request db %s, %w", UserIDGetByID, err) } - return u, nil + return nil, nil } func (r *UserRep) GetUserByLogin(ctx context.Context, login string) (*models.User, error) { diff --git a/internal/microservices/user/usecase/user_usecase.go b/internal/microservices/user/usecase/user_usecase.go index 57b3a66..c7fa073 100644 --- a/internal/microservices/user/usecase/user_usecase.go +++ b/internal/microservices/user/usecase/user_usecase.go @@ -30,7 +30,7 @@ func NewUsecase( } } -func (u *Usecase) GetUser(ctx context.Context, userID uuid.UUID) (models.User, error) { // need test +func (u *Usecase) GetUser(ctx context.Context, userID uuid.UUID) (*models.User, error) { // need test user, err := u.userRepo.GetByID(ctx, userID) if err != nil { return user, fmt.Errorf("[usecase] can't get user from repository %w", err) diff --git a/internal/microservices/user/user.go b/internal/microservices/user/user.go index 9d05464..acf6eee 100644 --- a/internal/microservices/user/user.go +++ b/internal/microservices/user/user.go @@ -16,7 +16,7 @@ type Usecase interface { GetCurrentBudget(ctx context.Context, userID uuid.UUID) (float64, error) GetAccounts(ctx context.Context, userID uuid.UUID) ([]models.Accounts, error) GetFeed(ctx context.Context, userID uuid.UUID) (*transfer_models.UserFeed, error) - GetUser(ctx context.Context, userID uuid.UUID) (models.User, error) + GetUser(ctx context.Context, userID uuid.UUID) (*models.User, error) UpdateUser(ctx context.Context, user *models.User) error UpdatePhoto(ctx context.Context, usserID uuid.UUID) (uuid.UUID, error) AddUserInAccount(ctx context.Context, accountInput models.AddUserAccount, adminID uuid.UUID) error @@ -25,7 +25,7 @@ type Usecase interface { } type Repository interface { - GetByID(ctx context.Context, userID uuid.UUID) (models.User, error) + GetByID(ctx context.Context, userID uuid.UUID) (*models.User, error) CreateUser(ctx context.Context, user models.User) (uuid.UUID, error) // IncreaseUserVersion(ctx context.Context, ctx context.Context, userID uuid.UUID) error GetUserByLogin(ctx context.Context, login string) (*models.User, error)