From 39ba41a617a7c9f5c6a1d260ff577d68e04dbbe4 Mon Sep 17 00:00:00 2001 From: "sosuke.iwabuchi" Date: Fri, 9 Jun 2023 10:14:59 +0900 Subject: [PATCH] =?UTF-8?q?=E5=A5=91=E7=B4=84=E4=B8=80=E8=A6=A7=E5=8F=96?= =?UTF-8?q?=E5=BE=97=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/ContractsController.php | 52 +++++++++++++ .../Web/Contract/ContractsParam.php | 26 +++++++ app/Repositories/ContractRepository.php | 73 +++++++++++++++++++ app/Repositories/ContractRepositoryData.php | 10 +++ routes/api.php | 6 +- 5 files changed, 166 insertions(+), 1 deletion(-) create mode 100644 app/Http/Controllers/Web/Contract/ContractsController.php create mode 100644 app/Http/Controllers/Web/Contract/ContractsParam.php create mode 100644 app/Repositories/ContractRepository.php create mode 100644 app/Repositories/ContractRepositoryData.php diff --git a/app/Http/Controllers/Web/Contract/ContractsController.php b/app/Http/Controllers/Web/Contract/ContractsController.php new file mode 100644 index 0000000..d95a419 --- /dev/null +++ b/app/Http/Controllers/Web/Contract/ContractsController.php @@ -0,0 +1,52 @@ +roleAllow(UserRole::SUPER_ADMIN); + } + + protected function getParam(): IParam + { + return $this->param; + } + + protected function run(Request $request): JsonResponse + { + $param = $this->param; + + $condition = [ + ...$param->toArray(), + ]; + + $list = $this->repository->get($condition); + + + return $this->successResponse([ + 'records' => $list + ]); + } +} diff --git a/app/Http/Controllers/Web/Contract/ContractsParam.php b/app/Http/Controllers/Web/Contract/ContractsParam.php new file mode 100644 index 0000000..18d45d4 --- /dev/null +++ b/app/Http/Controllers/Web/Contract/ContractsParam.php @@ -0,0 +1,26 @@ + $this->str(true), + Repository::CONDITION_NAME => $this->str(true), + ], + $this->sortableRules(), + ); + } +} diff --git a/app/Repositories/ContractRepository.php b/app/Repositories/ContractRepository.php new file mode 100644 index 0000000..32913f8 --- /dev/null +++ b/app/Repositories/ContractRepository.php @@ -0,0 +1,73 @@ + + */ + public function get(array $condition): Collection + { + $table = Contract::getBuilder(static::TABLE_CONTRACT); + + + // -----検索条件 + // ID + $this->where($table, $condition, static::CONDITION_ID, $this->makeColumnName([static::TABLE_CONTRACT, Contract::COL_NAME_ID])); + + // 名前 + $name = data_get($condition, static::CONDITION_NAME); + if ($name) { + $table->where($this->makeColumnName([static::TABLE_CONTRACT, Contract::COL_NAME_NAME]), 'like', "%{$name}%"); + } + + $table->select($this->columns()); + + $main = DB::table($table, "main"); + + // ソート + $this->sort($main, $condition); + $main->orderBy(static::CONDITION_ID); + + // リミット + $this->limit($main, $condition); + + + return ContractRepositoryData::makeList($main->get()); + } + + private function columns() + { + $contract = static::TABLE_CONTRACT; + $columns = [ + $this->makeColumnNameForSelect([$contract, Contract::COL_NAME_ID]), + $this->makeColumnNameForSelect([$contract, Contract::COL_NAME_NAME]), + $this->makeColumnNameForSelect([$contract, Contract::COL_NAME_UPDATED_AT]), + ]; + + + return $columns; + } +} diff --git a/app/Repositories/ContractRepositoryData.php b/app/Repositories/ContractRepositoryData.php new file mode 100644 index 0000000..5b5b3fe --- /dev/null +++ b/app/Repositories/ContractRepositoryData.php @@ -0,0 +1,10 @@ +