12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?php
- namespace App\Http\Controllers\API;
- use App\Http\Controllers\Controller;
- use App\Http\Requests\API\Action\CommentRequest;
- use App\Models\Action;
- use App\Models\Enums\ActionObjectType;
- use App\Models\Enums\ObjectAction;
- use App\Repositories\ActionRepository;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Auth;
- class ActionController extends Controller
- {
- public function history(string $objectType, string $objectId)
- {
- $actionObjectType = ActionObjectType::from($objectType);
- $actionObjectType->modelBuilder()->where("company_id", Auth::user()->company_id)->findOrFail($objectId);
- return $this->success([
- 'data' => ActionRepository::actionWithHistory($actionObjectType, $objectId),
- ]);
- }
- /**
- * action comment
- *
- * @param CommentRequest $request
- * @param string $objectType
- * @param string $objectId
- * @return \Illuminate\Http\Response
- */
- public function comment(CommentRequest $request, string $objectType, string $objectId)
- {
- $actionObjectType = ActionObjectType::from($objectType);
- $object = $actionObjectType?->modelBuilderAllowed($objectId)
- ->where("company_id", Auth::user()->company_id)
- ->findOrFail($objectId);
- $projectId = match ($actionObjectType) {
- ActionObjectType::PROJECT => $objectId,
- ActionObjectType::TASK => $object->project_id,
- default => null
- };
- ActionRepository::create(
- $objectId,
- $actionObjectType,
- ObjectAction::COMMENTED,
- projectId: $projectId,
- comment: $request->comment,
- );
- return $this->created();
- }
- /**
- * update comment
- *
- * @param CommentRequest $request
- * @param string $id
- * @return \Illuminate\Http\Response
- */
- public function updateComment(CommentRequest $request, string $id)
- {
- $action = Action::query()->findOrFail($id);
- $actionObjectType = ActionObjectType::from($action->object_type);
- $actionObjectType?->modelBuilderAllowed($action->object_id)
- ->where("company_id", Auth::user()->company_id)
- ->findOrFail($action->object_id);
- $action->comment = $request->comment;
- $action->save();
- return $this->noContent();
- }
- }
|