Connect CalDAV todos to DB-Items, finish todo component and add it to pipeline items
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user