From 0e57b9050935c6e53e4bccb34f986b64626eff04 Mon Sep 17 00:00:00 2001 From: Yisroel Baum Date: Fri, 24 Apr 2026 10:25:53 +0300 Subject: [PATCH] add plan controller --- app/Plan/PlanController.php | 55 +++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 app/Plan/PlanController.php diff --git a/app/Plan/PlanController.php b/app/Plan/PlanController.php new file mode 100644 index 0000000..3dd6ab4 --- /dev/null +++ b/app/Plan/PlanController.php @@ -0,0 +1,55 @@ +getParsedBody(); + $userId = $data['userId'] ?? null; + $textId = $data['textId'] ?? null; + $name = $data['name'] ?? null; + $dateStart = $data['dateStart'] ?? null; + $dateEnd = $data['dateEnd'] ?? null; + + try { + $plan = $createPlanUseCase->execute(new CreatePlanRequest( + userId: $userId, + textId: $textId, + name: $name, + dateStart: $dateStart, + dateEnd: $dateEnd, + )); + } catch (BadRequestException $exception) { + $response->getBody()->write( + json_encode(['error' => $exception->getMessage()]) + ); + return $response->withStatus(400) + ->withHeader('Content-Type', 'application/json'); + } catch (DomainException $exception) { + $response->getBody()->write( + json_encode(['error' => $exception->getMessage()]) + ); + return $response->withStatus(404) + ->withHeader('Content-Type', 'application/json'); + } + + $response->getBody()->write(json_encode([ + 'id' => $plan->getId(), + 'name' => $plan->getName(), + ])); + return $response->withStatus(201) + ->withHeader('Content-Type', 'application/json'); + } +}