feat(api/games): add GET /types endpoint
All checks were successful
Deploy to Production / deploy (push) Successful in 21s
All checks were successful
Deploy to Production / deploy (push) Successful in 21s
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
const { Game } = require('../models');
|
||||
const { cacheUtils } = require('../config/redis');
|
||||
const { sequelize } = require('../config/database');
|
||||
|
||||
/**
|
||||
* Game Controller - Quản lý trò chơi giáo dục
|
||||
@@ -393,6 +394,40 @@ class GameController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all unique game types
|
||||
*/
|
||||
async getGameTypes(req, res, next) {
|
||||
try {
|
||||
const cacheKey = 'games:types';
|
||||
|
||||
const cached = await cacheUtils.get(cacheKey);
|
||||
if (cached) {
|
||||
return res.json({
|
||||
success: true,
|
||||
data: cached,
|
||||
cached: true,
|
||||
});
|
||||
}
|
||||
|
||||
// Get distinct types
|
||||
const types = await Game.aggregate('type', 'DISTINCT', { plain: false });
|
||||
|
||||
// Format response as array of objects
|
||||
const result = types.map(t => ({ type: t.type }));
|
||||
|
||||
await cacheUtils.set(cacheKey, result, 3600);
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
data: result,
|
||||
cached: false,
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get game statistics
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user