123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <?php
- namespace App\Services\Course;
- use App\Contracts\Repositories\Course\CommentRepository;
- use App\Repositories\Criteria\Course\CommentCriteria;
- use App\Repositories\Eloquent\Course\CommentRepositoryEloquent;
- use App\Repositories\Enums\ResponseCodeEnum;
- use App\Repositories\Presenters\Course\CommentPresenter;
- use Illuminate\Http\Request;
- class CommentService
- {
- /**
- * @var CommentRepositoryEloquent
- */
- private $commentRepository;
- /**
- * CommentService constructor.
- *
- * @param CommentRepositoryEloquent $commentRepositoryEloquent
- */
- public function __construct(CommentRepositoryEloquent $commentRepositoryEloquent)
- {
- $this->commentRepository = $commentRepositoryEloquent;
- }
- /**
- * @param Request $request
- *
- * @return mixed
- * @throws \Prettus\Repository\Exceptions\RepositoryException
- */
- public function handleList(Request $request)
- {
- $this->commentRepository->pushCriteria(new CommentCriteria($request));
- $this->commentRepository->setPresenter(CommentPresenter::class);
- return $this->commentRepository->searchCommentsByPage();
- }
- /**
- * @param $id
- *
- * @return \Illuminate\Database\Eloquent\Model
- */
- public function handleProfile($id)
- {
- $this->commentRepository->setPresenter(CommentPresenter::class);
- return $this->commentRepository->searchCommentBy($id);
- }
- /**
- * @param array $data
- *
- * @return mixed
- * @throws \Prettus\Validator\Exceptions\ValidatorException
- */
- public function handleStore($data)
- {
- $comment = $this->commentRepository->create($data);
- return $comment;
- }
- /**
- * @param array $data
- *
- * @return mixed
- * @throws \Prettus\Validator\Exceptions\ValidatorException
- */
- public function handleUpdate($data)
- {
- $comment = $this->commentRepository->update($data, $data['id']);
- return $comment;
- }
- /**
- * @param Request $request
- *
- * @return mixed
- * @throws \Prettus\Validator\Exceptions\ValidatorException
- */
- public function handleDelete($id)
- {
- return $this->commentRepository->delete($id);
- }
- /**
- * @param Request $request
- *
- * @return mixed
- * @throws \Prettus\Repository\Exceptions\RepositoryException
- */
- public function handleAll(Request $request)
- {
- $this->commentRepository->pushCriteria(new CommentCriteria($request));
- $this->commentRepository->setPresenter(CommentPresenter::class);
- return $this->commentRepository->get();
- }
- /**
- * 批量删除
- * @param $ids
- * @return mixed
- */
- public function handleBatchDelete($ids)
- {
- return $this->commentRepository->whereIn('id', $ids)->delete();
- }
- public function handleUserDelete($id)
- {
- $node = $this->commentRepository->find($id);
- if ($node['user_id'] != login_user_id()) abort(ResponseCodeEnum::SERVICE_OPERATION_ERROR, '非法操作');
- return $this->commentRepository->delete($id);
- }
- }
|