- Create App\Traits\ResponseTrait that wraps CodeIgniter\API\ResponseTrait - Add json_helper with convert_empty_strings_to_null() and prepare_json_response() functions - Replace all imports of CodeIgniter\API\ResponseTrait with App\Traits\ResponseTrait across all controllers - Add 'json' helper to BaseController helpers array - Ensure consistent API response formatting across the application
65 lines
2.2 KiB
PHP
65 lines
2.2 KiB
PHP
<?php
|
|
namespace App\Controllers\Contact;
|
|
|
|
use App\Traits\ResponseTrait;
|
|
use App\Controllers\BaseController;
|
|
use App\Models\Contact\MedicalSpecialtyModel;
|
|
|
|
class MedicalSpecialtyController extends BaseController {
|
|
use ResponseTrait;
|
|
|
|
protected $db;
|
|
protected $model;
|
|
protected $rules;
|
|
|
|
public function __construct() {
|
|
$this->db = \Config\Database::connect();
|
|
$this->model = new MedicalSpecialtyModel();
|
|
$this->rules = [ 'SpecialtyText' => 'required' ];
|
|
}
|
|
|
|
public function index() {
|
|
$Parent = $this->request->getVar('Parent');
|
|
$SpecialtyText = $this->request->getVar('SpecialtyText');
|
|
$rows = $this->model->getOccupations($Parent,$SpecialtyText);
|
|
|
|
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 show($SpecialtyID = null) {
|
|
$model = new MedicalSpecialtyModel();
|
|
$row = $model->find($SpecialtyID);
|
|
if (empty($row)) {
|
|
return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => null], 200);
|
|
}
|
|
return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $row ], 200);
|
|
}
|
|
|
|
public function create() {
|
|
$input = $this->request->getJSON(true);
|
|
try {
|
|
$this->model->insert($input);
|
|
$id = $this->model->getInsertID();
|
|
return $this->respondCreated([ 'status' => 'success', 'message' => 'data created successfully', 'data' => $id ], 201);
|
|
} catch (\Throwable $e) {
|
|
$this->db->transRollback();
|
|
return $this->failServerError('Exception : ' . $e->getMessage());
|
|
}
|
|
}
|
|
|
|
public function update() {
|
|
$input = $this->request->getJSON(true);
|
|
try {
|
|
$this->model->update($input['SpecialtyID'], $input);
|
|
return $this->respondCreated([ 'status' => 'success', 'message' => 'Data updated successfully', 'data' => $input['SpecialtyID'] ], 201);
|
|
} catch (\Throwable $e) {
|
|
return $this->failServerError('Exception : ' . $e->getMessage());
|
|
}
|
|
}
|
|
|
|
}
|