敏捷工具
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.1 KiB

2 years ago
  1. package com.whn.hellospring.controller;
  2. import com.whn.hellospring.model.CoffeeDO;
  3. import com.whn.hellospring.model.CoffeeDTO;
  4. import com.whn.hellospring.request.DeleteCoffeeRequest;
  5. import com.whn.hellospring.request.GetCoffeeListByOrderIdRequest;
  6. import com.whn.hellospring.service.CoffeeService;
  7. import com.whn.hellospring.utils.DO2DTOUtil;
  8. import org.joda.money.CurrencyUnit;
  9. import org.joda.money.Money;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.web.bind.annotation.PostMapping;
  12. import org.springframework.web.bind.annotation.RequestBody;
  13. import org.springframework.web.bind.annotation.RequestMapping;
  14. import org.springframework.web.bind.annotation.RestController;
  15. import javax.validation.Valid;
  16. import java.util.ArrayList;
  17. import java.util.List;
  18. @RestController
  19. @RequestMapping(value = "/coffee")
  20. public class CoffeeController {
  21. @Autowired
  22. CoffeeService service;
  23. /**
  24. * 创建编辑咖啡
  25. */
  26. @PostMapping(value = "/update")
  27. public String createCoffee(@Valid @RequestBody CoffeeDTO coffeeDTO){
  28. CoffeeDO coffeeDO = (CoffeeDO) DO2DTOUtil.getInstance().dtoToDo(coffeeDTO, CoffeeDO.class);
  29. coffeeDO.setPrice(Money.of(CurrencyUnit.of("CNY"),coffeeDTO.getPrice()));
  30. service.updateCoffee(coffeeDO);
  31. return "success";
  32. }
  33. /**
  34. * 删除咖啡
  35. */
  36. @PostMapping(value = "/delete")
  37. public String deleteCoffeeById(@RequestBody DeleteCoffeeRequest request){
  38. service.deleteCoffee(request.getId());
  39. return "success";
  40. }
  41. /**
  42. * 获取一个订单下的咖啡列表
  43. * @return
  44. */
  45. @PostMapping(value = "/coffeeListByOrderId")
  46. public List<CoffeeDTO> getCoffeeListByOrderId(@RequestBody GetCoffeeListByOrderIdRequest request){
  47. List<CoffeeDO> coffeeList = service.getCoffeeListWithOrderId(request.getOrderId());
  48. List<CoffeeDTO> coffeeDTOList = new ArrayList<>();
  49. for (CoffeeDO coffeeDo :coffeeList) {
  50. CoffeeDTO dto = new CoffeeDTO(coffeeDo);
  51. coffeeDTOList.add(dto);
  52. }
  53. return coffeeDTOList;
  54. }
  55. }