From 0f93308c6517c6beb75da036584fa05eadec5ec9 Mon Sep 17 00:00:00 2001 From: Andrey Epifantsev Date: Wed, 27 Aug 2025 15:05:25 +0400 Subject: [PATCH] =?UTF-8?q?style:=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=82?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=B4=D0=B0=20-=20=D1=83=D0=B1=D1=80=D0=B0=D0=BD=D1=8B=20?= =?UTF-8?q?=D0=BB=D0=B8=D1=88=D0=BD=D0=B8=D0=B5=20=D0=BF=D1=83=D1=81=D1=82?= =?UTF-8?q?=D1=8B=D0=B5=20=D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core-service/internal/models/models.go | 6 ++--- .../internal/repository/organizations.go | 25 ++++++++++--------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/core-service/internal/models/models.go b/core-service/internal/models/models.go index 32f4cba..75ee9f3 100644 --- a/core-service/internal/models/models.go +++ b/core-service/internal/models/models.go @@ -90,9 +90,9 @@ type OrganizationResponse struct { // LoginResponse ответ на аутентификацию type LoginResponse struct { - Token string `json:"token"` - User UserResponse `json:"user"` - Organization OrganizationResponse `json:"organization"` + Token string `json:"token"` + User UserResponse `json:"user"` + Organization OrganizationResponse `json:"organization"` } // CreateLocationRequest запрос на создание места хранения diff --git a/core-service/internal/repository/organizations.go b/core-service/internal/repository/organizations.go index 73191f6..1e8c033 100644 --- a/core-service/internal/repository/organizations.go +++ b/core-service/internal/repository/organizations.go @@ -7,6 +7,7 @@ import ( "fmt" "erp-mvp/core-service/internal/models" + "github.com/google/uuid" ) @@ -29,18 +30,18 @@ func (r *organizationRepository) Create(ctx context.Context, org *models.Organiz INSERT INTO organizations (id, name, type, settings, created_at) VALUES ($1, $2, $3, $4, $5) ` - + // Конвертируем JSON в строку settingsJSON, err := json.Marshal(org.Settings) if err != nil { return fmt.Errorf("failed to marshal settings: %w", err) } - + _, err = r.db.ExecContext(ctx, query, org.ID, org.Name, org.Type, string(settingsJSON), org.CreatedAt) if err != nil { return fmt.Errorf("failed to create organization: %w", err) } - + return nil } @@ -50,7 +51,7 @@ func (r *organizationRepository) GetByID(ctx context.Context, id uuid.UUID) (*mo FROM organizations WHERE id = $1 ` - + var settingsJSON []byte org := &models.Organization{} err := r.db.QueryRowContext(ctx, query, id).Scan( @@ -60,14 +61,14 @@ func (r *organizationRepository) GetByID(ctx context.Context, id uuid.UUID) (*mo &settingsJSON, &org.CreatedAt, ) - + if err != nil { if err == sql.ErrNoRows { return nil, fmt.Errorf("organization not found") } return nil, fmt.Errorf("failed to get organization: %w", err) } - + // Конвертируем JSON строку в map if len(settingsJSON) > 0 { err = json.Unmarshal(settingsJSON, &org.Settings) @@ -77,7 +78,7 @@ func (r *organizationRepository) GetByID(ctx context.Context, id uuid.UUID) (*mo } else { org.Settings = make(models.JSON) } - + return org, nil } @@ -87,26 +88,26 @@ func (r *organizationRepository) Update(ctx context.Context, org *models.Organiz SET name = $2, type = $3, settings = $4 WHERE id = $1 ` - + // Конвертируем JSON в строку settingsJSON, err := json.Marshal(org.Settings) if err != nil { return fmt.Errorf("failed to marshal settings: %w", err) } - + result, err := r.db.ExecContext(ctx, query, org.ID, org.Name, org.Type, string(settingsJSON)) if err != nil { return fmt.Errorf("failed to update organization: %w", err) } - + rowsAffected, err := result.RowsAffected() if err != nil { return fmt.Errorf("failed to get rows affected: %w", err) } - + if rowsAffected == 0 { return fmt.Errorf("organization not found") } - + return nil }