Exemple #1
0
                verifyXsrf();
                $requestContent = file_get_contents("php://input");
                $requestObject = json_decode($requestContent);
                $follow = new Follower($requestObject->followerFollowerId, $requestObject->followerFollowedId);
                $follow->insert($pdo);
                $tempName = Profile::getProfilebyProfileId($pdo, $requestObject->followerFollowedId)->getProfileHandle();
                $reply->message = "You are now following " . $tempName;
            } elseif ($method === "DELETE") {
                $follower = Follower::getFollowerByFollowerIdAndFollowedId($pdo, $followerFollowerId, $followerFollowedId);
                if ($follower === null) {
                    throw new \RuntimeException("relationship does not exist", 404);
                }
                if ($_SESSION["profile"]->getProfileId() !== $follower->getFollowerFollowerId()) {
                    throw new \RuntimeException("Only the follower can stop following.");
                }
                $tempName = Profile::getProfilebyProfileId($pdo, $follower->getFollowerFollowedId())->getProfileHandle();
                $follower->delete($pdo);
                $deletedObject = new stdClass();
                $deletedObject->followerFollowerId = $followerFollowerId;
                $deletedObject->followerFollowedId = $followerFollowedId;
                $reply->message = "You are no longer following " . $tempName;
            }
        } elseif (empty($method) === false && $method !== "GET") {
            //If a non-admin attempted to access anything other than GET, throw an error at them
            throw new \RuntimeException("Only administrators are allowed to modify entries", 401);
        }
    }
} catch (Exception $exception) {
    $reply->status = $exception->getCode();
    $reply->message = $exception->getMessage();
}