--- /dev/null
+<?php
+
+/**
+ * Bookmark short summary.
+ *
+ * Bookmark description.
+ *
+ * @version 1.0
+ * @author Ferrand
+ */
+class CommentAPI extends RestAPI {
+ use dontAllowPut, dontAllowPutCollection;
+ use dontAllowDeleteCollection;
+ use dontAllowPost;
+ use dontAllowGetCollection;
+
+ protected function GETAction() {
+ $dbh = $this->databaseHelper();
+
+ $response = $dbh->prepare('SELECT * FROM pub_Commentary
+ WHERE id = :id
+ ');
+ $response->execute(['id' => $this->element]);
+
+ if($response === false) {
+ $this->respondeError();
+ return; // end this
+ }
+
+ $row = $response->fetch(PDO::FETCH_ASSOC) ;
+ if($row === false) {
+ $this->respondeNoResult();
+ return; // end this
+ }
+
+ $serverCommentary = new ServerCommentary();
+ $serverCommentary->id = $row['id'];
+ $serverCommentary->title = $row['title'];
+ $serverCommentary->message = $row['description'];
+ $serverCommentary->mark = $row['rating'];
+ $serverCommentary->username = $row['userId'];
+ $serverCommentary->projectID = $row['projectId'];
+ $serverCommentary->creationDate = $row['creationDate'];
+
+ $this->responde(200, $serverCommentary);
+ }
+
+
+ protected function POSTCollectionAction() {
+ // TODO
+ $dbh = $this->databaseHelper();
+
+ $data = $this->getBodyData();
+ $user = $this->authentication();
+
+ /*
+ if($user === null or $user['pseudo'] !== $data->username) {
+ $this->respondeUnauthorized();
+ return; // end this!
+ }
+ */
+
+ // Attention, pour le commentaire, on peut commenter plusieurs fois
+ /*
+ $response = $dbh->prepare('SELECT * FROM pub_Commentary
+ WHERE userId = :userId and projectId = :projectId
+ ');
+ $response->execute([':userId' => $data->username, ':projectId' => $data->projectID]);
+
+ if($response === false) {
+ $this->respondeError();
+ return; // end this
+ }
+
+ $row = $response->fetch(PDO::FETCH_ASSOC) ;
+ if($row !== false) {
+ $this->respondeNotAcceptable();
+ return; // end this
+ }*/
+
+ $request = 'INSERT INTO `pub_Commentary` (
+ `id` , `creationDate`, `userId` , `projectId`,`title`, `description`, `rating` )
+ VALUES ("" , CURRENT_DATE(), :userId, :projectId, :title, :description, :rating);';
+
+ $response = $dbh->prepare($request);
+ $bool = $response->execute([
+ ':userId' => $data->username,
+ ':projectId' => $data->projectID,
+ ':title' => $data->title,
+ ':description' => $data->message,
+ ':rating' => $data->mark
+ ]);
+
+ if($response === false) { // Server/database fails
+ $this->respondeError();
+ }
+
+ $rowAffected = new RowAffected();
+ $rowAffected->id = $dbh->lastInsertId();
+
+ $this->responde(201, $rowAffected);
+ }
+
+ protected function DELETEAction() {
+
+ }
+}