// // 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 }
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 } }