Skip to content

Commit

Permalink
v2
Browse files Browse the repository at this point in the history
  • Loading branch information
williambelle committed Dec 23, 2024
1 parent 1c89bd3 commit a3d504b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
21 changes: 20 additions & 1 deletion src/controllers/semantic.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,25 @@ async function get (req, res) {
}
}

async function getv2 (req, res) {
if (appCache.has(req.originalUrl)) {
return res.send(appCache.get(req.originalUrl));
} else {
try {
const results = await semanticService.getv2(req.query);
appCache.set(req.originalUrl, results.data);
return res.json(results.data);
} catch (err) {
console.error('[error] ', err.message);
return res.status(400).json({
success: false,
error: 'Oops, something went wrong'
});
}
}
}

module.exports = {
get
get,
getv2
};
1 change: 1 addition & 0 deletions src/routes/semantic.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ const router = express.Router();
const semanticController = require('../controllers/semantic.controller');

router.get('/', semanticController.get);
router.get('/v2/', semanticController.getv2);

module.exports = router;
16 changes: 15 additions & 1 deletion src/services/semantic.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ async function get (query) {
});
}

async function getv2 (query) {
let limit = query.limit || 10;
limit = limit > 100 ? 100 : limit;

return axios.get('https://graphsearch.epfl.ch/api/v2/search/search.epfl.ch', {
params: {
q: query.q,
limit,
types: query.doctype || 'any'
}
});
}

module.exports = {
get
get,
getv2
};

0 comments on commit a3d504b

Please sign in to comment.