SceneController.java 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package com.fdage.followheartplay.controller;
  2. import com.fdage.followheartplay.dto.SceneDto;
  3. import com.fdage.followheartplay.service.SceneService;
  4. import com.fdkankan.common.constant.ServerCode;
  5. import com.fdkankan.common.response.ResultData;
  6. import com.fdkankan.common.util.JwtUtil;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.util.ObjectUtils;
  9. import org.springframework.web.bind.annotation.PostMapping;
  10. import org.springframework.web.bind.annotation.RequestHeader;
  11. import org.springframework.web.bind.annotation.RequestMapping;
  12. import org.springframework.web.bind.annotation.RestController;
  13. import java.util.List;
  14. @RestController
  15. @RequestMapping("/scene")
  16. public class SceneController {
  17. @Autowired
  18. private SceneService sceneService;
  19. /**
  20. * 查询场景信息
  21. * @param token
  22. * @param type 0:未购买,1:已购买,空全部
  23. * @return
  24. */
  25. @PostMapping("/list")
  26. public ResultData getScenes(@RequestHeader String token, Integer type){
  27. String username = JwtUtil.getUsername(token);
  28. List<SceneDto> sceneEntities = sceneService.getScenesByTypeAndUserId(username,type);
  29. return ResultData.ok(sceneEntities);
  30. }
  31. /**
  32. * 查询场景信息
  33. * @param token
  34. * @param sceneId
  35. * @return
  36. */
  37. @PostMapping("/buy")
  38. public ResultData buy(@RequestHeader String token, Integer sceneId){
  39. if(ObjectUtils.isEmpty(sceneId)){
  40. return ResultData.error(ServerCode.PARAM_REQUIRED.code(),"缺少必要参数!");
  41. }
  42. String username = JwtUtil.getUsername(token);
  43. sceneService.buy(username,sceneId);
  44. return ResultData.ok();
  45. }
  46. }