/** * Add a new exchange rate */ public function addRate() { $data = $this->request->getJsonRawBody(); if (!is_object($data) || !isset($data->currency_code) || !isset($data->currency_name)) { $this->sendError('INVALID_PARAMS', 400); } $exists = Rate::getRate($data->currency_code); if ($exists) { $this->sendError('RATE_ALREADY_EXISTS', 400); } $rate = Rate::addRate($data); if ($rate) { $this->sendSuccess($rate); } else { $this->sendError('UNABLE_TO_SAVE_RATE', 500); } }