add GET /user/ai/{category}
continuous-integration/drone/push Build is failing Details

ai_support
remrem 1 year ago
parent 95003fe61c
commit 5a1ce860a8

@ -92,6 +92,23 @@ class UserGateway
return ["email" => $results[0]['email'], "username" => $results[0]['username']]; return ["email" => $results[0]['email'], "username" => $results[0]['username']];
} }
public function getModelByCategory(string $uuid, string $category)
{
$query = "SELECT model FROM trained_model WHERE user_id = :user_uuid and category = LOWER(:category);";
try {
$this->con->executeQuery($query, array(
':user_uuid' => array($uuid, PDO::PARAM_STR),
':category' => array($category, PDO::PARAM_STR)
));
$results = $this->con->getResults();
} catch (PDOException) {
return -1;
}
if (count($results) === 0) return 1;
return ["model" => $results[0]['model']];
}
public function updateMail(string $uuid, string $new_email) public function updateMail(string $uuid, string $new_email)
{ {
$query = "UPDATE user SET email=:new_email WHERE id=:uuid;"; $query = "UPDATE user SET email=:new_email WHERE id=:uuid;";

@ -40,7 +40,7 @@ return function (App $app) {
return $res; return $res;
}); });
#### ACCOUNT #### // ===== ACCOUNT =====
// Create User // Create User
$app->post('/user', function (Request $req, Response $res) { $app->post('/user', function (Request $req, Response $res) {
if (!Helpers::validJson((string) $req->getBody(), array("email", "hash", "username"))) { if (!Helpers::validJson((string) $req->getBody(), array("email", "hash", "username"))) {
@ -114,6 +114,23 @@ return function (App $app) {
return $res; return $res;
}); });
$app->get('/user/ai/{category}', function(Request $req, Response $res, $args) {
if (!(new Token)->verifyToken($req->getHeader('Authorization'))) {
return $res->withStatus(401);
}
$token = $req->getHeader('Authorization')[0];
$category = $args['category'];
$uuid = (new Token)->getUuidFromToken($token);
$code = (new UserGateway)->getModelByCategory($uuid, $category);
if($code === -1) return $res->withStatus(500);
else if($code === 1) return $res->withStatus(404);
$res->getBody()->write(json_encode($code));
return $res->withStatus(200);
});
// Update Mail // Update Mail
$app->put('/user/email', function (Request $req, Response $res) { $app->put('/user/email', function (Request $req, Response $res) {
if (!(new Token)->verifyToken($req->getHeader('Authorization'))) { if (!(new Token)->verifyToken($req->getHeader('Authorization'))) {

Loading…
Cancel
Save