Exemple #1
0
        return ResultWrapper::getResult(Comment::getByPromo($promoId, $page), $response);
    } catch (Exception $e) {
        return ResultWrapper::getError($e->getMessage(), $response);
    }
});
$app->get("/comment-user/{userId}/{page}", function (Request $request, Response $response, $userId, $page) {
    try {
        return ResultWrapper::getResult(Comment::getByUser($userId, $page), $response);
    } catch (Exception $e) {
        return ResultWrapper::getError($e->getMessage(), $response);
    }
});
$app->delete('/comment/{id}', function (Request $request, Response $response, $id) {
    try {
        $token = $request->getHeader('token');
        return ResultWrapper::getResult(Comment::del($token, $id), $response);
    } catch (Exception $e) {
        return ResultWrapper::getError($e->getMessage(), $response);
    }
});
//For scraping data from the website only
$app->get('/scrap-data/{category}/{page}', function (Request $request, Response $response, $category, $page) {
    try {
        return ResultWrapper::getResult(Scraper::scrapListPromo($category, $page), $response);
    } catch (Exception $e) {
        return ResultWrapper::getError($e->getMessage(), $response);
    }
});
$app->get('/fill-empty-desc', function (Request $request, Response $response) {
    try {
        return ResultWrapper::getResult(Scraper::fillDescriptionPromo(), $response);
 public static function del($token, $id)
 {
     if ($token == null or $token == "") {
         throw new \Exception("Session expired, please re-login");
     }
     $userId = User::query()->where('token', '=', $token)->first()->id;
     if ($userId == null or $userId == "") {
         throw new \Exception("Session expired, please re-login");
     }
     $comment = Comment::find($id);
     if ($comment == null) {
         throw new \Exception("Invalid comment item");
     }
     if ($comment->delete()) {
         return "Comment item has ben deleted";
     } else {
         return "Error while deleting comment";
     }
 }