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,129 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\StoreIdeaRequest;
|
||||
use App\Http\Requests\UpdateIdeaRequest;
|
||||
use App\Http\Resources\IdeaResource;
|
||||
use App\Models\Idea;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class IdeaController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$query = Idea::query();
|
||||
|
||||
if ($request->filled('status')) {
|
||||
$query->where('status', $request->string('status'));
|
||||
}
|
||||
|
||||
if ($request->filled('category')) {
|
||||
$query->where('category', $request->string('category'));
|
||||
}
|
||||
|
||||
if ($request->filled('project_id')) {
|
||||
$query->where('project_id', $request->integer('project_id'));
|
||||
}
|
||||
|
||||
if ($request->filled('search')) {
|
||||
$query->search($request->string('search'));
|
||||
}
|
||||
|
||||
if ($request->filled('unlinked')) {
|
||||
$query->unlinked();
|
||||
}
|
||||
|
||||
if ($request->filled('priority')) {
|
||||
$query->where('priority', $request->integer('priority'));
|
||||
}
|
||||
|
||||
$ideas = $query->orderBy('priority', 'desc')->orderBy('created_at', 'desc')->get();
|
||||
|
||||
// Eager load relationships if requested
|
||||
if ($request->boolean('with_project')) {
|
||||
$ideas->load(['project']);
|
||||
}
|
||||
|
||||
if ($request->boolean('with_user')) {
|
||||
$ideas->load(['user']);
|
||||
}
|
||||
|
||||
return IdeaResource::collection($ideas);
|
||||
}
|
||||
|
||||
public function store(StoreIdeaRequest $request)
|
||||
{
|
||||
$idea = Idea::create($request->validated());
|
||||
|
||||
return (new IdeaResource($idea))
|
||||
->response()
|
||||
->setStatusCode(201);
|
||||
}
|
||||
|
||||
public function show(Request $request, Idea $idea)
|
||||
{
|
||||
if ($request->boolean('with_project')) {
|
||||
$idea->load(['project']);
|
||||
}
|
||||
|
||||
if ($request->boolean('with_user')) {
|
||||
$idea->load(['user']);
|
||||
}
|
||||
|
||||
return new IdeaResource($idea);
|
||||
}
|
||||
|
||||
public function update(UpdateIdeaRequest $request, Idea $idea)
|
||||
{
|
||||
$idea->update($request->validated());
|
||||
|
||||
return new IdeaResource($idea);
|
||||
}
|
||||
|
||||
public function destroy(Idea $idea)
|
||||
{
|
||||
$idea->delete();
|
||||
|
||||
return response()->noContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Change idea status.
|
||||
*/
|
||||
public function changeStatus(Request $request, Idea $idea)
|
||||
{
|
||||
$request->validate([
|
||||
'status' => ['required', 'string', 'in:' . implode(',', Idea::STATUSES)],
|
||||
]);
|
||||
|
||||
$idea->update(['status' => $request->string('status')]);
|
||||
|
||||
return new IdeaResource($idea);
|
||||
}
|
||||
|
||||
/**
|
||||
* Link an idea to a project.
|
||||
*/
|
||||
public function linkToProject(Request $request, Idea $idea)
|
||||
{
|
||||
$request->validate([
|
||||
'project_id' => ['required', 'integer', 'exists:projects,id'],
|
||||
]);
|
||||
|
||||
$idea->update(['project_id' => $request->integer('project_id')]);
|
||||
|
||||
return new IdeaResource($idea->load(['project']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlink an idea from a project.
|
||||
*/
|
||||
public function unlinkFromProject(Idea $idea)
|
||||
{
|
||||
$idea->update(['project_id' => null]);
|
||||
|
||||
return new IdeaResource($idea);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user