Commit the Projects/Tasks/Ideas/TaskComments feature
This was already implemented, migrated, and running live, but had never been committed. Bringing it into git: Project/Task/Idea/ TaskComment models, their JSON API (CRUD + status transitions, task comments, idea<->project linking), Livewire UI pages, and the nav/route wiring for them. All 42 of its own tests pass. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\StoreTaskCommentRequest;
|
||||
use App\Http\Resources\TaskCommentResource;
|
||||
use App\Models\Task;
|
||||
use App\Models\TaskComment;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TaskCommentController extends Controller
|
||||
{
|
||||
/**
|
||||
* Get all comments for a task.
|
||||
*/
|
||||
public function index(Request $request, Task $task)
|
||||
{
|
||||
$comments = $task->comments()->orderBy('created_at')->get();
|
||||
|
||||
return TaskCommentResource::collection($comments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new comment for a task.
|
||||
*/
|
||||
public function store(StoreTaskCommentRequest $request, Task $task)
|
||||
{
|
||||
$comment = $task->comments()->create($request->validated());
|
||||
|
||||
return (new TaskCommentResource($comment))
|
||||
->response()
|
||||
->setStatusCode(201);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a comment.
|
||||
*/
|
||||
public function update(Request $request, TaskComment $comment)
|
||||
{
|
||||
$request->validate([
|
||||
'body' => ['required', 'string'],
|
||||
]);
|
||||
|
||||
$comment->update([
|
||||
'body' => $request->string('body'),
|
||||
]);
|
||||
|
||||
return new TaskCommentResource($comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a single comment.
|
||||
*/
|
||||
public function show(TaskComment $comment)
|
||||
{
|
||||
return new TaskCommentResource($comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a comment.
|
||||
*/
|
||||
public function destroy(TaskComment $comment)
|
||||
{
|
||||
$comment->delete();
|
||||
|
||||
return response()->noContent();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user