AppointmentController.java 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package space.anyi.petServiceManagementSystem.server.controller;
  2. import io.swagger.v3.oas.annotations.Operation;
  3. import jakarta.servlet.http.HttpServletRequest;
  4. import jakarta.validation.Valid;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.web.bind.annotation.*;
  7. import space.anyi.petServiceManagementSystem.server.common.R;
  8. import space.anyi.petServiceManagementSystem.server.dto.appointment.AppointmentDto;
  9. import space.anyi.petServiceManagementSystem.server.service.AppointmentService;
  10. import space.anyi.petServiceManagementSystem.server.vo.appointment.AppointmentVo;
  11. import java.util.List;
  12. import java.util.Map;
  13. @RestController
  14. @RequestMapping("/appointments")
  15. public class AppointmentController {
  16. @Autowired
  17. private AppointmentService appointmentService;
  18. @PostMapping
  19. @Operation(summary = "提交预约")
  20. public R<AppointmentVo> create(@Valid @RequestBody AppointmentDto dto, HttpServletRequest request) {
  21. Long userId = (Long) request.getAttribute("userId");
  22. return R.ok(appointmentService.create(dto, userId));
  23. }
  24. @GetMapping
  25. @Operation(summary = "获取我的预约列表")
  26. public R<List<AppointmentVo>> list(HttpServletRequest request) {
  27. Long userId = (Long) request.getAttribute("userId");
  28. return R.ok(appointmentService.list(userId));
  29. }
  30. @GetMapping("/{id}")
  31. @Operation(summary = "获取预约详情")
  32. public R<AppointmentVo> getById(@PathVariable Long id, HttpServletRequest request) {
  33. Long userId = (Long) request.getAttribute("userId");
  34. return R.ok(appointmentService.getById(id, userId));
  35. }
  36. @PostMapping("/{id}/cancel")
  37. @Operation(summary = "申请取消")
  38. public R<Boolean> cancel(@PathVariable Long id, @RequestBody Map<String, String> body,
  39. HttpServletRequest request) {
  40. Long userId = (Long) request.getAttribute("userId");
  41. return R.ok(appointmentService.cancel(id, body.get("reason"), userId));
  42. }
  43. @PostMapping("/{id}/pay-deposit")
  44. @Operation(summary = "模拟支付定金")
  45. public R<Boolean> payDeposit(@PathVariable Long id, HttpServletRequest request) {
  46. Long userId = (Long) request.getAttribute("userId");
  47. return R.ok(appointmentService.payDeposit(id, userId));
  48. }
  49. }