diff --git a/app/Controllers/Contact.php b/app/Controllers/Contact/Contact.php similarity index 98% rename from app/Controllers/Contact.php rename to app/Controllers/Contact/Contact.php index e4dcbf4..5d2ba68 100644 --- a/app/Controllers/Contact.php +++ b/app/Controllers/Contact/Contact.php @@ -4,8 +4,8 @@ namespace App\Controllers; use CodeIgniter\API\ResponseTrait; use CodeIgniter\Controller; -use App\Models\ContactModel; -use App\Models\ContactDetailModel; +use App\Models\Contact\ContactModel; +use App\Models\Contact\ContactDetailModel; class Contact extends Controller { use ResponseTrait; diff --git a/app/Controllers/Occupation.php b/app/Controllers/Contact/Occupation.php similarity index 58% rename from app/Controllers/Occupation.php rename to app/Controllers/Contact/Occupation.php index 73971d4..f3cdd01 100644 --- a/app/Controllers/Occupation.php +++ b/app/Controllers/Contact/Occupation.php @@ -2,26 +2,25 @@ namespace App\Controllers; use CodeIgniter\API\ResponseTrait; -use CodeIgniter\Controller; -use App\Models\OccupationModel; +use CodeIgniter\BaseController; +use App\Models\Contact\OccupationModel; -class Occupation extends Controller { +class Occupation extends BaseController { use ResponseTrait; protected $db; - protected $modelOccupation; - protected $rulesOccupation; + protected $model; + protected $rules; public function __construct() { $this->db = \Config\Database::connect(); - $this->modelOccupation = new OccupationModel(); - $this->rulesOccupation = [ 'OccCode' => 'required','OccText' => 'required' ]; + $this->model = new OccupationModel(); + $this->rules = [ 'OccCode' => 'required','OccText' => 'required' ]; } public function index() { $model = new OccupationModel(); - $rows = $model->get()->getResultArray(); - + $rows = $model->findAll(); if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "no Data."], 200); } @@ -31,26 +30,17 @@ class Occupation extends Controller { public function show($OccupationID = null) { $model = new OccupationModel(); - $rows = $model->where('occupationID', (int) $OccupationID)->get()->getResultArray(); - + $rows = $model->find($OccupationID); if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "no Data."], 200); } - return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200); } public function create() { $input = $this->request->getJSON(true); try { - $this->db->transStart(); - $insert = $this->modelOccupation->insert($input); - $this->db->transComplete(); - - if ($this->db->transStatus() === false || !$insert) { - return $this->fail(); - } - + $insert = $this->model->insert($input); return $this->respondCreated([ 'status' => 'success', 'message' => 'data created successfully', 'data' => $input ], 201); } catch (\Throwable $e) { $this->db->transRollback(); @@ -61,18 +51,7 @@ class Occupation extends Controller { public function update() { $input = $this->request->getJSON(true); try { - if (!$this->modelOccupation->find($input['OccupationID'])) { - return $this->failNotFound('Data not found'); - } - - $this->db->transStart(); - $update = $this->modelOccupation->update($input['OccupationID'], $input); - $this->db->transComplete(); - - if ($this->db->transStatus() === false || !$insert) { - return $this->fail(); - } - + $this->modelOccupation->update($input['OccupationID'], $input); return $this->respondCreated([ 'status' => 'success', 'message' => 'Data updated successfully', 'data' => $input ], 201); } catch (\Throwable $e) { $this->db->transRollback(); diff --git a/app/Controllers/ValueSet/ValueSet.php b/app/Controllers/ValueSet/ValueSet.php index f412f0c..f0f753b 100644 --- a/app/Controllers/ValueSet/ValueSet.php +++ b/app/Controllers/ValueSet/ValueSet.php @@ -37,10 +37,7 @@ class ValueSet extends BaseController { } public function showByValueSetDef($VSetID = null) { - $rows = $this->db->table('valueset') - ->select("*") - ->where('VSetID', (int) $VSetID) - ->get()->getResultArray(); + $rows = $this->model->getValueSetByValueSetDef($VSetID); if (empty($rows)) { return $this->respond([ 'status' => 'success', 'message' => "ValueSet not found.", 'data' => [] ], 200); } diff --git a/app/Models/BaseUtcModel.php b/app/Models/BaseModel.php similarity index 95% rename from app/Models/BaseUtcModel.php rename to app/Models/BaseModel.php index c276b5b..9e3ba00 100644 --- a/app/Models/BaseUtcModel.php +++ b/app/Models/BaseModel.php @@ -4,7 +4,7 @@ namespace App\Models; use CodeIgniter\Model; -class BaseUtcModel extends Model { +class BaseModel extends Model { protected $beforeInsert = ['normalizeDatesToUTC']; protected $beforeUpdate = ['normalizeDatesToUTC']; protected $afterFind = ['convertDatesToUTCISO']; diff --git a/app/Models/ContactDetailModel.php b/app/Models/Contact/ContactDetailModel.php similarity index 94% rename from app/Models/ContactDetailModel.php rename to app/Models/Contact/ContactDetailModel.php index c70767d..5a94f5f 100644 --- a/app/Models/ContactDetailModel.php +++ b/app/Models/Contact/ContactDetailModel.php @@ -1,10 +1,10 @@ where('VSetID', (int) $VSetID)->findAll(); + return $rows; + } + + }