Ejemplo n.º 1
0
        echo json_encode(array('status' => false, 'message' => "Product ID {$id} does not exist"));
    }
});
$app->get('/prods/:ids', function ($ids) use($app, $db) {
    $app->response->header("Content-Type", "application/json");
    $idList = explode(",", $ids);
    $prod = $db->products()->where("item_id", $idList);
    $products = array();
    foreach ($prod as $data) {
        $products[] = array('item_id' => $data['item_id'], 'item_price' => $data['item_price'], 'item_name' => $data['item_name'], 'item_desc' => $data['item_desc'], 'item_reviews' => $data['item_reviews'], 'item_rating' => $data['item_rating'], 'item_location' => $data['item_location']);
    }
    echo json_encode($products, JSON_FORCE_OBJECT);
});
$app->get('/purchases/:id', function ($id) use($app, $db) {
    $app->response()->header("Content-Type", "application/json");
    $purch = $db->purchases()->where('user_id', $id);
    $purchases = array();
    foreach ($purch as $data) {
        $purchases[] = array('id' => $data['id'], 'user_id' => $data['user_id'], 'item_id' => $data['item_id']);
    }
    echo json_encode($purchases, JSON_FORCE_OBJECT);
});
$app->get('/reviewsratings/:id', function ($id) use($app, $db) {
    $app->response()->header("Content-Type", "application/json");
    $reviews = array();
    $revs = $db->ReviewsRatings()->where('item_id', $id);
    foreach ($revs as $data) {
        $reviews[] = array('id' => $data['id'], 'user_id' => $data['user_id'], 'item_id' => $data['item_id'], 'rating' => $data['rating'], 'review' => $data['review'], 'date' => $data['date']);
    }
    echo json_encode($reviews, JSON_FORCE_OBJECT);
});