-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.php
More file actions
66 lines (43 loc) · 1.43 KB
/
api.php
File metadata and controls
66 lines (43 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
require_once 'vendor/autoload.php';
require 'database.php';
$app = new \Slim\Slim();
$recipes=\Cocktails\RecipesPopularityQuery::create();
$app->response;
$app->get("/v1/recipes/popular/:how_many",function($how_many) use ($app,$recipes){
$populars = $recipes
->orderByFavorited("desc")
->limit($how_many)
->find()
->toJson();
echo $populars;
});
$app->put("/v1/recipes/favorite/:url",function($url) use ($recipes,$app){
$request = $app->request;
$getfavorite = $recipes->findByUrl($url);
if ( $getfavorite != null ) {
$getfavorite = $recipes->findOneByUrl($url);
$qtyFavorite=$getfavorite->getFavorited()+1;
$getfavorite->setFavorited($qtyFavorite);
$getfavorite->save();
} else {
$getfavorite->setUrl($url);
$getfavorite->setTitle($request->params("title"));
$getfavorite->save();
}
});
$app->put("/v1/recipes/unfavorite/:id",function($id) use ($recipes,$app){
$getfavorite = $recipes->findOneByRecipeId($id);
if ( $getfavorite != null ) {
$qtyFavorite = $getfavorite->getFavorited() - 1;
$getfavorite->setFavorited($qtyFavorite);
$getfavorite->save();
}else {
$app->notFound();
}
});
//$app->delete("/v1/recipes/favorite/:id",function($id) use ($recipes,$app){
// $getfavorite = $recipes->findOneByRecipeId($id);
// $getfavorite->delete();
//});
$app->run();