Add calendar routes to backend and frontend; update routing and UI components for calendar feature
This commit is contained in:
38
backend/src/controllers/CalendarController.js
Normal file
38
backend/src/controllers/CalendarController.js
Normal file
@@ -0,0 +1,38 @@
|
||||
const CalendarService = require('../services/CalendarService');
|
||||
|
||||
/**
|
||||
* Controller für Kalender
|
||||
* Verarbeitet HTTP-Requests und delegiert an CalendarService
|
||||
*/
|
||||
class CalendarController {
|
||||
/**
|
||||
* Holt Kalenderdaten für einen Monat
|
||||
*/
|
||||
async getMonth(req, res) {
|
||||
try {
|
||||
const userId = req.user?.id || 1;
|
||||
const year = parseInt(req.query.year) || new Date().getFullYear();
|
||||
const month = parseInt(req.query.month) || (new Date().getMonth() + 1);
|
||||
|
||||
if (isNaN(year) || year < 1900 || year > 2100) {
|
||||
return res.status(400).json({ message: 'Ungültiges Jahr' });
|
||||
}
|
||||
|
||||
if (isNaN(month) || month < 1 || month > 12) {
|
||||
return res.status(400).json({ message: 'Ungültiger Monat' });
|
||||
}
|
||||
|
||||
const calendarData = await CalendarService.getCalendarMonth(userId, year, month);
|
||||
res.json(calendarData);
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Abrufen der Kalenderdaten:', error);
|
||||
res.status(500).json({
|
||||
message: 'Fehler beim Abrufen der Kalenderdaten',
|
||||
error: error.message
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new CalendarController();
|
||||
|
||||
Reference in New Issue
Block a user