diff --git a/src/application/controller/api/follow/add.php b/src/application/controller/api/follow/add.php index e69de29..baebf34 100644 --- a/src/application/controller/api/follow/add.php +++ b/src/application/controller/api/follow/add.php @@ -0,0 +1,27 @@ + false, + 'message' => _('Internal server error'), +]; + +if (isset($_SESSION['userName']) && isset($_POST['userName'])) { + + $result = $_twister->follow($_SESSION['userName'], [$_POST['userName']]); + + $response = [ + 'success' => true, + 'message' => _('Followed successfully'), + ]; + +} else { + + $response = [ + 'success' => false, + 'message' => _('Session expired. Please, reload the page.'), + ]; + +} + +header('Content-Type: application/json; charset=utf-8'); +echo json_encode($response); \ No newline at end of file diff --git a/src/application/controller/api/follow/delete.php b/src/application/controller/api/follow/delete.php index 963e1da..45ae9cf 100644 --- a/src/application/controller/api/follow/delete.php +++ b/src/application/controller/api/follow/delete.php @@ -5,9 +5,7 @@ $response = [ 'message' => _('Internal server error'), ]; -if (isset($_SESSION['userName'])) { - - $userName = isset($_POST['userName']) ? $_POST['userName'] : false; +if (isset($_SESSION['userName']) && isset($_POST['userName'])) { $result = $_twister->unFollow($_SESSION['userName'], [$_POST['userName']]); diff --git a/src/bootstrap.php b/src/bootstrap.php index b803c51..eb0012d 100644 --- a/src/bootstrap.php +++ b/src/bootstrap.php @@ -79,6 +79,9 @@ if (isset($_GET['_route_'])) { case 'api/follow/get': require(PROJECT_DIR . '/application/controller/api/follow/get.php'); break; + case 'api/follow/add': + require(PROJECT_DIR . '/application/controller/api/follow/add.php'); + break; case 'api/follow/delete': require(PROJECT_DIR . '/application/controller/api/follow/delete.php'); break;