style: форматирование кода - убраны лишние пустые строки и исправлены импорты
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"erp-mvp/core-service/internal/models"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
@@ -34,7 +35,7 @@ func (r *operationsRepository) PlaceItem(ctx context.Context, placement *models.
|
||||
INSERT INTO item_placements (id, organization_id, item_id, location_id, quantity, created_at)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
`
|
||||
|
||||
|
||||
_, err := r.db.ExecContext(ctx, query,
|
||||
placement.ID,
|
||||
placement.OrganizationID,
|
||||
@@ -46,7 +47,7 @@ func (r *operationsRepository) PlaceItem(ctx context.Context, placement *models.
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to place item: %w", err)
|
||||
}
|
||||
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -56,21 +57,21 @@ func (r *operationsRepository) MoveItem(ctx context.Context, placementID uuid.UU
|
||||
SET location_id = $2
|
||||
WHERE id = $1 AND organization_id = $3
|
||||
`
|
||||
|
||||
|
||||
result, err := r.db.ExecContext(ctx, query, placementID, newLocationID, orgID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to move item: %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("item placement not found")
|
||||
}
|
||||
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -81,13 +82,13 @@ func (r *operationsRepository) GetByItem(ctx context.Context, itemID uuid.UUID,
|
||||
WHERE item_id = $1 AND organization_id = $2
|
||||
ORDER BY created_at DESC
|
||||
`
|
||||
|
||||
|
||||
rows, err := r.db.QueryContext(ctx, query, itemID, orgID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to query item placements: %w", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
|
||||
var placements []*models.ItemPlacement
|
||||
for rows.Next() {
|
||||
placement := &models.ItemPlacement{}
|
||||
@@ -102,14 +103,14 @@ func (r *operationsRepository) GetByItem(ctx context.Context, itemID uuid.UUID,
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to scan item placement: %w", err)
|
||||
}
|
||||
|
||||
|
||||
placements = append(placements, placement)
|
||||
}
|
||||
|
||||
|
||||
if err = rows.Err(); err != nil {
|
||||
return nil, fmt.Errorf("error iterating item placements: %w", err)
|
||||
}
|
||||
|
||||
|
||||
return placements, nil
|
||||
}
|
||||
|
||||
@@ -120,13 +121,13 @@ func (r *operationsRepository) GetByLocation(ctx context.Context, locationID uui
|
||||
WHERE location_id = $1 AND organization_id = $2
|
||||
ORDER BY created_at DESC
|
||||
`
|
||||
|
||||
|
||||
rows, err := r.db.QueryContext(ctx, query, locationID, orgID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to query location placements: %w", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
|
||||
var placements []*models.ItemPlacement
|
||||
for rows.Next() {
|
||||
placement := &models.ItemPlacement{}
|
||||
@@ -141,14 +142,14 @@ func (r *operationsRepository) GetByLocation(ctx context.Context, locationID uui
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to scan item placement: %w", err)
|
||||
}
|
||||
|
||||
|
||||
placements = append(placements, placement)
|
||||
}
|
||||
|
||||
|
||||
if err = rows.Err(); err != nil {
|
||||
return nil, fmt.Errorf("error iterating location placements: %w", err)
|
||||
}
|
||||
|
||||
|
||||
return placements, nil
|
||||
}
|
||||
|
||||
@@ -158,7 +159,7 @@ func (r *operationsRepository) GetByID(ctx context.Context, id uuid.UUID, orgID
|
||||
FROM item_placements
|
||||
WHERE id = $1 AND organization_id = $2
|
||||
`
|
||||
|
||||
|
||||
placement := &models.ItemPlacement{}
|
||||
err := r.db.QueryRowContext(ctx, query, id, orgID).Scan(
|
||||
&placement.ID,
|
||||
@@ -168,14 +169,14 @@ func (r *operationsRepository) GetByID(ctx context.Context, id uuid.UUID, orgID
|
||||
&placement.Quantity,
|
||||
&placement.CreatedAt,
|
||||
)
|
||||
|
||||
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, fmt.Errorf("item placement not found")
|
||||
}
|
||||
return nil, fmt.Errorf("failed to get item placement: %w", err)
|
||||
}
|
||||
|
||||
|
||||
return placement, nil
|
||||
}
|
||||
|
||||
@@ -185,21 +186,21 @@ func (r *operationsRepository) UpdateQuantity(ctx context.Context, id uuid.UUID,
|
||||
SET quantity = $2
|
||||
WHERE id = $1 AND organization_id = $3
|
||||
`
|
||||
|
||||
|
||||
result, err := r.db.ExecContext(ctx, query, id, quantity, orgID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to update quantity: %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("item placement not found")
|
||||
}
|
||||
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -208,21 +209,21 @@ func (r *operationsRepository) Delete(ctx context.Context, id uuid.UUID, orgID u
|
||||
DELETE FROM item_placements
|
||||
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 item placement: %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("item placement not found")
|
||||
}
|
||||
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -237,42 +238,42 @@ func (r *operationsRepository) Search(ctx context.Context, orgID uuid.UUID, quer
|
||||
JOIN storage_locations sl ON ip.location_id = sl.id
|
||||
WHERE i.organization_id = $1 AND sl.organization_id = $1
|
||||
`
|
||||
|
||||
|
||||
var args []interface{}
|
||||
args = append(args, orgID)
|
||||
argIndex := 2
|
||||
|
||||
|
||||
if query != "" {
|
||||
baseQuery += fmt.Sprintf(" AND (i.name ILIKE $%d OR i.description ILIKE $%d)", argIndex, argIndex)
|
||||
args = append(args, "%"+query+"%")
|
||||
argIndex++
|
||||
}
|
||||
|
||||
|
||||
if category != "" {
|
||||
baseQuery += fmt.Sprintf(" AND i.category = $%d", argIndex)
|
||||
args = append(args, category)
|
||||
argIndex++
|
||||
}
|
||||
|
||||
|
||||
if address != "" {
|
||||
baseQuery += fmt.Sprintf(" AND sl.address ILIKE $%d", argIndex)
|
||||
args = append(args, "%"+address+"%")
|
||||
argIndex++
|
||||
}
|
||||
|
||||
|
||||
baseQuery += " ORDER BY i.name, sl.name"
|
||||
|
||||
|
||||
rows, err := r.db.QueryContext(ctx, baseQuery, args...)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to search items with locations: %w", err)
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
|
||||
var results []*models.ItemWithLocation
|
||||
for rows.Next() {
|
||||
var coordinatesJSON []byte
|
||||
itemWithLocation := &models.ItemWithLocation{}
|
||||
|
||||
|
||||
err := rows.Scan(
|
||||
&itemWithLocation.Item.ID,
|
||||
&itemWithLocation.Item.OrganizationID,
|
||||
@@ -293,7 +294,7 @@ func (r *operationsRepository) Search(ctx context.Context, orgID uuid.UUID, quer
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to scan item with location: %w", err)
|
||||
}
|
||||
|
||||
|
||||
// Конвертируем JSON строку в map
|
||||
if len(coordinatesJSON) > 0 {
|
||||
err = json.Unmarshal(coordinatesJSON, &itemWithLocation.Location.Coordinates)
|
||||
@@ -303,13 +304,13 @@ func (r *operationsRepository) Search(ctx context.Context, orgID uuid.UUID, quer
|
||||
} else {
|
||||
itemWithLocation.Location.Coordinates = make(models.JSON)
|
||||
}
|
||||
|
||||
|
||||
results = append(results, itemWithLocation)
|
||||
}
|
||||
|
||||
|
||||
if err = rows.Err(); err != nil {
|
||||
return nil, fmt.Errorf("error iterating search results: %w", err)
|
||||
}
|
||||
|
||||
|
||||
return results, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user