ShopApiController.java 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package com.cdf.controller.api;
  2. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  3. import com.cdf.common.ResultData;
  4. import com.cdf.entity.Shop;
  5. import com.cdf.entity.Video;
  6. import com.cdf.service.IShopCategoryService;
  7. import com.cdf.service.IShopService;
  8. import com.cdf.service.IVideoService;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.web.bind.annotation.GetMapping;
  11. import org.springframework.web.bind.annotation.RequestMapping;
  12. import org.springframework.web.bind.annotation.RequestParam;
  13. import org.springframework.web.bind.annotation.RestController;
  14. import java.util.List;
  15. @RestController
  16. @RequestMapping("/api")
  17. public class ShopApiController {
  18. @Autowired
  19. private IShopCategoryService shopCategoryService;
  20. @Autowired
  21. private IShopService shopService;
  22. @GetMapping("/getShopCategory")
  23. public ResultData getShopCategory(){
  24. return ResultData.ok(shopCategoryService.list());
  25. }
  26. @GetMapping("/getShopByCategory")
  27. public ResultData getShopByCategory(@RequestParam(required = false) Integer categoryId){
  28. LambdaQueryWrapper<Shop> wrapper = new LambdaQueryWrapper<>();
  29. if(categoryId != null){
  30. wrapper.eq(Shop::getCategoryId,categoryId);
  31. }
  32. wrapper.orderByAsc(Shop::getSort);
  33. wrapper.orderByDesc(Shop::getCreateTime);
  34. return ResultData.ok(shopService.list(wrapper));
  35. }
  36. }