Connect CalDAV todos to DB-Items, finish todo component and add it to pipeline items

This commit is contained in:
2026-02-24 16:15:21 +01:00
parent 7e2094847f
commit 823cd6391d
27 changed files with 605 additions and 205 deletions
+1 -1
View File
@@ -14,7 +14,7 @@ public function index($invoiceId)
$items = LineItem::with('unit')
->select('line_items.*')
->where('invoice_id', $invoiceId)
->orderBy('position', 'desc')
->orderBy('position', 'asc')
->get();
return $items->map(function ($item) {
+10 -1
View File
@@ -9,6 +9,15 @@
class NoteController extends Controller
{
/**
* Display a listing of the resource
*/
public function index()
{
$notes = Note::with('user')->orderBy('created_at', 'desc')->get();
return ApiDataTransformer::snakeToCamel($notes->toArray());
}
/**
* Display a listing of the resource.
* @param Request $request
@@ -16,7 +25,7 @@ class NoteController extends Controller
* @param string $modelId The ID of the model
* @return \Illuminate\Http\JsonResponse
*/
public function index(Request $request, string $modelType, int $modelId)
public function notesForModel(Request $request, string $modelType, int $modelId)
{
$model = app("App\\Models\\" . $modelType)::findOrFail($modelId);
+30 -7
View File
@@ -16,15 +16,38 @@ class PipelineController extends Controller
{
public function index()
{
$lanes = PipelineLane::with(['items' => function ($q) {
$q->withCount(['notes' => function ($query) {
$query->where('notable_type', 'App\Models\PipelineItem');
}])->orderBy('position');
}])->orderBy('position')->get();
$lanes = PipelineLane::with(['items' => function ($query) {
$query
->withCount(['notes' => function ($query) {
$query->where('notable_type', 'App\Models\PipelineItem');
}])
->withCount(['todos' => function ($query) {
$query->where('todoable_type', 'App\Models\PipelineItem')
->whereNotIn('status', ['completed', 'COMPLETED']);
}])
->with(['todos' => function ($query) {
$query->where('todoable_type', 'App\Models\PipelineItem')->orderBy('due_date', 'asc');
}])
->orderBy('position')
;
}])
->orderBy('position')
->get();
return $lanes->map(function ($lane) {
return ApiDataTransformer::snakeToCamel($lane->toArray());
$lanesArray = $lanes->map(function ($lane) {
$laneArray = $lane->toArray();
// Process items to add latest_todo_due_date and remove todos array
$laneArray['items'] = collect($laneArray['items'])->map(function ($item) {
$item['next_todo_due_date'] = $item['todos'][0]['due_date'] ?? null;
unset($item['todos']); // Remove the todos array
return $item;
})->toArray();
return $laneArray;
});
return ApiDataTransformer::snakeToCamel($lanesArray->toArray());
}
public function show()
+44 -16
View File
@@ -5,6 +5,7 @@
use App\Models\PipelineItem;
use App\Support\ApiDataTransformer;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class PipelineItemController extends Controller
{
@@ -13,11 +14,24 @@ class PipelineItemController extends Controller
*/
public function index()
{
$pipelineItems = PipelineItem::withCount(['notes' => function ($query) {
$query->where('notable_type', 'App\Models\PipelineItem');
}])->orderBy('position')->get();
$pipelineItems = PipelineItem
::withCount(['notes' => function ($query) {
$query->where('notable_type', 'App\Models\PipelineItem');
}])
->withCount(['todos' => function ($query) {
$query->where('todoable_type', 'App\Models\PipelineItem');
}])
->orderBy('position')
->get();
return ApiDataTransformer::snakeToCamel($pipelineItems->toArray());
$pipelineItemsArray = $pipelineItems->map(function ($item) {
$itemArray = $item->toArray();
$itemArray['next_todo_due_date'] = $item->todos->first()?->due_date?->toISOString() ?? null;
unset($itemArray['todos']); // Remove the todos array
return $itemArray;
});
return ApiDataTransformer::snakeToCamel($pipelineItemsArray->toArray());
}
/**
@@ -25,9 +39,12 @@ public function index()
*/
public function single(int $id)
{
$pipelineItem = PipelineItem::withCount(['notes' => function ($query) {
$query->where('notable_type', 'App\Models\PipelineItem');
}])->orderBy('position')->findOrFail($id);
$pipelineItem = PipelineItem
::with(['notes' => function ($query) {
$query->where('notable_type', 'App\Models\PipelineItem')->orderBy('created_at', 'desc');
}])->with(['todos' => function ($query) {
$query->where('todoable_type', 'App\Models\PipelineItem')->orderBy('due_date', 'asc');
}])->orderBy('position')->findOrFail($id);
return ApiDataTransformer::snakeToCamel($pipelineItem->toArray());
}
@@ -38,11 +55,11 @@ public function single(int $id)
public function store(Request $request)
{
$validatedData = $request->validate([
'pipeline_lane_id' => 'required|integer|exists:pipeline_lanes,id',
'pipelineLaneId' => 'required|integer|exists:pipeline_lanes,id',
'title' => 'required|string',
'position' => 'required|integer|min:0',
'expected_revenue' => 'nullable|numeric',
'due_date' => 'nullable|date',
'expectedRevenue' => 'nullable|numeric',
'dueDate' => 'nullable|date',
'description' => 'nullable|string',
]);
@@ -54,20 +71,31 @@ public function store(Request $request)
/**
* Update the specified resource in storage.
*/
public function update(Request $request, PipelineItem $pipelineItem)
public function update(Request $request, int $id)
{
$validatedData = $request->validate([
'pipeline_lane_id' => 'sometimes|integer|exists:pipeline_lanes,id',
'pipelineLaneId' => 'sometimes|integer|exists:pipeline_lanes,id',
'title' => 'sometimes|string',
'position' => 'sometimes|integer|min:0',
'expected_revenue' => 'nullable|numeric',
'due_date' => 'nullable|date',
'expectedRevenue' => 'nullable|numeric',
'dueDate' => 'nullable|date',
'description' => 'nullable|string',
]);
$pipelineItem->update($validatedData);
$snakeCaseData = ApiDataTransformer::camelToSnake($validatedData);
return ApiDataTransformer::snakeToCamel($pipelineItem->toArray());
DB::beginTransaction();
try {
$pipelineItem = PipelineItem::findOrFail($id);
$snakeCaseData = ApiDataTransformer::camelToSnake($validatedData);
$pipelineItem->update($snakeCaseData);
DB::commit();
return response()->noContent();
} catch (\Exception $e) {
DB::rollBack();
return response()->json(['error' => 'Failed to update pipeline item', 'message' => $e->getMessage()], 500);
}
}
/**
+53 -1
View File
@@ -15,7 +15,29 @@ public function index()
return ApiDataTransformer::snakeToCamel($todos->toArray());
}
public function show(string $id)
/**
* Display a listing of the resource.
* @param Request $request
* @param string $modelType The type of the model (e.g., 'Customer', 'Invoice')
* @param string $modelId The ID of the model
* @return \Illuminate\Http\JsonResponse
*/
public function todosForModel(Request $request, string $modelType, int $modelId)
{
$model = app("App\\Models\\" . $modelType)::findOrFail($modelId);
// Load all todos of the model with the user relationship
$todos = $model->todos()->with('type')->orderBy('created_at', 'desc')->get();
// Transformiere die Daten in camelCase
$notesArray = $todos->map(function ($todo) {
return ApiDataTransformer::snakeToCamel($todo->toArray());
});
return response()->json($notesArray);
}
public function single(string $id)
{
return Todo::with('type')->findOrFail($id);
}
@@ -35,6 +57,8 @@ public function store(Request $request)
'status' => 'nullable|string',
'parent' => 'nullable|string',
'object' => 'nullable|string',
'todoable_id' => 'nullable|integer',
'todoable_type' => 'nullable|string',
]);
$data['id'] = $data['id'] ?? (string) Str::uuid();
@@ -42,6 +66,19 @@ public function store(Request $request)
$data['created_at'] = $data['created_at'] ?? $now;
$data['last_modified'] = $now;
// Set the title with the todoable title if todoable_id and todoable_type are set
if (isset($data['todoable_id']) && isset($data['todoable_type'])) {
$modelName = str_replace('App\\Models\\', '', $data['todoable_type']);
$modelClass = 'App\\Models\\' . $modelName;
if (class_exists($modelClass)) {
$todoable = $modelClass::find($data['todoable_id']);
if ($todoable) {
$data['title'] = '[' . $todoable->title . '] ' . $data['title'];
}
}
}
$todo = Todo::create($data);
return response()->json($todo, 201);
@@ -63,10 +100,25 @@ public function update(Request $request, string $id)
'status' => 'nullable|string',
'parent' => 'nullable|string',
'object' => 'nullable|string',
'todoable_id' => 'nullable|integer',
'todoable_type' => 'nullable|string',
]);
$data['last_modified'] = now();
// Set the title with the todoable title if todoable_id and todoable_type are set
if (isset($data['todoable_id']) && isset($data['todoable_type'])) {
$modelName = str_replace('App\\Models\\', '', $data['todoable_type']);
$modelClass = 'App\\Models\\' . $modelName;
if (class_exists($modelClass)) {
$todoable = $modelClass::find($data['todoable_id']);
if ($todoable) {
$data['title'] = '[' . $todoable->title . '] ' . $data['title'];
}
}
}
$todo->update($data);
return response()->json($todo);