Преглед на файлове

API finalisée (nofake)

Brendan Abolivier преди 9 години
родител
ревизия
ff8b71cb5f

web/api/view/palmares.php → web/api/controller/palmares.php Целия файл

@@ -1,6 +1,12 @@
1 1
 <?php
2 2
 
3
-try {
3
+if(!empty($_GET['login']) && !empty($_GET['score'])) {
4
+	Score::add($_GET['login'], $_GET['score']);
5
+	$scArray = array(
6
+		"status" => 1,
7
+		"message" => "score_add_success"
8
+	);
9
+} else {
4 10
 	$scores = Score::getScores(10);
5 11
 	$scArray = array();
6 12
 	for($i = 0; $i < sizeof($scores); $i++) {
@@ -9,6 +15,4 @@ try {
9 15
 			"score" => $scores[$i]->getScore()
10 16
 		));
11 17
 	}
12
-}catch(Exception $e) {
13
-	echo json_encode(array("erreur" => $e->getMessage()));
14 18
 }

web/api/view/questions.php → web/api/controller/questions.php Целия файл


+ 32
- 8
web/api/index.php Целия файл

@@ -4,12 +4,36 @@ require_once('model/classes.php');
4 4
 
5 5
 header("Content-Type:application/json");
6 6
 
7
-if(!empty($_GET['page'])) {
8
-  if($_GET['page'] == "palmares") {
9
-    include("view/palmares.php");
10
-    echo json_encode($scArray);
11
-  }
12
-} else {
13
-  include("view/questions.php");
14
-	echo json_encode($categories);
7
+try {
8
+	if(!empty($_GET['page'])) {
9
+		if($_GET['page'] == "palmares") {
10
+			if(include("controller/palmares.php")) {
11
+				$scArray["status"] = 1;
12
+				echo json_encode($scArray);
13
+			} else {
14
+				echo json_encode(array(
15
+					"status" => 0,
16
+					"source" => "root",
17
+					"message" => "Erreur d'inclusion"
18
+				));
19
+			}
20
+		}
21
+	} else {
22
+		if(include("controller/questions.php")) {
23
+			$categories["status"] = 1;
24
+			echo json_encode($categories);
25
+		} else {
26
+			echo json_encode(array(
27
+				"status" => 0,
28
+				"source" => "root",
29
+				"message" => "Erreur d'inclusion"
30
+			));
31
+		}
32
+	}
33
+} catch(Exception $e) {
34
+	echo json_encode(array(
35
+		"status" => 0,
36
+		"source" => $e->getTrace()[0]["class"],
37
+		"message" => $e->getMessage()
38
+	));
15 39
 }

+ 1
- 1
web/api/model/class.categorie.php Целия файл

@@ -4,7 +4,7 @@ class Categorie {
4 4
 	private $bdd;
5 5
 	private $nomCat;
6 6
 	private $questsets;
7
-	
7
+
8 8
 	function __construct($nomCat) {
9 9
 		$this->bdd = new Connector();
10 10
 		$this->selectCat($nomCat);

+ 5
- 9
web/api/model/class.connector.php Целия файл

@@ -34,8 +34,7 @@ class Connector {
34 34
 				$whereClause = " $upName ";
35 35
 				foreach($value as $array) {
36 36
 					if(sizeof($array) != 3) {
37
-						throw new Exception('Nombre de paramètres incorrect (WHERE). Les paramètres passés sont : '
38
-							.implode(',',$array));
37
+						throw new Exception('wrong_arg_nmbr_where');
39 38
 					}
40 39
 
41 40
 					$whereClause .= $array[0]." ".$array[1]." :".$array[0]." AND ";
@@ -44,8 +43,7 @@ class Connector {
44 43
 				$request .= substr($whereClause, 0, -5);
45 44
 			} else if(($upName = strtoupper($name)) == "ORDER BY") {
46 45
 				if(sizeof($value) != 2 && substr($value[0], -2) != "()") {
47
-					throw new Exception('Nombre de paramètres incorrects (ORDER BY). Les paramètres passés sont : '
48
-						.implode(',', $value));
46
+					throw new Exception('wrong_arg_nmbr_order_by');
49 47
 				}
50 48
 
51 49
 				$request .= " ".$upName." ".implode(' ', $value);
@@ -57,11 +55,10 @@ class Connector {
57 55
 					// La colonne "limit" contient un index de départ et un nombre de champs
58 56
 					$request .= " $upName ".$value[0].",".$value[1];
59 57
 				} else {
60
-					throw new Exception('Nombre de paramètres incorrects (LIMIT). Les paramètres passés sont : '
61
-						.implode(',', $value));
58
+					throw new Exception('wrong_arg_numbr_limit');
62 59
 				}
63 60
 			} else {
64
-				throw new Exception('Argument '.strtoupper($name).' inconnu');
61
+				throw new Exception('unknown_arg');
65 62
 			}
66 63
 		}
67 64
 
@@ -99,10 +96,9 @@ class Connector {
99 96
 			array_push($arrayVerif, $value);
100 97
 		}
101 98
 		$request = substr($request, 0, -1)." WHERE ";
102
-		var_dump($request);
103 99
 		foreach($update['where'] as $value) {
104 100
 			$request .= $value[0].$value[1]."? AND ";
105
-			array_push($arrayVerif, $value[2]);			
101
+			array_push($arrayVerif, $value[2]);
106 102
 		}
107 103
 		$request = substr($request, 0, -5);
108 104
 

+ 2
- 0
web/api/model/class.score.php Целия файл

@@ -69,6 +69,8 @@ class Score {
69 69
           "set" => array("score" => $score)
70 70
         );
71 71
         $bdd->Update("scores", $update);
72
+      } else {
73
+        throw new Exception('higher_score_present');
72 74
       }
73 75
     }
74 76
   }

+ 1
- 5
web/api/tests.php Целия файл

@@ -2,8 +2,4 @@
2 2
 
3 3
 require_once('model/classes.php');
4 4
 
5
-try {
6
-	Score::add("Yolo", 200);
7
-}catch(Exception $e) {
8
-	echo("Erreur : ".$e->getMessage());
9
-}
5
+Score::add("Yolo", 200);