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 @@ +