service->list($request); return TaskResource::collection($tasks)->response(); } catch (Throwable $e) { return response()->json([ 'error' => 'Service unavailable', 'message' => $e->getMessage(), ], 503); } } /** * Show the form for creating a new resource. */ public function create() { // } /** * Store a newly created resource in storage. */ public function store(StoreTaskRequest $request): JsonResponse { try { $task = $this->service->create($request->validated()); return new TaskResource($task->load('tags')) ->response() ->setStatusCode(201); } catch (Throwable $e) { return response()->json([ 'error' => 'Service unavailable', 'message' => $e->getMessage(), ], 503); } } /** * Display the specified resource. */ public function show(Task $task): JsonResponse { $task = $this->service->show($task); return new TaskResource($task->load('tags'))->response(); } /** * Show the form for editing the specified resource. */ public function edit(Task $task) { // } /** * Update the specified resource in storage. */ public function update(UpdateTaskRequest $request, Task $task): JsonResponse { try { $task = $this->service->update($task, $request->validated()); return new TaskResource($task->load('tags'))->response(); } catch (Throwable $e) { return response()->json([ 'error' => 'Service unavailable', 'message' => $e->getMessage(), ], 503); } } /** * Remove the specified resource from storage. */ public function destroy(Task $task): Response { $this->service->delete($task); return response()->noContent(); } }