diff --git a/app/Controllers/LocationController.php b/app/Controllers/LocationController.php index 24cb70e..fae89c0 100644 --- a/app/Controllers/LocationController.php +++ b/app/Controllers/LocationController.php @@ -43,8 +43,8 @@ class LocationController extends BaseController { $input = $this->request->getJSON(true); if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors($this->validator->getErrors()); } try { - $id = $this->model->saveLocation($input); - return $this->respondCreated([ 'status' => 'success', 'message' => 'data created successfully', 'data' => $id ], 201); + $result = $this->model->saveLocation($input); + return $this->respondCreated([ 'status' => 'success', 'message' => 'data created successfully', 'data' => $result ], 201); } catch (\Throwable $e) { return $this->failServerError('Something went wrong: ' . $e->getMessage()); } @@ -54,8 +54,8 @@ class LocationController extends BaseController { $input = $this->request->getJSON(true); try { if (!$this->validateData($input, $this->rules)) { return $this->failValidationErrors( $this->validator->getErrors()); } - $id = $this->model->saveLocation($input, true); - return $this->respondCreated([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $id ], 201); + $result = $this->model->saveLocation($input, true); + return $this->respondCreated([ 'status' => 'success', 'message' => 'data updated successfully', 'data' => $result ], 201); } catch (\Throwable $e) { return $this->failServerError('Something went wrong: ' . $e->getMessage()); } diff --git a/app/Database/Migrations/2025-09-10-141522_Location.php b/app/Database/Migrations/2025-09-10-141522_Location.php index ba1239c..16d8fea 100644 --- a/app/Database/Migrations/2025-09-10-141522_Location.php +++ b/app/Database/Migrations/2025-09-10-141522_Location.php @@ -24,12 +24,14 @@ class CreateLocationTable extends Migration { $this->forge->addField([ 'LocationID' => ['type' => 'INT', 'unsigned' => true], 'Street1' => ['type' => 'Varchar', 'constraint' => 255, 'null' => true], - 'Street2' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => false], + 'Street2' => ['type' => 'VARCHAR', 'constraint' => 255, 'null' => true], 'City' => ['type' => 'int', 'null' => true], 'Province' => ['type' => 'int', 'null' => true], 'PostCode' => ['type' => 'varchar', 'constraint' => 255, 'null' => true], 'GeoLocationSystem' => ['type' => 'varchar', 'constraint' => 255, 'null' => true], 'GeoLocationData' => ['type' => 'varchar', 'constraint' => 255, 'null' => true], + 'Phone' => ['type' => 'varchar', 'constraint' => 100, 'null' => true], + 'Email' => ['type' => 'varchar', 'constraint' => 150, 'null' => true], 'CreateDate' => ['type' => 'DATETIME', 'null' => true], 'EndDate' => ['type' => 'DATETIME', 'null' => true] ]); diff --git a/app/Models/Location/LocationAddressModel.php b/app/Models/Location/LocationAddressModel.php index 4684175..b6971d1 100644 --- a/app/Models/Location/LocationAddressModel.php +++ b/app/Models/Location/LocationAddressModel.php @@ -5,7 +5,8 @@ use App\Models\BaseModel; class LocationAddressModel extends BaseModel { protected $table = 'locationaddress'; protected $primaryKey = 'LocationID'; - protected $allowedFields = ['LocationID', 'Street1', 'Street2', 'City', 'Province', 'PostCode', 'GeoLocationSystem', 'GeoLocationData', 'CreateDate', 'EndDate']; + protected $allowedFields = ['LocationID', 'Street1', 'Street2', 'City', 'Province', 'PostCode', + 'GeoLocationSystem', 'GeoLocationData', 'Phone', 'Email', 'CreateDate', 'EndDate']; protected $useTimestamps = true; protected $createdField = 'CreateDate'; diff --git a/app/Models/Location/LocationModel.php b/app/Models/Location/LocationModel.php index f2696c0..569a2fe 100644 --- a/app/Models/Location/LocationModel.php +++ b/app/Models/Location/LocationModel.php @@ -50,14 +50,15 @@ class LocationModel extends BaseModel { $modelAddress->insert($data); } if ($db->transStatus() === false) { + $error = $db->error(); $db->transRollback(); - throw new \Exception('Transaction failed'); + throw new \Exception($error['message'] ?? 'Transaction failed'); } $db->transCommit(); return [ 'status' => 'success', 'LocationID' => $LocationID ]; } catch (\Throwable $e) { $db->transRollback(); - return [ 'status' => 'error', 'message' => $e->getMessage() ]; + throw $e; } } @@ -70,14 +71,15 @@ class LocationModel extends BaseModel { $this->delete($LocationID); $modelAddress->delete($LocationID); if ($db->transStatus() === false) { + $error = $db->error(); $db->transRollback(); - throw new \Exception('Transaction failed'); + throw new \Exception($error['message'] ?? 'Transaction failed'); } $db->transCommit(); return [ 'status' => 'success', 'LocationID' => $LocationID ]; } catch (\Throwable $e) { $db->transRollback(); - return [ 'status' => 'error', 'message' => $e->getMessage() ]; + throw $e; } } }