forked from ariadnaguitian/pixelesp-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpruebas.php
More file actions
72 lines (46 loc) · 1.58 KB
/
pruebas.php
File metadata and controls
72 lines (46 loc) · 1.58 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
65
66
67
68
69
70
71
72
<? php
//imagenes
$app->get('/imagenes', function () use ($app) {
$db = $app->db->getConnection();
$imagenes = $db->table('imagenes')->select('imagenes.*','usuarios.username')
->leftjoin('usuarios', 'usuarios.id', '=', 'imagenes.idusuario')
->orderby('created_at','desc')->get();
$app->render(200,array('data' => $imagenes));
});
$app->get('/imagenes/:id', function ($id) use ($app) {
$imagen = Image::find($id);
$imgComments = ImgComments::where('id_imagen', '=', $imagen->id)
->select('imgcomments.*','usuarios.username', 'usuarios.imagen')
->leftjoin('usuarios', 'usuarios.id', '=', 'imgcomments.idusuario')
->orderby('created_at','desc')->get();
if(empty($imgComments->toArray())){
$result = array();
} else{
$result = $imgComments->toArray();
}
$imagen->comentarios = $result;
if(empty($imagen)){
$app->render(404,array(
'error' => TRUE,
'msg' => 'imagen no encontrada',
));
}
$app->render(200,array('data' => $imagen->toArray()));
});
//comentarios de imagenes:
$app->get('/imgcomments', function () use ($app) {
$db = $app->db->getConnection();
$imgcomments = $db->table('imgcomments')->select()->orderby('created_at','desc')->get();
$app->render(200,array('data' => $imgcomments));
});
$app->get('/imgcomments/:id', function ($id) use ($app) {
$imgcomment = ImgComments::find($id);
if(empty($imgcomment)){
$app->render(404,array(
'error' => TRUE,
'msg' => 'imgcomment not found',
));
}
$app->render(200,array('data' => $imgcomment->toArray()));
});
?>