From 112e6ec3118e44941f103d311a4f8913ed57342f Mon Sep 17 00:00:00 2001 From: mahdahar <89adham@gmail.com> Date: Wed, 29 Oct 2025 11:08:38 +0700 Subject: [PATCH] add organization endpoint --- app/Config/Routes.php | 26 +++++++ app/Controllers/Organization/Department.php | 72 +++++++++++++++++++ app/Controllers/Organization/Discipline.php | 72 +++++++++++++++++++ app/Controllers/Organization/Workbench.php | 72 +++++++++++++++++++ app/Controllers/Organization/Workstation.php | 72 +++++++++++++++++++ .../2025-10-12-100001_Ref_Range.php | 2 +- .../2025-10-23-110105_Organization.php | 2 +- .../2025-10-29-100201_Equipment.php | 65 +++++++++++++++++ app/Models/Organization/DepartmentModel.php | 16 +++++ app/Models/Organization/DisciplineModel.php | 16 +++++ app/Models/Organization/WorkbenchModel.php | 16 +++++ app/Models/Organization/WorkstationModel.php | 17 +++++ 12 files changed, 446 insertions(+), 2 deletions(-) create mode 100644 app/Controllers/Organization/Department.php create mode 100644 app/Controllers/Organization/Discipline.php create mode 100644 app/Controllers/Organization/Workbench.php create mode 100644 app/Controllers/Organization/Workstation.php create mode 100644 app/Database/Migrations/2025-10-29-100201_Equipment.php create mode 100644 app/Models/Organization/DepartmentModel.php create mode 100644 app/Models/Organization/DisciplineModel.php create mode 100644 app/Models/Organization/WorkbenchModel.php create mode 100644 app/Models/Organization/WorkstationModel.php diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 6437007..bc30f0b 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -94,6 +94,32 @@ $routes->post('/api/containerdef', 'Specimen\ContainerDef::create'); $routes->patch('/api/containerdef', 'Specimen\ContainerDef::update'); $routes->delete('/api/containerdef', 'Specimen\ContainerDef::delete'); +//organization +// discipline +$routes->get('/api/organization/discipline/', 'Organization\Discipline::index'); +$routes->get('/api/organization/discipline/(:num)', 'Organization\Discipline::show/$1'); +$routes->post('/api/organization/discipline', 'Organization\Discipline::create'); +$routes->patch('/api/organization/discipline', 'Organization\Discipline::update'); +$routes->delete('/api/organization/discipline', 'Organization\Discipline::delete'); +// department +$routes->get('/api/organization/department/', 'Organization\Department::index'); +$routes->get('/api/organization/department/(:num)', 'Organization\Department::show/$1'); +$routes->post('/api/organization/department', 'Organization\Department::create'); +$routes->patch('/api/organization/department', 'Organization\Department::update'); +$routes->delete('/api/organization/department', 'Organization\Department::delete'); +// workstation +$routes->get('/api/organization/workstation/', 'Organization\Workstation::index'); +$routes->get('/api/organization/workstation/(:num)', 'Organization\Workstation::show/$1'); +$routes->post('/api/organization/workstation', 'Organization\Workstation::create'); +$routes->patch('/api/organization/workstation', 'Organization\Workstation::update'); +$routes->delete('/api/organization/workstation', 'Organization\Workstation::delete'); +// workbench +$routes->get('/api/organization/workbench/', 'Organization\Workbench::index'); +$routes->get('/api/organization/workbench/(:num)', 'Organization\Workbench::show/$1'); +$routes->post('/api/organization/workbench', 'Organization\Workbench::create'); +$routes->patch('/api/organization/workbench', 'Organization\Workbench::update'); +$routes->delete('/api/organization/workbench', 'Organization\Workbench::delete'); + // Khusus $routes->get('/api/zones', 'Zones::index'); $routes->get('/api/zones/synchronize', 'Zones::synchronize'); diff --git a/app/Controllers/Organization/Department.php b/app/Controllers/Organization/Department.php new file mode 100644 index 0000000..e929f61 --- /dev/null +++ b/app/Controllers/Organization/Department.php @@ -0,0 +1,72 @@ +db = \Config\Database::connect(); + $this->model = new DepartmentModel(); + } + + public function index() { + $rows = $this->model->findAll(); + + if (empty($rows)) { + return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); + } + + return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200); + } + + public function show($DepartmentID = null) { + $rows = $this->model->where('DepartmentID', $DepartmentID)->findAll(); + + if (empty($rows)) { + return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); + } + + return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200); + } + + public function delete() { + try { + $input = $this->request->getJSON(true); + $id = $input["DepartmentID"]; + if (!$id) { return $this->failValidationErrors('ID is required.'); } + $this->model->delete($id); + return $this->respondDeleted([ 'status' => 'success', 'message' => "{$id} deleted successfully."]); + } catch (\Throwable $e) { + return $this->failServerError('Something went wrong: ' . $e->getMessage()); + } + } + + public function create() { + $input = $this->request->getJSON(true); + try { + $id = $this->model->insert($input,true); + return $this->respondCreated([ 'status' => 'success', 'message' => 'data created successfully', 'data' => $id ], 201); + } catch (\Throwable $e) { + return $this->failServerError('Something went wrong: ' . $e->getMessage()); + } + } + + public function update() { + $input = $this->request->getJSON(true); + try { + $id = $input['DepartmentID']; + $this->model->where('DepartmentID', $id)->update(); + return $this->respondCreated([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $id ], 201); + } catch (\Throwable $e) { + return $this->failServerError('Something went wrong: ' . $e->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/Controllers/Organization/Discipline.php b/app/Controllers/Organization/Discipline.php new file mode 100644 index 0000000..72c47cc --- /dev/null +++ b/app/Controllers/Organization/Discipline.php @@ -0,0 +1,72 @@ +db = \Config\Database::connect(); + $this->model = new DisciplineModel(); + } + + public function index() { + $rows = $this->model->findAll(); + + if (empty($rows)) { + return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); + } + + return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200); + } + + public function show($DisciplineID = null) { + $rows = $this->model->where('DisciplineID', $DisciplineID)->findAll(); + + if (empty($rows)) { + return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); + } + + return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200); + } + + public function delete() { + try { + $input = $this->request->getJSON(true); + $id = $input["DisciplineID"]; + if (!$id) { return $this->failValidationErrors('ID is required.'); } + $this->model->delete($id); + return $this->respondDeleted([ 'status' => 'success', 'message' => "{$id} deleted successfully."]); + } catch (\Throwable $e) { + return $this->failServerError('Something went wrong: ' . $e->getMessage()); + } + } + + public function create() { + $input = $this->request->getJSON(true); + try { + $id = $this->model->insert($input,true); + return $this->respondCreated([ 'status' => 'success', 'message' => 'data created successfully', 'data' => $id ], 201); + } catch (\Throwable $e) { + return $this->failServerError('Something went wrong: ' . $e->getMessage()); + } + } + + public function update() { + $input = $this->request->getJSON(true); + try { + $id = $input['DisciplineID']; + $this->model->where('DisciplineID', $id)->update(); + return $this->respondCreated([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $id ], 201); + } catch (\Throwable $e) { + return $this->failServerError('Something went wrong: ' . $e->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/Controllers/Organization/Workbench.php b/app/Controllers/Organization/Workbench.php new file mode 100644 index 0000000..ed227e9 --- /dev/null +++ b/app/Controllers/Organization/Workbench.php @@ -0,0 +1,72 @@ +db = \Config\Database::connect(); + $this->model = new WorkbenchModel(); + } + + public function index() { + $rows = $this->model->findAll(); + + if (empty($rows)) { + return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); + } + + return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200); + } + + public function show($WorkbenchID = null) { + $rows = $this->model->where('WorkbenchID', $WorkbenchID)->findAll(); + + if (empty($rows)) { + return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); + } + + return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200); + } + + public function delete() { + try { + $input = $this->request->getJSON(true); + $id = $input["WorkbenchID"]; + if (!$id) { return $this->failValidationErrors('ID is required.'); } + $this->model->delete($id); + return $this->respondDeleted([ 'status' => 'success', 'message' => "{$id} deleted successfully."]); + } catch (\Throwable $e) { + return $this->failServerError('Something went wrong: ' . $e->getMessage()); + } + } + + public function create() { + $input = $this->request->getJSON(true); + try { + $id = $this->model->insert($input,true); + return $this->respondCreated([ 'status' => 'success', 'message' => 'data created successfully', 'data' => $id ], 201); + } catch (\Throwable $e) { + return $this->failServerError('Something went wrong: ' . $e->getMessage()); + } + } + + public function update() { + $input = $this->request->getJSON(true); + try { + $id = $input['WorkbenchID']; + $this->model->where('WorkbenchID', $id)->update(); + return $this->respondCreated([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $id ], 201); + } catch (\Throwable $e) { + return $this->failServerError('Something went wrong: ' . $e->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/Controllers/Organization/Workstation.php b/app/Controllers/Organization/Workstation.php new file mode 100644 index 0000000..8c5df3d --- /dev/null +++ b/app/Controllers/Organization/Workstation.php @@ -0,0 +1,72 @@ +db = \Config\Database::connect(); + $this->model = new WorkstationModel(); + } + + public function index() { + $rows = $this->model->findAll(); + + if (empty($rows)) { + return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); + } + + return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200); + } + + public function show($WorkstationID = null) { + $rows = $this->model->where('WorkstationID', $WorkstationID)->findAll(); + + if (empty($rows)) { + return $this->respond([ 'status' => 'success', 'message' => "no Data.", 'data' => [] ], 200); + } + + return $this->respond([ 'status' => 'success', 'message'=> "fetch success", 'data' => $rows ], 200); + } + + public function delete() { + try { + $input = $this->request->getJSON(true); + $id = $input["WorkstationID"]; + if (!$id) { return $this->failValidationErrors('ID is required.'); } + $this->model->delete($id); + return $this->respondDeleted([ 'status' => 'success', 'message' => "{$id} deleted successfully."]); + } catch (\Throwable $e) { + return $this->failServerError('Something went wrong: ' . $e->getMessage()); + } + } + + public function create() { + $input = $this->request->getJSON(true); + try { + $id = $this->model->insert($input,true); + return $this->respondCreated([ 'status' => 'success', 'message' => 'data created successfully', 'data' => $id ], 201); + } catch (\Throwable $e) { + return $this->failServerError('Something went wrong: ' . $e->getMessage()); + } + } + + public function update() { + $input = $this->request->getJSON(true); + try { + $id = $input['WorkstationID']; + $this->model->where('WorkstationID', $id)->update(); + return $this->respondCreated([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $id ], 201); + } catch (\Throwable $e) { + return $this->failServerError('Something went wrong: ' . $e->getMessage()); + } + } +} \ No newline at end of file diff --git a/app/Database/Migrations/2025-10-12-100001_Ref_Range.php b/app/Database/Migrations/2025-10-12-100001_Ref_Range.php index 6818568..9c98e6d 100644 --- a/app/Database/Migrations/2025-10-12-100001_Ref_Range.php +++ b/app/Database/Migrations/2025-10-12-100001_Ref_Range.php @@ -4,7 +4,7 @@ namespace App\Database\Migrations; use CodeIgniter\Database\Migration; -class CreateTestsTable extends Migration { +class CreateRefRangesTable extends Migration { public function up() { $this->forge->addField([ diff --git a/app/Database/Migrations/2025-10-23-110105_Organization.php b/app/Database/Migrations/2025-10-23-110105_Organization.php index 9ed53e0..34fe3ba 100644 --- a/app/Database/Migrations/2025-10-23-110105_Organization.php +++ b/app/Database/Migrations/2025-10-23-110105_Organization.php @@ -13,7 +13,7 @@ class Organization extends Migration { 'CreateDate' => ['type'=>'DATETIME', 'null' => true], 'EndDate' => ['type'=>'DATETIME', 'null' => true] ]); - $this->forge->addKey('DiciplineID', true); + $this->forge->addKey('DisciplineID', true); $this->forge->createTable('discipline'); $this->forge->addField([ diff --git a/app/Database/Migrations/2025-10-29-100201_Equipment.php b/app/Database/Migrations/2025-10-29-100201_Equipment.php new file mode 100644 index 0000000..1ff7bd1 --- /dev/null +++ b/app/Database/Migrations/2025-10-29-100201_Equipment.php @@ -0,0 +1,65 @@ +forge->addField([ + 'EquipmentID' => ['type' => 'int', 'unsigned' => true, 'auto_increment'=> true], + 'DepartmentID' => ['type' => 'int', 'constraint'=> 10, 'null'=> false], + 'InstrumentID' => ['type' => 'varchar', 'constraint'=> 150, 'null'=> true], + 'InstrumentName' => ['type' => 'varchar', 'constraint'=> 150, 'null'=> true], + 'Enable' => ['type' => 'bit', 'null'=> false], + 'EquipmentRole' => ['type' => 'varchar', 'constraint' => 1, 'null'=> false], + 'CreateDate' => ['type'=>'DATETIME', 'null' => true], + 'EndDate' => ['type'=>'DATETIME', 'null' => true] + ]); + $this->forge->addKey('EquipmentID', true); + $this->forge->createTable('equipmentlist'); + + $this->forge->addField([ + 'InterfaceID' => ['type' => 'int', 'unsigned' => true, 'auto_increment'=> true], + 'InstrumentID' => ['type' => 'int', 'null'=> false], + 'SiteID' => ['type' => 'int', 'null'=> true], + 'InterfaceName' => ['type' => 'varchar', 'constraint'=> 150, 'null'=> true], + 'InterfaceDesc' => ['type' => 'varchar', 'constraint'=> 150, 'null'=> true], + 'Protocol' => ['type' => 'varchar', 'constraint'=> 50, 'null'=> true], + 'IPAddress' => ['type' => 'varchar', 'constraint'=> 50, 'null'=> true], + 'Port' => ['type' => 'varchar', 'constraint'=> 25, 'null'=> true], + 'COM' => ['type' => 'varchar', 'constraint'=> 5, 'null'=> true], + 'Baud' => ['type' => 'varchar', 'constraint'=> 10, 'null'=> true], + 'Data' => ['type' => 'varchar', 'constraint'=> 10, 'null'=> true], + 'Parity' => ['type' => 'varchar', 'constraint'=> 10, 'null'=> true], + 'Stop' => ['type' => 'varchar', 'constraint'=> 10, 'null'=> true], + 'CreateDate' => ['type'=>'DATETIME', 'null' => true], + 'EndDate' => ['type'=>'DATETIME', 'null' => true] + ]); + $this->forge->addKey('InterfaceID', true); + $this->forge->createTable('comparameters'); + + $this->forge->addField([ + 'EquipmentID' => ['type' => 'int', 'unsigned' => true, 'auto_increment'=> true], + 'DeviceName' => ['type' => 'varchar', 'constraint' => 50,'null'=> false], + 'Description' => ['type' => 'varchar', 'constraint' => 50,'null'=> false], + 'SiteID' => ['type' => 'int', 'null'=> true], + 'LocationID' => ['type' => 'int', 'null'=> true], + 'DIDType' => ['type' => 'varchar', 'constraint'=>10, 'null'=> true], + 'DID' => ['type' => 'varchar', 'constraint'=>100, 'null'=> true], + 'MachineID' => ['type' => 'varchar', 'constraint'=>100, 'null'=> true], + 'IPAddress' => ['type' => 'varchar', 'constraint'=>25, 'null'=> true], + 'CreateDate' => ['type'=>'DATETIME', 'null' => true], + 'EndDate' => ['type'=>'DATETIME', 'null' => true] + ]); + $this->forge->addKey('EquipmentID', true); + $this->forge->createTable('devicelist'); + + } + + public function down() { + $this->forge->dropTable('equipmentlist', true); + $this->forge->dropTable('comparameters', true); + $this->forge->dropTable('devicelist', true); + } +} diff --git a/app/Models/Organization/DepartmentModel.php b/app/Models/Organization/DepartmentModel.php new file mode 100644 index 0000000..30cb2fb --- /dev/null +++ b/app/Models/Organization/DepartmentModel.php @@ -0,0 +1,16 @@ +