getPaginationParams(); $builder = $this->getDB()->table('ir'); // Search $searchType = $this->request->getGet('search_type'); $searchKeyword = $this->request->getGet('search_keyword'); if ($searchType && $searchKeyword) { if ($searchType === 'title') { $builder->like('title', $searchKeyword); } elseif ($searchType === 'name') { $builder->like('name', $searchKeyword); } elseif ($searchType === 'content') { $builder->like('content', $searchKeyword); } } $builder->orderBy('is_notice', 'DESC'); $builder->orderBy('id', 'DESC'); $result = $this->paginatedResponse($builder, $params); return $this->respondSuccess($result); } /** * Get single IR (Public) */ public function show($id = null) { $builder = $this->getDB()->table('ir'); $ir = $builder->where('id', $id)->get()->getRow(); if (!$ir) { return $this->respondError('IR 자료를 찾을 수 없습니다.', ResponseInterface::HTTP_NOT_FOUND); } // Parse file_urls JSON $ir->file_urls = json_decode($ir->file_urls ?? '[]'); // Increment view count $builder->where('id', $id)->set('views', 'views + 1', false)->update(); return $this->respondSuccess($ir); } /** * Create IR */ public function create() { $auth = $this->requireAuth(); if ($auth instanceof ResponseInterface) { return $auth; } $json = $this->request->getJSON(); $data = [ 'allow_comment' => $json->allow_comment ?? 0, 'is_notice' => $json->is_notice ?? 0, 'name' => $json->name ?? '', 'email' => $json->email ?? '', 'url' => $json->url ?? '', 'title' => $json->title ?? '', 'content' => $json->content ?? '', 'file_urls' => json_encode($json->file_urls ?? []), 'views' => 0, 'created_at' => date('Y-m-d H:i:s') ]; $builder = $this->getDB()->table('ir'); $builder->insert($data); return $this->respondSuccess(['id' => $this->getDB()->insertID()], 'IR 자료가 등록되었습니다.'); } /** * Update IR */ public function update($id = null) { $auth = $this->requireAuth(); if ($auth instanceof ResponseInterface) { return $auth; } $json = $this->request->getJSON(); $data = [ 'allow_comment' => $json->allow_comment ?? 0, 'is_notice' => $json->is_notice ?? 0, 'name' => $json->name ?? '', 'email' => $json->email ?? '', 'url' => $json->url ?? '', 'title' => $json->title ?? '', 'content' => $json->content ?? '', 'file_urls' => json_encode($json->file_urls ?? []), 'updated_at' => date('Y-m-d H:i:s') ]; $builder = $this->getDB()->table('ir'); $builder->where('id', $id)->update($data); return $this->respondSuccess(null, 'IR 자료가 수정되었습니다.'); } /** * Delete IR */ public function delete($id = null) { $auth = $this->requireAuth(); if ($auth instanceof ResponseInterface) { return $auth; } $builder = $this->getDB()->table('ir'); $builder->where('id', $id)->delete(); return $this->respondSuccess(null, 'IR 자료가 삭제되었습니다.'); } }