Add endpoint to retrieve all available languages in VocabController and VocabRouter

- Introduced a new method in VocabService to list all languages from the database.
- Updated VocabController to wrap the new method for user access.
- Added a new route in VocabRouter to handle requests for all languages.
- Modified VocabCourseListView to utilize the new endpoint for loading languages, enhancing the course selection experience.
This commit is contained in:
Torsten Schulz (local)
2026-01-19 14:23:37 +01:00
parent 408b65be30
commit 64f4468664
4 changed files with 22 additions and 1 deletions

View File

@@ -9,6 +9,7 @@ class VocabController {
this.service = new VocabService();
this.listLanguages = this._wrapWithUser((userId) => this.service.listLanguages(userId));
this.listAllLanguages = this._wrapWithUser(() => this.service.listAllLanguages());
this.createLanguage = this._wrapWithUser((userId, req) => this.service.createLanguage(userId, req.body), { successStatus: 201 });
this.subscribe = this._wrapWithUser((userId, req) => this.service.subscribeByShareCode(userId, req.body), { successStatus: 201 });
this.getLanguage = this._wrapWithUser((userId, req) => this.service.getLanguage(userId, req.params.languageId));

View File

@@ -8,6 +8,7 @@ const vocabController = new VocabController();
router.use(authenticate);
router.get('/languages', vocabController.listLanguages);
router.get('/languages/all', vocabController.listAllLanguages);
router.post('/languages', vocabController.createLanguage);
router.post('/subscribe', vocabController.subscribe);
router.get('/languages/:languageId', vocabController.getLanguage);

View File

@@ -147,6 +147,24 @@ export default class VocabService {
return { languages: rows };
}
async listAllLanguages() {
// Gibt alle verfügbaren Sprachen zurück (für Kursliste)
const rows = await sequelize.query(
`
SELECT
id,
name
FROM community.vocab_language
ORDER BY name ASC
`,
{
type: sequelize.QueryTypes.SELECT,
}
);
return { languages: rows };
}
async listLanguagesForMenu(userId) {
// userId ist die numerische community.user.id
const rows = await sequelize.query(

View File

@@ -165,7 +165,8 @@ export default {
methods: {
async loadLanguages() {
try {
const res = await apiClient.get('/api/vocab/languages');
// Verwende /languages/all für die Kursliste, um alle Sprachen anzuzeigen
const res = await apiClient.get('/api/vocab/languages/all');
this.languages = res.data?.languages || [];
// Lade die Muttersprache des Benutzers