forked from imabutahersiddik/CodeStore
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.php
More file actions
35 lines (29 loc) · 919 Bytes
/
api.php
File metadata and controls
35 lines (29 loc) · 919 Bytes
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
<?php
header('Content-Type: application/json');
require_once 'config.php';
require_once 'auth.php';
$auth = new Auth($pdo);
switch ($_GET['action']) {
case 'rate':
if (!$auth->isLoggedIn()) {
echo json_encode(['error' => 'Login required']);
exit;
}
$appId = filter_input(INPUT_POST, 'app_id', FILTER_VALIDATE_INT);
$rating = filter_input(INPUT_POST, 'rating', FILTER_VALIDATE_INT);
$comment = trim($_POST['comment'] ?? '');
try {
recordRating($pdo, $appId, $_SESSION['user_id'], $rating, $comment);
echo json_encode(['success' => true]);
} catch (Exception $e) {
echo json_encode(['error' => $e->getMessage()]);
}
break;
case 'favorite':
// Handle favoriting apps
break;
case 'report':
// Handle app reporting
break;
}
?>