Add comments to tasks
Everyone who may change a task's status (attached subcontractors too) comments on it on the job page. Authors edit and remove their own comments; admin and management may remove anyone's (jobs.remove-any-task-comment). Edited comments show when they were edited, and task cards show the number of comments. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
+51
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Jobs\Infrastructure\Persistence\Repositories;
|
||||
|
||||
use App\Modules\Jobs\Domain\Contracts\TaskCommentRepository;
|
||||
use App\Modules\Jobs\Domain\Entities\TaskComment;
|
||||
use App\Modules\Jobs\Domain\ValueObjects\TaskCommentBody;
|
||||
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\TaskCommentModel;
|
||||
use DateTimeImmutable;
|
||||
|
||||
class EloquentTaskCommentRepository implements TaskCommentRepository
|
||||
{
|
||||
public function findForTask(int $taskId, int $commentId): ?TaskComment
|
||||
{
|
||||
$model = TaskCommentModel::query()->where('task_id', $taskId)->find($commentId);
|
||||
|
||||
return $model === null ? null : $this->toEntity($model);
|
||||
}
|
||||
|
||||
public function save(TaskComment $comment): TaskComment
|
||||
{
|
||||
$model = $comment->id() === null ? new TaskCommentModel : TaskCommentModel::query()->findOrFail($comment->id());
|
||||
|
||||
$model->fill([
|
||||
'task_id' => $comment->taskId(),
|
||||
'user_id' => $comment->authorId(),
|
||||
'body' => $comment->body()->value,
|
||||
'edited_at' => $comment->editedAt(),
|
||||
'created_at' => $comment->createdAt(),
|
||||
])->save();
|
||||
|
||||
return $this->toEntity($model->refresh());
|
||||
}
|
||||
|
||||
public function delete(TaskComment $comment): void
|
||||
{
|
||||
TaskCommentModel::query()->whereKey($comment->id())->delete();
|
||||
}
|
||||
|
||||
private function toEntity(TaskCommentModel $model): TaskComment
|
||||
{
|
||||
return TaskComment::reconstitute(
|
||||
$model->id,
|
||||
$model->task_id,
|
||||
$model->user_id,
|
||||
new TaskCommentBody($model->body),
|
||||
DateTimeImmutable::createFromInterface($model->created_at),
|
||||
$model->edited_at === null ? null : DateTimeImmutable::createFromInterface($model->edited_at),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user