From 5b3323185fe6f34662660f3407a6bac483cfe89d Mon Sep 17 00:00:00 2001 From: ghost Date: Fri, 31 Dec 2021 01:21:14 +0200 Subject: [PATCH] implement follow feature --- src/application/controller/api/follow/add.php | 27 +++++++++++++++++++ .../controller/api/follow/delete.php | 4 +-- src/bootstrap.php | 3 +++ 3 files changed, 31 insertions(+), 3 deletions(-) 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;