123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?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\FileObjectType;
- use App\Models\Enums\ObjectAction;
- use App\Models\File;
- use App\Repositories\ActionRepository;
- use App\Repositories\ContainerFileRepository;
- use App\Services\File\FileAssociationService;
- use App\Services\File\ImageUrlService;
- use DOMDocument;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Auth;
- class ActionController extends Controller
- {
- public function history(string $objectType, string $objectId)
- {
- $actionObjectType = ActionObjectType::from($objectType);
- $model = $actionObjectType->modelBuilder()->findOrFail($objectId);
- $objectIds = [$objectId];
- if (ActionObjectType::CONTAINER_FILE->value == $objectType) {
- ContainerFileRepository::getSourceFileFiles($model)->each(function ($file) use (&$objectIds) {
- $objectIds[] = $file->id;
- $objectIds[] = $file->source_file_id;
- });
- }
- return $this->success([
- 'data' => ActionRepository::actionWithHistory($actionObjectType, array_unique($objectIds)),
- ]);
- }
- /**
- * action comment
- *
- * @param CommentRequest $request
- * @param string $objectType
- * @param string $objectId
- */
- public function comment(FileAssociationService $service, CommentRequest $request, string $objectType, string $objectId,ImageUrlService $imgService)
- {
- $actionObjectType = ActionObjectType::from($objectType);
- $comment=$request->get('comment');
- $newComment=$imgService->interceptImageUrl($comment);
- $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
- };
- $service->check(
- $request->get("file_ids", []),
- FileObjectType::ACTION,
- );
- $action = ActionRepository::create(
- $objectId,
- $actionObjectType,
- ObjectAction::COMMENTED,
- projectId: $projectId,
- comment: $newComment,
- );
- $service->association($action->id);
- return $this->created();
- }
- /**
- * update comment
- *
- * @param CommentRequest $request
- * @param string $id
- * @return \Illuminate\Http\Response
- */
- public function updateComment(CommentRequest $request, string $id,ImageUrlService $imgService)
- {
- $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);
- $comment=$request->get('comment');
- $newComment=$imgService->interceptImageUrl($comment);
- $action->comment = $newComment;
- $action->save();
- return $this->noContent();
- }
- public function lastDynamic(){
- return $this->success([
- 'data' => ActionRepository::allLatestDynamic()
- ]);
- }
- }
|