From 57f1b02ae3dbfa537bfe61306c04c6cf89f878c9 Mon Sep 17 00:00:00 2001 From: "sosuke.iwabuchi" Date: Wed, 28 Jun 2023 11:15:01 +0900 Subject: [PATCH] =?UTF-8?q?=E5=A5=91=E7=B4=84=E6=96=B0=E8=A6=8F=E4=BD=9C?= =?UTF-8?q?=E6=88=90=E6=A9=9F=E8=83=BD=E3=80=80=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Web/Contract/CreateController.php | 45 ++++++++++++++ .../Controllers/Web/Contract/CreateParam.php | 23 +++++++ app/Logic/Contract/ContractManager.php | 60 +++++++++++++++++++ app/Logic/Contract/CreateManager.php | 14 +++++ 4 files changed, 142 insertions(+) create mode 100644 app/Http/Controllers/Web/Contract/CreateController.php create mode 100644 app/Http/Controllers/Web/Contract/CreateParam.php create mode 100644 app/Logic/Contract/ContractManager.php create mode 100644 app/Logic/Contract/CreateManager.php diff --git a/app/Http/Controllers/Web/Contract/CreateController.php b/app/Http/Controllers/Web/Contract/CreateController.php new file mode 100644 index 0000000..2d08e64 --- /dev/null +++ b/app/Http/Controllers/Web/Contract/CreateController.php @@ -0,0 +1,45 @@ +roleAllow(UserRole::SUPER_ADMIN); + } + + protected function run(Request $request): JsonResponse + { + $param = $this->param; + + $messages = $this->manager->initForCreate() + ->fill($param->toArray()) + ->create(); + + if (count($messages) !== 0) { + return $this->failedResponse([], $messages); + } + + return $this->successResponse(); + } +} diff --git a/app/Http/Controllers/Web/Contract/CreateParam.php b/app/Http/Controllers/Web/Contract/CreateParam.php new file mode 100644 index 0000000..1af6046 --- /dev/null +++ b/app/Http/Controllers/Web/Contract/CreateParam.php @@ -0,0 +1,23 @@ + $this->str(), + Contract::COL_NAME_CUSTOM => $this->str(), + ]; + } +} diff --git a/app/Logic/Contract/ContractManager.php b/app/Logic/Contract/ContractManager.php new file mode 100644 index 0000000..2e304f2 --- /dev/null +++ b/app/Logic/Contract/ContractManager.php @@ -0,0 +1,60 @@ +contract = $contract; + $this->initialized = true; + return $this; + } + + public function initForCreate(): static + { + $contract = new Contract(); + $contract->setId(); + + $this->contract = $contract; + $this->initialized = true; + return $this; + } + + public function fill(array $attr): static + { + if (!$this->initialized) { + throw new LogicException("初期化ミス"); + } + + $this->contract->fill($attr); + return $this; + } + + public function id(): string + { + if (!$this->initialized) { + throw new LogicException("初期化ミス"); + } + return $this->contract->id; + } + + + // ----------------PROTECTED---------- + protected function save(): static + { + $this->contract->save(); + return $this; + } +} diff --git a/app/Logic/Contract/CreateManager.php b/app/Logic/Contract/CreateManager.php new file mode 100644 index 0000000..06673ca --- /dev/null +++ b/app/Logic/Contract/CreateManager.php @@ -0,0 +1,14 @@ +save(); + + return $messages; + } +}