branchCategory = new BranchCategory(); $this->db = Config::connect(); } public function index() { try { $data = $this->branchCategory->findAll(); if (!empty($data)) return $this->respond(['status' => 200, 'message' => 'OK', 'result' => $data], 200); return $this->respond(['status' => 200, 'message' => 'No branch categories found'], 200); } catch (\Exception $e) { return $this->respond(['status' => 500, 'message' => 'Server error'], 500); } } public function show($id = null) { try { $item = $this->branchCategory->find($id); if ($item) return $this->respond(['status' => 200, 'message' => 'OK', 'result' => $item], 200); return $this->respond(['status' => 404, 'message' => 'Branch Category not found'], 404); } catch (\Exception $e) { return $this->respond(['status' => 500, 'message' => 'Server error'], 500); } } public function create() { try { $payload = $this->request->getJSON(true); $id = $this->branchCategory->insert($payload); if ($id) return $this->respond(['status' => 201, 'message' => 'Branch Category created', 'result' => ['id' => $id]], 201); return $this->respond(['status' => 400, 'message' => 'Failed to create Branch Category'], 400); } catch (\Exception $e) { return $this->respond(['status' => 500, 'message' => 'Server error'], 500); } } public function update($id = null) { try { if (!$this->branchCategory->find($id)) return $this->respond(['status' => 404, 'message' => 'Branch Category not found'], 404); $payload = $this->request->getJSON(true); if ($this->branchCategory->update($id, $payload)) return $this->respond(['status' => 200, 'message' => 'Branch Category updated'], 200); return $this->respond(['status' => 400, 'message' => 'Failed to update Branch Category'], 400); } catch (\Exception $e) { return $this->respond(['status' => 500, 'message' => 'Server error'], 500); } } public function delete($id = null) { try { if (!$this->branchCategory->find($id)) return $this->respond(['status' => 404, 'message' => 'Branch Category not found'], 404); if ($this->branchCategory->delete($id)) return $this->respond(['status' => 200, 'message' => 'Branch Category deleted'], 200); return $this->respond(['status' => 400, 'message' => 'Failed to delete Branch Category'], 400); } catch (\Exception $e) { return $this->respond(['status' => 500, 'message' => 'Server error'], 500); } } }