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; + } +}