[Задача 12799] Добавил контроллер для получения ссылки на редактирование

parent 4e191350
...@@ -76,6 +76,13 @@ class Typos extends CI_Controller { ...@@ -76,6 +76,13 @@ class Typos extends CI_Controller {
return; return;
} }
private function createJsonResponse($data, int $status = 200) {
$this->output
->set_content_type('application/json')
->set_status_header($status)
->set_output(json_encode($data));
}
/** /**
* Устанавливает статус опечатки, если status = 0, то опечатка отправляется * Устанавливает статус опечатки, если status = 0, то опечатка отправляется
* в архив, при этом автоматического исправления не происходит, иначе * в архив, при этом автоматического исправления не происходит, иначе
...@@ -133,10 +140,32 @@ class Typos extends CI_Controller { ...@@ -133,10 +140,32 @@ class Typos extends CI_Controller {
$response["message"] = $e->getMessage(); $response["message"] = $e->getMessage();
} }
return $this->output return $this->createJsonResponse($data);
->set_content_type('application/json') }
->set_status_header(200)
->set_output(json_encode($response)); /**
* Получает ссылку на редактирование статьи и возвращает её
*
* @return string JSON массив, по ключу editUrl находится url для редактирования статьи
*/
function getEditUrl() {
if (!$this->input->get("typoId")) {
return $this->createJsonResponse("", 400);
}
$typoId = intval($this->input->get("typoId"));
$response = [
"editUrl" => ""
];
try {
$response["editUrl"] = $this->typo->getArticleEditUrl($typoId);
} catch (Exception $e) {
log_message("error", `Failed to get article edit url: {$e->getMessage()}`);
}
return $this->createJsonResponse($response);
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment