getAttribute('user'); if (!$user instanceof User) { $response->getBody()->write( json_encode(['error' => 'unauthenticated']) ); return $response->withStatus(401) ->withHeader('Content-Type', 'application/json'); } $queryParams = $request->getQueryParams(); $date = $queryParams['date'] ?? null; if ($date === null || $date === '') { $response->getBody()->write( json_encode(['error' => 'date is required']) ); return $response->withStatus(400) ->withHeader('Content-Type', 'application/json'); } $scheduledNodes = $getTodaysSchedule->execute( new GetTodaysScheduleRequest( date: $date, userId: $user->getId(), ) ); $data = array_values(array_map( function (ScheduledNode $scheduledNode) { return [ 'id' => $scheduledNode->getId(), 'date' => $scheduledNode->getDate()->format('Y-m-d'), 'planName' => $scheduledNode->getPlan()->getName(), 'nodeTitle' => $scheduledNode->getNode()->getTitle(), 'completed' => $scheduledNode->getCompleted(), ]; }, $scheduledNodes, )); $response->getBody()->write(json_encode($data)); return $response->withStatus(200) ->withHeader('Content-Type', 'application/json'); } }