style: форматирование кода - убраны лишние пустые строки и исправлены импорты
This commit is contained in:
@@ -34,7 +34,7 @@ func NewItemService(itemRepo repository.ItemRepository) ItemService {
|
||||
|
||||
func (s *itemService) CreateItem(ctx context.Context, orgID uuid.UUID, req *models.CreateItemRequest) (*models.Item, error) {
|
||||
s.logger.Info("Creating item for organization: ", orgID)
|
||||
|
||||
|
||||
item := &models.Item{
|
||||
ID: uuid.New(),
|
||||
OrganizationID: orgID,
|
||||
@@ -43,84 +43,84 @@ func (s *itemService) CreateItem(ctx context.Context, orgID uuid.UUID, req *mode
|
||||
Category: req.Category,
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
|
||||
|
||||
if err := s.itemRepo.Create(ctx, item); err != nil {
|
||||
s.logger.Error("Failed to create item: ", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
s.logger.Info("Item created successfully: ", item.ID)
|
||||
return item, nil
|
||||
}
|
||||
|
||||
func (s *itemService) GetItem(ctx context.Context, id uuid.UUID, orgID uuid.UUID) (*models.Item, error) {
|
||||
s.logger.Info("Getting item: ", id, " for organization: ", orgID)
|
||||
|
||||
|
||||
item, err := s.itemRepo.GetByID(ctx, id, orgID)
|
||||
if err != nil {
|
||||
s.logger.Error("Failed to get item: ", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
return item, nil
|
||||
}
|
||||
|
||||
func (s *itemService) GetItems(ctx context.Context, orgID uuid.UUID) ([]*models.Item, error) {
|
||||
s.logger.Info("Getting all items for organization: ", orgID)
|
||||
|
||||
|
||||
items, err := s.itemRepo.GetByOrganization(ctx, orgID)
|
||||
if err != nil {
|
||||
s.logger.Error("Failed to get items: ", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
return items, nil
|
||||
}
|
||||
|
||||
func (s *itemService) UpdateItem(ctx context.Context, id uuid.UUID, orgID uuid.UUID, req *models.CreateItemRequest) (*models.Item, error) {
|
||||
s.logger.Info("Updating item: ", id, " for organization: ", orgID)
|
||||
|
||||
|
||||
// Сначала получаем существующий товар
|
||||
item, err := s.itemRepo.GetByID(ctx, id, orgID)
|
||||
if err != nil {
|
||||
s.logger.Error("Failed to get item for update: ", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
// Обновляем поля
|
||||
item.Name = req.Name
|
||||
item.Description = req.Description
|
||||
item.Category = req.Category
|
||||
|
||||
|
||||
if err := s.itemRepo.Update(ctx, item); err != nil {
|
||||
s.logger.Error("Failed to update item: ", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
s.logger.Info("Item updated successfully: ", item.ID)
|
||||
return item, nil
|
||||
}
|
||||
|
||||
func (s *itemService) DeleteItem(ctx context.Context, id uuid.UUID, orgID uuid.UUID) error {
|
||||
s.logger.Info("Deleting item: ", id, " for organization: ", orgID)
|
||||
|
||||
|
||||
if err := s.itemRepo.Delete(ctx, id, orgID); err != nil {
|
||||
s.logger.Error("Failed to delete item: ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
s.logger.Info("Item deleted successfully: ", id)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *itemService) SearchItems(ctx context.Context, orgID uuid.UUID, query string, category string) ([]*models.Item, error) {
|
||||
s.logger.Info("Searching items for organization: ", orgID, " query: ", query, " category: ", category)
|
||||
|
||||
|
||||
items, err := s.itemRepo.Search(ctx, orgID, query, category)
|
||||
if err != nil {
|
||||
s.logger.Error("Failed to search items: ", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
return items, nil
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ func NewLocationService(locationRepo repository.LocationRepository) LocationServ
|
||||
|
||||
func (s *locationService) CreateLocation(ctx context.Context, orgID uuid.UUID, req *models.CreateLocationRequest) (*models.StorageLocation, error) {
|
||||
s.logger.Info("Creating location for organization: ", orgID)
|
||||
|
||||
|
||||
location := &models.StorageLocation{
|
||||
ID: uuid.New(),
|
||||
OrganizationID: orgID,
|
||||
@@ -45,86 +45,86 @@ func (s *locationService) CreateLocation(ctx context.Context, orgID uuid.UUID, r
|
||||
Coordinates: req.Coordinates,
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
|
||||
|
||||
if err := s.locationRepo.Create(ctx, location); err != nil {
|
||||
s.logger.Error("Failed to create location: ", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
s.logger.Info("Location created successfully: ", location.ID)
|
||||
return location, nil
|
||||
}
|
||||
|
||||
func (s *locationService) GetLocation(ctx context.Context, id uuid.UUID, orgID uuid.UUID) (*models.StorageLocation, error) {
|
||||
s.logger.Info("Getting location: ", id, " for organization: ", orgID)
|
||||
|
||||
|
||||
location, err := s.locationRepo.GetByID(ctx, id, orgID)
|
||||
if err != nil {
|
||||
s.logger.Error("Failed to get location: ", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
return location, nil
|
||||
}
|
||||
|
||||
func (s *locationService) GetLocations(ctx context.Context, orgID uuid.UUID) ([]*models.StorageLocation, error) {
|
||||
s.logger.Info("Getting all locations for organization: ", orgID)
|
||||
|
||||
|
||||
locations, err := s.locationRepo.GetByOrganization(ctx, orgID)
|
||||
if err != nil {
|
||||
s.logger.Error("Failed to get locations: ", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
return locations, nil
|
||||
}
|
||||
|
||||
func (s *locationService) UpdateLocation(ctx context.Context, id uuid.UUID, orgID uuid.UUID, req *models.CreateLocationRequest) (*models.StorageLocation, error) {
|
||||
s.logger.Info("Updating location: ", id, " for organization: ", orgID)
|
||||
|
||||
|
||||
// Сначала получаем существующую локацию
|
||||
location, err := s.locationRepo.GetByID(ctx, id, orgID)
|
||||
if err != nil {
|
||||
s.logger.Error("Failed to get location for update: ", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
// Обновляем поля
|
||||
location.ParentID = req.ParentID
|
||||
location.Name = req.Name
|
||||
location.Address = req.Address
|
||||
location.Type = req.Type
|
||||
location.Coordinates = req.Coordinates
|
||||
|
||||
|
||||
if err := s.locationRepo.Update(ctx, location); err != nil {
|
||||
s.logger.Error("Failed to update location: ", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
s.logger.Info("Location updated successfully: ", location.ID)
|
||||
return location, nil
|
||||
}
|
||||
|
||||
func (s *locationService) DeleteLocation(ctx context.Context, id uuid.UUID, orgID uuid.UUID) error {
|
||||
s.logger.Info("Deleting location: ", id, " for organization: ", orgID)
|
||||
|
||||
|
||||
if err := s.locationRepo.Delete(ctx, id, orgID); err != nil {
|
||||
s.logger.Error("Failed to delete location: ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
s.logger.Info("Location deleted successfully: ", id)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *locationService) GetChildren(ctx context.Context, parentID uuid.UUID, orgID uuid.UUID) ([]*models.StorageLocation, error) {
|
||||
s.logger.Info("Getting children for location: ", parentID, " in organization: ", orgID)
|
||||
|
||||
|
||||
children, err := s.locationRepo.GetChildren(ctx, parentID, orgID)
|
||||
if err != nil {
|
||||
s.logger.Error("Failed to get children: ", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
return children, nil
|
||||
}
|
||||
|
||||
@@ -39,21 +39,21 @@ func NewOperationsService(operationsRepo repository.OperationsRepository, itemRe
|
||||
|
||||
func (s *operationsService) PlaceItem(ctx context.Context, orgID uuid.UUID, req *models.PlaceItemRequest) (*models.ItemPlacement, error) {
|
||||
s.logger.Info("Placing item: ", req.ItemID, " in location: ", req.LocationID, " for organization: ", orgID)
|
||||
|
||||
|
||||
// Проверяем, что товар существует и принадлежит организации
|
||||
_, err := s.itemRepo.GetByID(ctx, req.ItemID, orgID)
|
||||
if err != nil {
|
||||
s.logger.Error("Item not found or not accessible: ", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
// Проверяем, что место хранения существует и принадлежит организации
|
||||
_, err = s.locationRepo.GetByID(ctx, req.LocationID, orgID)
|
||||
if err != nil {
|
||||
s.logger.Error("Location not found or not accessible: ", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
placement := &models.ItemPlacement{
|
||||
ID: uuid.New(),
|
||||
OrganizationID: orgID,
|
||||
@@ -62,131 +62,131 @@ func (s *operationsService) PlaceItem(ctx context.Context, orgID uuid.UUID, req
|
||||
Quantity: req.Quantity,
|
||||
CreatedAt: time.Now(),
|
||||
}
|
||||
|
||||
|
||||
if err := s.operationsRepo.PlaceItem(ctx, placement); err != nil {
|
||||
s.logger.Error("Failed to place item: ", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
s.logger.Info("Item placed successfully: ", placement.ID)
|
||||
return placement, nil
|
||||
}
|
||||
|
||||
func (s *operationsService) MoveItem(ctx context.Context, placementID uuid.UUID, newLocationID uuid.UUID, orgID uuid.UUID) error {
|
||||
s.logger.Info("Moving item placement: ", placementID, " to location: ", newLocationID, " for organization: ", orgID)
|
||||
|
||||
|
||||
// Проверяем, что размещение существует и принадлежит организации
|
||||
placement, err := s.operationsRepo.GetByID(ctx, placementID, orgID)
|
||||
if err != nil {
|
||||
s.logger.Error("Item placement not found or not accessible: ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
// Проверяем, что новое место хранения существует и принадлежит организации
|
||||
_, err = s.locationRepo.GetByID(ctx, newLocationID, orgID)
|
||||
if err != nil {
|
||||
s.logger.Error("New location not found or not accessible: ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
if err := s.operationsRepo.MoveItem(ctx, placementID, newLocationID, orgID); err != nil {
|
||||
s.logger.Error("Failed to move item: ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
s.logger.Info("Item moved successfully from location: ", placement.LocationID, " to: ", newLocationID)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *operationsService) GetItemPlacements(ctx context.Context, itemID uuid.UUID, orgID uuid.UUID) ([]*models.ItemPlacement, error) {
|
||||
s.logger.Info("Getting placements for item: ", itemID, " in organization: ", orgID)
|
||||
|
||||
|
||||
// Проверяем, что товар существует и принадлежит организации
|
||||
_, err := s.itemRepo.GetByID(ctx, itemID, orgID)
|
||||
if err != nil {
|
||||
s.logger.Error("Item not found or not accessible: ", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
placements, err := s.operationsRepo.GetByItem(ctx, itemID, orgID)
|
||||
if err != nil {
|
||||
s.logger.Error("Failed to get item placements: ", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
return placements, nil
|
||||
}
|
||||
|
||||
func (s *operationsService) GetLocationPlacements(ctx context.Context, locationID uuid.UUID, orgID uuid.UUID) ([]*models.ItemPlacement, error) {
|
||||
s.logger.Info("Getting placements for location: ", locationID, " in organization: ", orgID)
|
||||
|
||||
|
||||
// Проверяем, что место хранения существует и принадлежит организации
|
||||
_, err := s.locationRepo.GetByID(ctx, locationID, orgID)
|
||||
if err != nil {
|
||||
s.logger.Error("Location not found or not accessible: ", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
placements, err := s.operationsRepo.GetByLocation(ctx, locationID, orgID)
|
||||
if err != nil {
|
||||
s.logger.Error("Failed to get location placements: ", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
return placements, nil
|
||||
}
|
||||
|
||||
func (s *operationsService) UpdateQuantity(ctx context.Context, placementID uuid.UUID, quantity int, orgID uuid.UUID) error {
|
||||
s.logger.Info("Updating quantity for placement: ", placementID, " to: ", quantity, " in organization: ", orgID)
|
||||
|
||||
|
||||
// Проверяем, что размещение существует и принадлежит организации
|
||||
_, err := s.operationsRepo.GetByID(ctx, placementID, orgID)
|
||||
if err != nil {
|
||||
s.logger.Error("Item placement not found or not accessible: ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
if err := s.operationsRepo.UpdateQuantity(ctx, placementID, quantity, orgID); err != nil {
|
||||
s.logger.Error("Failed to update quantity: ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
s.logger.Info("Quantity updated successfully for placement: ", placementID)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *operationsService) DeletePlacement(ctx context.Context, placementID uuid.UUID, orgID uuid.UUID) error {
|
||||
s.logger.Info("Deleting placement: ", placementID, " for organization: ", orgID)
|
||||
|
||||
|
||||
// Проверяем, что размещение существует и принадлежит организации
|
||||
_, err := s.operationsRepo.GetByID(ctx, placementID, orgID)
|
||||
if err != nil {
|
||||
s.logger.Error("Item placement not found or not accessible: ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
if err := s.operationsRepo.Delete(ctx, placementID, orgID); err != nil {
|
||||
s.logger.Error("Failed to delete placement: ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
s.logger.Info("Placement deleted successfully: ", placementID)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *operationsService) Search(ctx context.Context, orgID uuid.UUID, req *models.SearchRequest) (*models.SearchResponse, error) {
|
||||
s.logger.Info("Searching items with locations for organization: ", orgID, " query: ", req.Query)
|
||||
|
||||
|
||||
results, err := s.operationsRepo.Search(ctx, orgID, req.Query, req.Category, req.Address)
|
||||
if err != nil {
|
||||
s.logger.Error("Failed to search items with locations: ", err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
||||
response := &models.SearchResponse{
|
||||
Items: results,
|
||||
TotalCount: len(results),
|
||||
}
|
||||
|
||||
|
||||
return response, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user