style: форматирование кода - убраны лишние пустые строки и исправлены импорты
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"erp-mvp/core-service/internal/models"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
@@ -32,7 +33,7 @@ func (r *locationRepository) Create(ctx context.Context, location *models.Storag
|
||||
INSERT INTO storage_locations (id, organization_id, parent_id, name, address, type, coordinates, created_at)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
||||
`
|
||||
|
||||
|
||||
// Конвертируем JSON в строку
|
||||
var coordinatesJSON string
|
||||
if location.Coordinates != nil {
|
||||
@@ -42,7 +43,7 @@ func (r *locationRepository) Create(ctx context.Context, location *models.Storag
|
||||
}
|
||||
coordinatesJSON = string(coords)
|
||||
}
|
||||
|
||||
|
||||
_, err := r.db.ExecContext(ctx, query,
|
||||
location.ID,
|
||||
location.OrganizationID,
|
||||
@@ -56,7 +57,7 @@ func (r *locationRepository) Create(ctx context.Context, location *models.Storag
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create storage location: %w", err)
|
||||
}
|
||||
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -66,7 +67,7 @@ func (r *locationRepository) GetByID(ctx context.Context, id uuid.UUID, orgID uu
|
||||
FROM storage_locations
|
||||
WHERE id = $1 AND organization_id = $2
|
||||
`
|
||||
|
||||
|
||||
var coordinatesJSON []byte
|
||||
location := &models.StorageLocation{}
|
||||
err := r.db.QueryRowContext(ctx, query, id, orgID).Scan(
|
||||
@@ -79,14 +80,14 @@ func (r *locationRepository) GetByID(ctx context.Context, id uuid.UUID, orgID uu
|
||||
&coordinatesJSON,
|
||||
&location.CreatedAt,
|
||||
)
|
||||
|
||||
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, fmt.Errorf("storage location not found")
|
||||
}
|
||||
return nil, fmt.Errorf("failed to get storage location: %w", err)
|
||||
}
|
||||
|
||||
|
||||
// Конвертируем JSON строку в map
|
||||
if len(coordinatesJSON) > 0 {
|
||||
err = json.Unmarshal(coordinatesJSON, &location.Coordinates)
|
||||
@@ -96,7 +97,7 @@ func (r *locationRepository) GetByID(ctx context.Context, id uuid.UUID, orgID uu
|
||||
} else {
|
||||
location.Coordinates = make(models.JSON)
|
||||
}
|
||||
|
||||
|
||||
return location, nil
|
||||
}
|
||||
|
||||
@@ -107,13 +108,13 @@ func (r *locationRepository) GetByOrganization(ctx context.Context, orgID uuid.U
|
||||
WHERE organization_id = $1
|
||||
ORDER BY name
|
||||
`
|
||||
|
||||
|
||||
rows, err := r.db.QueryContext(ctx, query, orgID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to query storage locations: %w", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
|
||||
var locations []*models.StorageLocation
|
||||
for rows.Next() {
|
||||
var coordinatesJSON []byte
|
||||
@@ -131,7 +132,7 @@ func (r *locationRepository) GetByOrganization(ctx context.Context, orgID uuid.U
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to scan storage location: %w", err)
|
||||
}
|
||||
|
||||
|
||||
// Конвертируем JSON строку в map
|
||||
if len(coordinatesJSON) > 0 {
|
||||
err = json.Unmarshal(coordinatesJSON, &location.Coordinates)
|
||||
@@ -141,14 +142,14 @@ func (r *locationRepository) GetByOrganization(ctx context.Context, orgID uuid.U
|
||||
} else {
|
||||
location.Coordinates = make(models.JSON)
|
||||
}
|
||||
|
||||
|
||||
locations = append(locations, location)
|
||||
}
|
||||
|
||||
|
||||
if err = rows.Err(); err != nil {
|
||||
return nil, fmt.Errorf("error iterating storage locations: %w", err)
|
||||
}
|
||||
|
||||
|
||||
return locations, nil
|
||||
}
|
||||
|
||||
@@ -158,7 +159,7 @@ func (r *locationRepository) Update(ctx context.Context, location *models.Storag
|
||||
SET parent_id = $3, name = $4, address = $5, type = $6, coordinates = $7
|
||||
WHERE id = $1 AND organization_id = $2
|
||||
`
|
||||
|
||||
|
||||
// Конвертируем JSON в строку
|
||||
var coordinatesJSON string
|
||||
if location.Coordinates != nil {
|
||||
@@ -168,7 +169,7 @@ func (r *locationRepository) Update(ctx context.Context, location *models.Storag
|
||||
}
|
||||
coordinatesJSON = string(coords)
|
||||
}
|
||||
|
||||
|
||||
result, err := r.db.ExecContext(ctx, query,
|
||||
location.ID,
|
||||
location.OrganizationID,
|
||||
@@ -181,16 +182,16 @@ func (r *locationRepository) Update(ctx context.Context, location *models.Storag
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to update storage location: %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("storage location not found")
|
||||
}
|
||||
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -199,21 +200,21 @@ func (r *locationRepository) Delete(ctx context.Context, id uuid.UUID, orgID uui
|
||||
DELETE FROM storage_locations
|
||||
WHERE id = $1 AND organization_id = $2
|
||||
`
|
||||
|
||||
|
||||
result, err := r.db.ExecContext(ctx, query, id, orgID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to delete storage location: %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("storage location not found")
|
||||
}
|
||||
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -224,13 +225,13 @@ func (r *locationRepository) GetChildren(ctx context.Context, parentID uuid.UUID
|
||||
WHERE parent_id = $1 AND organization_id = $2
|
||||
ORDER BY name
|
||||
`
|
||||
|
||||
|
||||
rows, err := r.db.QueryContext(ctx, query, parentID, orgID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to query child locations: %w", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
|
||||
var locations []*models.StorageLocation
|
||||
for rows.Next() {
|
||||
var coordinatesJSON []byte
|
||||
@@ -248,7 +249,7 @@ func (r *locationRepository) GetChildren(ctx context.Context, parentID uuid.UUID
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to scan child location: %w", err)
|
||||
}
|
||||
|
||||
|
||||
// Конвертируем JSON строку в map
|
||||
if len(coordinatesJSON) > 0 {
|
||||
err = json.Unmarshal(coordinatesJSON, &location.Coordinates)
|
||||
@@ -258,13 +259,13 @@ func (r *locationRepository) GetChildren(ctx context.Context, parentID uuid.UUID
|
||||
} else {
|
||||
location.Coordinates = make(models.JSON)
|
||||
}
|
||||
|
||||
|
||||
locations = append(locations, location)
|
||||
}
|
||||
|
||||
|
||||
if err = rows.Err(); err != nil {
|
||||
return nil, fmt.Errorf("error iterating child locations: %w", err)
|
||||
}
|
||||
|
||||
|
||||
return locations, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user