Ejemplo n.º 1
0
// Searchfy converts *Inventory to *InventorySearch.
func (src *Inventory) Searchfy() (*InventorySearch, error) {
	if src == nil {
		return nil, nil
	}
	dest := &InventorySearch{}
	dest.src = src
	var err error
	var b []byte
	dest.ID = strconv.FormatInt(src.ID, 10)
	dest.ProductName = src.ProductName

	dest.Description = src.Description
	dest.DescriptionUnigram, err = smgutils.UnigramForSearch(src.Description)
	if err != nil {
		return nil, err
	}
	dest.DescriptionBigram, err = smgutils.BigramForSearch(src.Description)
	if err != nil {
		return nil, err
	}
	dest.Stock = float64(src.Stock)
	dest.Price = strconv.Itoa(src.Price)
	dest.Barcode = strconv.FormatInt(src.Barcode, 10)

	b, err = json.Marshal(src.AdminNames)
	if err != nil {
		return nil, err
	}
	if str := string(b); str != "" && str != "\"\"" {
		dest.AdminNames = str
	}

	b, err = json.Marshal(src.Shops)
	if err != nil {
		return nil, err
	}
	if str := string(b); str != "" && str != "\"\"" {
		dest.Shops = str
	}
	dest.CreatedAt = src.CreatedAt

	dest.UpdatedAtUnixTime = float64(smgutils.Unix(src.UpdatedAt))
	dest.UpdatedAt = src.UpdatedAt
	return dest, nil
}
Ejemplo n.º 2
0
func (doc *Inventory) Searchfy() (*InventorySearch, error) {
	if doc == nil {
		return nil, nil
	}
	dest := &InventorySearch{}

	var err error
	var b []byte

	dest.ID = strconv.FormatInt(doc.ID, 10)
	dest.ProductName = doc.ProductName
	dest.Description = doc.Description
	dest.DescriptionUnigram, err = smgutils.UnigramForSearch(doc.Description)
	if err != nil {
		return nil, err
	}
	dest.DescriptionBigram, err = smgutils.BigramForSearch(doc.Description)
	if err != nil {
		return nil, err
	}
	dest.Stock = float64(doc.Stock)
	b, err = json.Marshal(dest.AdminNames)
	if err != nil {
		return nil, err
	}
	if str := string(b); str != "" && str != `""` {
		dest.AdminNames = str
	}
	b, err = json.Marshal(dest.Shops)
	if err != nil {
		return nil, err
	}
	if str := string(b); str != "" && str != `""` {
		dest.Shops = str
	}
	dest.CreatedAt = doc.CreatedAt

	return dest, nil
}