Пример #1
0
func (s *ProductService) ListStocks(parser *db.QueryParser) ([]*model.Product, error) {

	// func FillProductStocksByIdSet(models []*model.Product) error {
	// 	if nil == models || len(models) == 0 {
	// 		return nil
	// 	}

	// 	var idset = map[int64]bool{}
	// 	for _, m := range models {
	// 		idset[int64(m.Id)] = true
	// 	}
	// 	if allstocks, err := GetAllStocksByIdSet(idset); err != nil {
	// 		return err
	// 	} else {
	// 		if nil != allstocks {
	// 			for _, m := range models {
	// 				if stock, ok := allstocks[int64(m.Id)]; ok {
	// 					m.Stocks = stock
	// 					m.Stock = stock.Total()
	// 				}
	// 			}
	// 		}
	// 	}
	// 	return nil
	// }

	if models, err := productdao.List(parser); err != nil {
		return nil, err
	} else {
		if err := inventorydao.FillProductStocksByIdSet(models); err != nil {
			return nil, err
		}
		return models, nil
	}
}
Пример #2
0
//
// Get Product, with product's size and color properties.
//
func (s *ProductService) GetProduct(id int, withs Withs) (*model.Product, error) {
	if product, err := productdao.Get(id); err != nil {
		return nil, err
	} else if nil != product {
		models := []*model.Product{product}
		if withs&WITH_PRODUCT_DETAIL > 0 {
			if err := productdao.FillProductPropertiesByIdSet(models); err != nil {
				return nil, err
			}
		}
		if withs&WITH_PRODUCT_INVENTORY > 0 {
			if err := inventorydao.FillProductStocksByIdSet(models); err != nil {
				return nil, err
			}
		}
		return product, nil
	}
	return nil, nil
}
Пример #3
0
func (s *ProductService) List(parser *db.QueryParser, withs Withs) ([]*model.Product, error) {
	if models, err := productdao.List(parser); err != nil {
		return nil, err
	} else {
		// TODO: Print warrning information when has unused withs.
		// fmt.Println("--------------------------------------------------------------------", withs)
		if withs&WITH_PRODUCT_DETAIL > 0 {
			if err := productdao.FillProductPropertiesByIdSet(models); err != nil {
				return nil, err
			}
		}
		if withs&WITH_PRODUCT_INVENTORY > 0 {
			if err := inventorydao.FillProductStocksByIdSet(models); err != nil {
				return nil, err
			}
		}
		return models, nil
	}
}