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,113 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\StoreProjectRequest;
|
||||
use App\Http\Requests\UpdateProjectRequest;
|
||||
use App\Http\Resources\IdeaResource;
|
||||
use App\Http\Resources\ProjectResource;
|
||||
use App\Http\Resources\TaskResource;
|
||||
use App\Models\Project;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ProjectController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$query = Project::query();
|
||||
|
||||
if ($request->filled('status')) {
|
||||
$query->where('status', $request->string('status'));
|
||||
}
|
||||
|
||||
if ($request->filled('name')) {
|
||||
$query->where('name', 'like', '%' . $request->string('name') . '%');
|
||||
}
|
||||
|
||||
$projects = $query->orderBy('name')->get();
|
||||
|
||||
// Eager load tasks if ?with_tasks=1
|
||||
if ($request->boolean('with_tasks')) {
|
||||
$projects->load(['tasks.comments']);
|
||||
}
|
||||
|
||||
return ProjectResource::collection($projects);
|
||||
}
|
||||
|
||||
public function store(StoreProjectRequest $request)
|
||||
{
|
||||
$project = Project::create($request->validated());
|
||||
|
||||
return (new ProjectResource($project))
|
||||
->response()
|
||||
->setStatusCode(201);
|
||||
}
|
||||
|
||||
public function show(Request $request, Project $project)
|
||||
{
|
||||
if ($request->boolean('with_tasks')) {
|
||||
$project->load(['tasks.comments']);
|
||||
}
|
||||
|
||||
return new ProjectResource($project);
|
||||
}
|
||||
|
||||
public function update(UpdateProjectRequest $request, Project $project)
|
||||
{
|
||||
$project->update($request->validated());
|
||||
|
||||
return new ProjectResource($project);
|
||||
}
|
||||
|
||||
public function destroy(Project $project)
|
||||
{
|
||||
$project->delete();
|
||||
|
||||
return response()->noContent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tasks for a project.
|
||||
*/
|
||||
public function tasks(Request $request, Project $project)
|
||||
{
|
||||
$query = $project->tasks()->with(['comments']);
|
||||
|
||||
if ($request->filled('status')) {
|
||||
$query->where('status', $request->string('status'));
|
||||
}
|
||||
|
||||
if ($request->filled('priority')) {
|
||||
$query->where('priority', $request->integer('priority'));
|
||||
}
|
||||
|
||||
$tasks = $query->orderBy('priority', 'desc')->orderBy('created_at')->get();
|
||||
|
||||
return TaskResource::collection($tasks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ideas for a project.
|
||||
*/
|
||||
public function ideas(Request $request, Project $project)
|
||||
{
|
||||
$query = $project->ideas()->with(['user']);
|
||||
|
||||
if ($request->filled('status')) {
|
||||
$query->where('status', $request->string('status'));
|
||||
}
|
||||
|
||||
if ($request->filled('category')) {
|
||||
$query->where('category', $request->string('category'));
|
||||
}
|
||||
|
||||
if ($request->filled('priority')) {
|
||||
$query->where('priority', $request->integer('priority'));
|
||||
}
|
||||
|
||||
$ideas = $query->orderBy('priority', 'desc')->orderBy('created_at', 'desc')->get();
|
||||
|
||||
return IdeaResource::collection($ideas);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user