service.py 700 B

123456789101112131415161718192021222324
  1. from db import MongoDao
  2. from data import BrandInfo, ProductInfo
  3. product_dao = MongoDao("vbrand-ec")
  4. class Service:
  5. @staticmethod
  6. def get_brand_list():
  7. """获取数据库中存储的品牌列表"""
  8. brand_list = product_dao.get_one_field_data("brandName")
  9. brand_list = list(dict.fromkeys(brand_list))
  10. return brand_list
  11. @staticmethod
  12. def load_products_by_brand(brand_name):
  13. """加载选定品牌的所有商品"""
  14. brand_info = BrandInfo(brand_name)
  15. return [product.title for product in brand_info.product_list], brand_info
  16. if __name__ == "__main__":
  17. brand_list = Service.get_brand_list()
  18. print(brand_list)