Add lesson retrieval functionality in VocabController and VocabService
- Introduced a new method in VocabService to fetch lesson details, including access control based on user ownership and lesson visibility. - Updated VocabController to wrap the new method for user access. - Added a new route in VocabRouter to handle requests for specific lessons. - Enhanced VocabCourseListView to support navigation to individual lesson views, improving user experience in accessing lesson content.
This commit is contained in:
@@ -197,6 +197,10 @@ export default {
|
||||
const nativeLang = this.languages.find(lang => lang.name === nativeLanguageName);
|
||||
if (nativeLang) {
|
||||
this.myNativeLanguageId = nativeLang.id;
|
||||
// Setze die eigene Muttersprache als Standardauswahl
|
||||
if (!this.selectedNativeLanguageId) {
|
||||
this.selectedNativeLanguageId = 'my';
|
||||
}
|
||||
console.log(`[loadMyNativeLanguageId] Gefunden: ${nativeLanguageName} (ID: ${nativeLang.id})`);
|
||||
} else {
|
||||
console.warn(`[loadMyNativeLanguageId] Sprache "${nativeLanguageName}" nicht in languages-Liste gefunden. Verfügbare Sprachen:`, this.languages.map(l => l.name).join(', '));
|
||||
@@ -297,6 +301,16 @@ export default {
|
||||
this.loading = false;
|
||||
}
|
||||
},
|
||||
async checkIfHasCourses() {
|
||||
// Prüfe, ob der Benutzer bereits Kurse hat
|
||||
try {
|
||||
const res = await apiClient.get('/api/vocab/courses/my');
|
||||
const courses = res.data || [];
|
||||
return courses.length > 0;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
async createCourse() {
|
||||
try {
|
||||
await apiClient.post('/api/vocab/courses', this.newCourse);
|
||||
@@ -318,7 +332,8 @@ export default {
|
||||
async enroll(courseId) {
|
||||
try {
|
||||
await apiClient.post(`/api/vocab/courses/${courseId}/enroll`);
|
||||
await this.loadAllCourses();
|
||||
// Nach dem Einschreiben sofort zum Kurs navigieren
|
||||
this.openCourse(courseId);
|
||||
} catch (e) {
|
||||
console.error('Fehler beim Einschreiben:', e);
|
||||
alert(e.response?.data?.error || 'Fehler beim Einschreiben');
|
||||
@@ -333,7 +348,13 @@ export default {
|
||||
},
|
||||
async mounted() {
|
||||
await this.loadLanguages();
|
||||
await this.loadAllCourses();
|
||||
// Wenn der Benutzer bereits Kurse hat, zeige "Meine Kurse" als Standard
|
||||
const hasCourses = await this.checkIfHasCourses();
|
||||
if (hasCourses) {
|
||||
await this.loadMyCourses();
|
||||
} else {
|
||||
await this.loadAllCourses();
|
||||
}
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user