diff --git a/database/entities/t_inventory_movement_entity.go b/database/entities/t_inventory_movement_entity.go index def5e6c..7ad4978 100644 --- a/database/entities/t_inventory_movement_entity.go +++ b/database/entities/t_inventory_movement_entity.go @@ -16,13 +16,13 @@ type TInventoryMovementEntity struct { MovementType string `gorm:"type:varchar(50);" json:"movement_type"` Status string `gorm:"type:varchar(50);default:'draft'" json:"status"` - ClientID uuid.UUID `gorm:"type:uuid;index;" json:"client_id"` - SourceLocationID uuid.UUID `gorm:"type:uuid;index;" json:"source_location_id"` - DestinationLocationID uuid.UUID `gorm:"type:uuid;index;" json:"destination_location_id"` - SourceZoneID uuid.UUID `gorm:"type:uuid;index;" json:"source_zone_id"` - DestinationZoneID uuid.UUID `gorm:"type:uuid;index;" json:"destination_zone_id"` - SourceAisleID uuid.UUID `gorm:"type:uuid;index;" json:"source_aisle_id"` - DestinationAisleID uuid.UUID `gorm:"type:uuid;index;" json:"destination_aisle_id"` + ClientID uuid.UUID `gorm:"type:uuid;index;" json:"client_id"` + SourceLocationID *uuid.UUID `gorm:"type:uuid;index;" json:"source_location_id"` + DestinationLocationID *uuid.UUID `gorm:"type:uuid;index;" json:"destination_location_id"` + SourceZoneID *uuid.UUID `gorm:"type:uuid;index;" json:"source_zone_id"` + DestinationZoneID *uuid.UUID `gorm:"type:uuid;index;" json:"destination_zone_id"` + SourceAisleID *uuid.UUID `gorm:"type:uuid;index;" json:"source_aisle_id"` + DestinationAisleID *uuid.UUID `gorm:"type:uuid;index;" json:"destination_aisle_id"` MovementLines []TInventoryMovementLineEntity `gorm:"foreignKey:InvMovementID;references:ID"` SourceLocation MWarehouseEntity `gorm:"foreignKey:SourceLocationID;references:ID"` diff --git a/modules/inventory_movement/dto/inventory_movement_dto.go b/modules/inventory_movement/dto/inventory_movement_dto.go index 173990b..a116610 100644 --- a/modules/inventory_movement/dto/inventory_movement_dto.go +++ b/modules/inventory_movement/dto/inventory_movement_dto.go @@ -86,36 +86,29 @@ type InventoryMovementLineResponse struct { } func ToInventoryMovementResponse(e entities.TInventoryMovementEntity) InventoryMovementResponse { - // prepare pointer strings for fields that are *string in the response - var srcLocationID *string - var dstLocationID *string - var srcZoneID *string - var dstZoneID *string - var srcAisleID *string - var dstAisleID *string + var srcLocationID, dstLocationID, srcZoneID, dstZoneID, srcAisleID, dstAisleID *string - // populate pointers from the entity's values - { + if e.SourceLocationID != nil { v := e.SourceLocationID.String() srcLocationID = &v } - { + if e.DestinationLocationID != nil { v := e.DestinationLocationID.String() dstLocationID = &v } - { + if e.SourceZoneID != nil { v := e.SourceZoneID.String() srcZoneID = &v } - { + if e.DestinationZoneID != nil { v := e.DestinationZoneID.String() dstZoneID = &v } - { + if e.SourceAisleID != nil { v := e.SourceAisleID.String() srcAisleID = &v } - { + if e.DestinationAisleID != nil { v := e.DestinationAisleID.String() dstAisleID = &v } diff --git a/modules/inventory_movement/service/inventory_movement_service.go b/modules/inventory_movement/service/inventory_movement_service.go index a0e72fe..818757d 100644 --- a/modules/inventory_movement/service/inventory_movement_service.go +++ b/modules/inventory_movement/service/inventory_movement_service.go @@ -78,25 +78,30 @@ func (s *inventoryMovementService) Create(ctx context.Context, req dtodomain.Inv tx.Rollback() return dtodomain.InventoryMovementResponse{}, err } - - var sourceLocationID, destinationLocationID, sourceZoneID, destinationZoneID, sourceAisleID, destinationAisleID uuid.UUID + var sourceLocationID, destinationLocationID, sourceZoneID, destinationZoneID, sourceAisleID, destinationAisleID *uuid.UUID if req.SourceLocationID != nil { - sourceLocationID = uuid.MustParse(*req.SourceLocationID) + tmp := uuid.MustParse(*req.SourceLocationID) + sourceLocationID = &tmp } if req.DestinationLocationID != nil { - destinationLocationID = uuid.MustParse(*req.DestinationLocationID) + tmp := uuid.MustParse(*req.DestinationLocationID) + destinationLocationID = &tmp } if req.SourceZoneID != nil { - sourceZoneID = uuid.MustParse(*req.SourceZoneID) + tmp := uuid.MustParse(*req.SourceZoneID) + sourceZoneID = &tmp } if req.DestinationZoneID != nil { - destinationZoneID = uuid.MustParse(*req.DestinationZoneID) + tmp := uuid.MustParse(*req.DestinationZoneID) + destinationZoneID = &tmp } if req.SourceAisleID != nil { - sourceAisleID = uuid.MustParse(*req.SourceAisleID) + tmp := uuid.MustParse(*req.SourceAisleID) + sourceAisleID = &tmp } if req.DestinationAisleID != nil { - destinationAisleID = uuid.MustParse(*req.DestinationAisleID) + tmp := uuid.MustParse(*req.DestinationAisleID) + destinationAisleID = &tmp } movement := entities.TInventoryMovementEntity{