예제 #1
0
파일: index.php 프로젝트: benjaminovak/ep
                 $filteredInput["id"] = $param;
                 $product = array_filter($filteredInput);
                 //var_dump($product);
                 try {
                     ProductsDB::update($product);
                     http_response_code(204);
                     // vračamo prazen odgovor
                 } catch (Exception $exc) {
                     echo returnError(400, $exc->getMessage());
                 }
             } else {
                 if ($http_method == "DELETE" && $param != null) {
                     try {
                         $product = ProductsDB::get(["id" => $param]);
                         if ($product != null) {
                             ProductsDB::delete(["id" => $param]);
                             http_response_code(204);
                         } else {
                             returnError(404, "No book with id {$param}");
                         }
                     } catch (Exception $exc) {
                         echo returnError(400, $exc->getMessage());
                     }
                 } else {
                     // error
                     echo returnError(404, "Unknown request: [{$http_method} {$resource}]");
                 }
             }
         }
     }
 }