Documentation
¶
Index ¶
- func Migrate(db *gorm.DB) error
- type StorageService
- func (s *StorageService) CreateLocation(data *models.LocationPointModel, warehouse *models.WarehouseModel) error
- func (s *StorageService) CreateWarehouse(data *models.WarehouseModel, lat, lng *float64) error
- func (s *StorageService) DeleteWarehouse(id string) error
- func (s *StorageService) DeleteWarehouseLocation(id string) error
- func (s *StorageService) GetWarehouseLocationByID(id string) (*models.LocationPointModel, error)
- func (s *StorageService) GetWarehouseLocations(request http.Request, search string) (paginate.Page, error)
- func (s *StorageService) GetWarehouses(request http.Request, search string) (paginate.Page, error)
- func (s *StorageService) UpdateWarehouse(id string, data *models.WarehouseModel) error
- func (s *StorageService) UpdateWarehouseLocation(id string, data *models.LocationPointModel) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type StorageService ¶
type StorageService struct {
// contains filtered or unexported fields
}
func NewStorageService ¶
func NewStorageService(db *gorm.DB, ctx *context.ERPContext, inventoryService *inventory.InventoryService) *StorageService
NewStorageService creates a new instance of StorageService with the given database connection, context and inventory service.
func (*StorageService) CreateLocation ¶
func (s *StorageService) CreateLocation(data *models.LocationPointModel, warehouse *models.WarehouseModel) error
CreateLocation creates a new location point record in the database.
It takes a pointer to a LocationPointModel and an optional pointer to a WarehouseModel as input. If the warehouse pointer is not nil, it either creates a new warehouse record in the database if the warehouse ID is empty or updates the existing record if the ID is not empty. The function then sets the WarehouseID field of the LocationPointModel to the ID of the created or updated warehouse. Finally, it creates a new location point record in the database using the input data.
The function returns an error if any of the operations fail. Otherwise, it returns nil.
func (*StorageService) CreateWarehouse ¶
func (s *StorageService) CreateWarehouse(data *models.WarehouseModel, lat, lng *float64) error
CreateWarehouse creates a new warehouse in the database.
It takes a pointer to a WarehouseModel, latitude and longitude as input. The function first creates a new warehouse record in the database using the input data. If the latitude and longitude are not empty, it creates a new location point record associated with the new warehouse.
The function returns an error if any of the operations fail. Otherwise, it returns nil.
func (*StorageService) DeleteWarehouse ¶
func (s *StorageService) DeleteWarehouse(id string) error
DeleteWarehouse deletes a warehouse in the database.
It takes an ID as input and attempts to delete the warehouse with the given ID from the database. If the deletion is successful, the function returns nil. If the deletion operation fails, the function returns an error.
func (*StorageService) DeleteWarehouseLocation ¶
func (s *StorageService) DeleteWarehouseLocation(id string) error
DeleteWarehouseLocation deletes a warehouse location record in the database.
It takes an ID as input and attempts to delete the warehouse location with the given ID from the database. If the deletion is successful, the function returns nil. If the deletion operation fails, the function returns an error.
func (*StorageService) GetWarehouseLocationByID ¶
func (s *StorageService) GetWarehouseLocationByID(id string) (*models.LocationPointModel, error)
GetWarehouseLocationByID retrieves a warehouse location record from the database by ID.
It takes an ID as input and returns a pointer to a LocationPointModel and an error. The function uses GORM to retrieve the location point data from the location_points table where the ID matches and preloads the associated warehouse. If the operation fails, an error is returned.
func (*StorageService) GetWarehouseLocations ¶
func (*StorageService) GetWarehouses ¶
GetWarehouses retrieves a paginated list of warehouses from the database.
It takes an HTTP request and a search query string as input. The method uses GORM to query the database for warehouses, applying the search query to the warehouse name, code and description fields. If the request contains a company ID header, the method also filters the result by the company ID. The function utilizes pagination to manage the result set and applies any necessary request modifications using the utils.FixRequest utility.
The function returns a paginated page of WarehouseModel and an error if the operation fails.
func (*StorageService) UpdateWarehouse ¶
func (s *StorageService) UpdateWarehouse(id string, data *models.WarehouseModel) error
UpdateWarehouse updates an existing warehouse record in the database.
It takes an ID and a pointer to a WarehouseModel as input and returns an error if the operation fails. The function uses GORM to update the warehouse data in the warehouses table where the ID matches.
If the update is successful, the error is nil. Otherwise, the error contains information about what went wrong.
func (*StorageService) UpdateWarehouseLocation ¶
func (s *StorageService) UpdateWarehouseLocation(id string, data *models.LocationPointModel) error