123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <?php
- namespace App\Http\Controllers\Admin\Manage;
- use App\Http\Controllers\Controller;
- use App\Services\Manage\SearchHistoryService;
- use Illuminate\Http\Request;
- /**
- * SearchHistory
- */
- class SearchHistoryController extends Controller
- {
- /**
- * @var SearchHistoryService
- */
- private $searchHistoryService;
- /**
- * SearchHistoryController constructor.
- *
- * @param SearchHistoryService $searchHistoryService
- */
- public function __construct(SearchHistoryService $searchHistoryService)
- {
- parent::__construct();
- $this->middleware('checkUserPermission');
- $this->searchHistoryService = $searchHistoryService;
- }
- /**
- * 列表
- * @param Request $request
- *
- * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\JsonResource
- * @throws \Prettus\Repository\Exceptions\RepositoryException
- */
- public function index(Request $request)
- {
- $searchHistorys = $this->searchHistoryService->handleList($request);
- return $this->response->success($searchHistorys);
- }
- /**
- * 我的历史记录
- * @param Request $request
- * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\JsonResource
- * @throws \Prettus\Repository\Exceptions\RepositoryException
- */
- public function myHistory(Request $request)
- {
- $searchHistories = $this->searchHistoryService->handleMyHistory($request);
- return $this->response->success($searchHistories);
- }
- /**
- * 新增
- * @param Request $request
- *
- * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\JsonResource
- * @throws \Prettus\Validator\Exceptions\ValidatorException
- */
- public function store(Request $request)
- {
- $data = $this->validateData($request, [
- 'name' => 'nullable|sometimes',
- 'body' => 'required',
- // 'status' => 'required|integer',
- ], []);
- $searchHistory = $this->searchHistoryService->handleStore($data);
- return $this->response->created($searchHistory, '创建成功');
- }
- /**
- * 详情
- * @param Request $request
- * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\JsonResource
- */
- public function show(Request $request)
- {
- $this->validate($request, ['id' => 'required|integer']);
- $searchHistory = $this->searchHistoryService->handleProfile($request->get('id'));
- return $this->response->success($searchHistory);
- }
- /**
- * 更新
- * @param Request $request
- *
- * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Resources\Json\JsonResource
- * @throws \Prettus\Validator\Exceptions\ValidatorException
- */
- public function update(Request $request)
- {
- $data = $this->validateData($request, [
- 'id' => 'required|integer',
- 'name' => 'required|string|max:200',
- 'sort' => 'required|integer',
- 'status' => 'required|integer',
- ], []);
- $searchHistory = $this->searchHistoryService->handleUpdate($data);
- return $this->response->success($searchHistory, '更新成功');
- }
- /**
- * 删除
- * @param Request $request
- */
- public function destroy(Request $request)
- {
- $this->validate($request, ['id' => 'required|integer']);
- $re = $this->searchHistoryService->handleDelete($request->get('id'));
- if ($re) {
- return $this->response->ok('删除成功');
- }
- return $this->response->fail('删除失败');
- }
- }
|