SearchHistoryController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. namespace App\Http\Controllers\Admin\Manage;
  3. use App\Http\Controllers\Controller;
  4. use App\Services\Manage\SearchHistoryService;
  5. use Illuminate\Http\Request;
  6. /**
  7. * SearchHistory
  8. */
  9. class SearchHistoryController extends Controller
  10. {
  11. /**
  12. * @var SearchHistoryService
  13. */
  14. private $searchHistoryService;
  15. /**
  16. * SearchHistoryController constructor.
  17. *
  18. * @param SearchHistoryService $searchHistoryService
  19. */
  20. public function __construct(SearchHistoryService $searchHistoryService)
  21. {
  22. parent::__construct();
  23. $this->middleware('checkUserPermission');
  24. $this->searchHistoryService = $searchHistoryService;
  25. }
  26. /**
  27. * 列表
  28. * @param Request $request
  29. *
  30. * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\JsonResource
  31. * @throws \Prettus\Repository\Exceptions\RepositoryException
  32. */
  33. public function index(Request $request)
  34. {
  35. $searchHistorys = $this->searchHistoryService->handleList($request);
  36. return $this->response->success($searchHistorys);
  37. }
  38. /**
  39. * 我的历史记录
  40. * @param Request $request
  41. * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\JsonResource
  42. * @throws \Prettus\Repository\Exceptions\RepositoryException
  43. */
  44. public function myHistory(Request $request)
  45. {
  46. $searchHistories = $this->searchHistoryService->handleMyHistory($request);
  47. return $this->response->success($searchHistories);
  48. }
  49. /**
  50. * 新增
  51. * @param Request $request
  52. *
  53. * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\JsonResource
  54. * @throws \Prettus\Validator\Exceptions\ValidatorException
  55. */
  56. public function store(Request $request)
  57. {
  58. $data = $this->validateData($request, [
  59. 'name' => 'nullable|sometimes',
  60. 'body' => 'required',
  61. // 'status' => 'required|integer',
  62. ], []);
  63. $searchHistory = $this->searchHistoryService->handleStore($data);
  64. return $this->response->created($searchHistory, '创建成功');
  65. }
  66. /**
  67. * 详情
  68. * @param Request $request
  69. * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\JsonResource
  70. */
  71. public function show(Request $request)
  72. {
  73. $this->validate($request, ['id' => 'required|integer']);
  74. $searchHistory = $this->searchHistoryService->handleProfile($request->get('id'));
  75. return $this->response->success($searchHistory);
  76. }
  77. /**
  78. * 更新
  79. * @param Request $request
  80. *
  81. * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\JsonResource
  82. * @throws \Prettus\Validator\Exceptions\ValidatorException
  83. */
  84. public function update(Request $request)
  85. {
  86. $data = $this->validateData($request, [
  87. 'id' => 'required|integer',
  88. 'name' => 'required|string|max:200',
  89. 'sort' => 'required|integer',
  90. 'status' => 'required|integer',
  91. ], []);
  92. $searchHistory = $this->searchHistoryService->handleUpdate($data);
  93. return $this->response->success($searchHistory, '更新成功');
  94. }
  95. /**
  96. * 删除
  97. * @param Request $request
  98. */
  99. public function destroy(Request $request)
  100. {
  101. $this->validate($request, ['id' => 'required|integer']);
  102. $re = $this->searchHistoryService->handleDelete($request->get('id'));
  103. if ($re) {
  104. return $this->response->ok('删除成功');
  105. }
  106. return $this->response->fail('删除失败');
  107. }
  108. }