CommentController.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace App\Http\Controllers\Client;
  3. use App\Http\Controllers\Controller;
  4. use App\Services\Client\CommentService;
  5. use Illuminate\Http\Request;
  6. /**
  7. * @group 用户端-评论管理
  8. *
  9. * 评论相关的API接口
  10. */
  11. class CommentController extends Controller
  12. {
  13. protected CommentService $service;
  14. public function __construct(CommentService $service)
  15. {
  16. $this->service = $service;
  17. }
  18. /**
  19. * 发表评价
  20. *
  21. * 发表评价
  22. *
  23. * @authenticated
  24. *
  25. * @bodyParam coach_id int required 技师ID. Example: 1
  26. * @bodyParam content string required 评价内容. Example: 很棒的服务!
  27. * @bodyParam rating int required 评分. Example: 5
  28. *
  29. * @response {
  30. * "code": 200,
  31. * "message": "评价成功",
  32. * "data": {
  33. * "id": 1,
  34. * "coach_id": 1,
  35. * "content": "很棒的服务!",
  36. * "rating": 5,
  37. * "created_at": "2024-01-01 10:00:00"
  38. * }
  39. * }
  40. */
  41. public function create(Request $request)
  42. {
  43. $coachId = $request->input('coach_id');
  44. $content = $request->input('content');
  45. $rating = $request->input('rating');
  46. return $this->service->createComment($coachId, $content, $rating);
  47. }
  48. /**
  49. * 评价列表
  50. *
  51. * 获取评价列表
  52. *
  53. * @authenticated
  54. *
  55. * @queryParam coach_id int required 技师ID. Example: 1
  56. *
  57. * @response {
  58. * "code": 200,
  59. * "message": "获取成功",
  60. * "data": [
  61. * {
  62. * "id": 1,
  63. * "coach_id": 1,
  64. * "content": "很棒的服务!",
  65. * "rating": 5,
  66. * "created_at": "2024-01-01 10:00:00"
  67. * }
  68. * ]
  69. * }
  70. */
  71. public function list(Request $request)
  72. {
  73. $coachId = $request->input('coach_id');
  74. return $this->service->getCommentList($coachId);
  75. }
  76. }