clqms-be/app/Controllers/ValueSet/ValueSetController.php
mahdahar f11bde4d30 refactor(valueset): simplify API response by removing pagination
- Remove pagination from ValueSetController::index() and ValueSetModel::getValueSets()
     - Delete duplicate AGENTS.md documentation (consolidated into CLAUDE.md)
     - Update .gitignore to exclude .claude folder
     - Add CLAUDE.md with comprehensive agent instructions for Valueset queries
     - Document new Lookups static library in README.md
2026-01-09 16:58:43 +07:00

90 lines
3.3 KiB
PHP

<?php
namespace App\Controllers\ValueSet;
use CodeIgniter\API\ResponseTrait;
use App\Controllers\BaseController;
use App\Models\ValueSet\ValueSetModel;
class ValueSetController extends BaseController {
use ResponseTrait;
protected $db;
protected $model;
protected $rules;
public function __construct() {
$this->db = \Config\Database::connect();
$this->model = new ValueSetModel;
$this->rules = [
'VSetID' => 'required',
'VValue' => 'required',
];
}
public function index() {
$param = $this->request->getVar('param');
$VSetID = $this->request->getVar('VSetID');
$data = $this->model->getValueSets($param, $VSetID);
return $this->respond([
'status' => 'success',
'message'=> "Data fetched successfully",
'data' => $data
], 200);
}
public function show($VID = null) {
$row = $this->model->getValueSet($VID);
if (empty($row)) {
return $this->respond([ 'status' => 'success', 'message' => "ValueSet with ID $VID not found.", 'data' => null ], 200);
}
return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $row], 200);
}
public function showByValueSetDef($VSetID = null) {
$rows = $this->model->getValueSetByValueSetDef($VSetID);
if (empty($rows)) {
return $this->respond([ 'status' => 'success', 'message' => "ValueSet not found.", 'data' => [] ], 200);
}
return $this->respond([ 'status' => 'success', 'message'=> "Data fetched successfully", 'data' => $rows ], 200);
}
public function create() {
$input = $this->request->getJSON(true);
if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); }
try {
$VID = $this->model->insert($input);
return $this->respondCreated([ 'status' => 'success', 'message' => "data $VID created successfully" ]);
} catch (\Exception $e) {
return $this->failServerError('Something went wrong: ' . $e->getMessage());
}
}
public function update() {
$input = $this->request->getJSON(true);
$VID = $input["VID"];
if (!$VID) { return $this->failValidationErrors('VID is required.'); }
if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors( $this->validator->getErrors() ); }
try {
$this->model->update($VID,$input);
return $this->respondCreated([ 'status' => 'success', 'message' => "data $VID updated successfully" ]);
} catch (\Exception $e) {
return $this->failServerError('Something went wrong: ' . $e->getMessage());
}
}
public function delete() {
$input = $this->request->getJSON(true);
$VID = $input["VID"];
if (!$VID) { return $this->failValidationErrors('VID is required.'); }
try {
$this->model->delete($VID);
return $this->respondDeleted(['status' => 'success', 'message' => "Data $VID deleted successfully."]);
} catch (\Throwable $e) {
return $this->failServerError('Something went wrong: ' . $e->getMessage());
}
}
}