81 lines
2.9 KiB
PHP
81 lines
2.9 KiB
PHP
<?php
|
|
namespace App\Controllers\Organization;
|
|
|
|
use App\Traits\ResponseTrait;
|
|
use App\Controllers\BaseController;
|
|
|
|
use App\Models\Organization\WorkstationModel;
|
|
|
|
class WorkstationController extends BaseController {
|
|
use ResponseTrait;
|
|
|
|
protected $db;
|
|
protected $model;
|
|
|
|
public function __construct() {
|
|
$this->db = \Config\Database::connect();
|
|
$this->model = new WorkstationModel();
|
|
}
|
|
|
|
public function index() {
|
|
$filter = [
|
|
'WorkstationCode' => $this->request->getVar('WorkstationCode'),
|
|
'WorkstationName' => $this->request->getVar('WorkstationName'),
|
|
];
|
|
$rows = $this->model->getWorkstations($filter);
|
|
|
|
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) {
|
|
$row = $this->model->getWorkstation($WorkstationID);
|
|
|
|
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 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($WorkstationID = null) {
|
|
$input = $this->request->getJSON(true);
|
|
try {
|
|
if (!$WorkstationID || !ctype_digit((string) $WorkstationID)) {
|
|
return $this->failValidationErrors('ID is required.');
|
|
}
|
|
$input['WorkstationID'] = (int) $WorkstationID;
|
|
$id = $input['WorkstationID'];
|
|
$this->model->update($id, $input);
|
|
return $this->respondCreated([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $id ], 201);
|
|
} catch (\Throwable $e) {
|
|
return $this->failServerError('Something went wrong: ' . $e->getMessage());
|
|
}
|
|
}
|
|
}
|