Add profile routes to backend and frontend; implement user state handling for holidays and workdays, and update UI components for profile settings
This commit is contained in:
62
backend/src/controllers/ProfileController.js
Normal file
62
backend/src/controllers/ProfileController.js
Normal file
@@ -0,0 +1,62 @@
|
||||
const ProfileService = require('../services/ProfileService');
|
||||
|
||||
/**
|
||||
* Controller für Benutzer-Profil
|
||||
* Verarbeitet HTTP-Requests und delegiert an ProfileService
|
||||
*/
|
||||
class ProfileController {
|
||||
/**
|
||||
* Holt das Benutzerprofil
|
||||
*/
|
||||
async getProfile(req, res) {
|
||||
try {
|
||||
const userId = req.user?.id || 1;
|
||||
const profile = await ProfileService.getProfile(userId);
|
||||
res.json(profile);
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Abrufen des Profils:', error);
|
||||
res.status(500).json({
|
||||
message: 'Fehler beim Abrufen des Profils',
|
||||
error: error.message
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Aktualisiert das Benutzerprofil
|
||||
*/
|
||||
async updateProfile(req, res) {
|
||||
try {
|
||||
const userId = req.user?.id || 1;
|
||||
const updates = req.body;
|
||||
|
||||
const profile = await ProfileService.updateProfile(userId, updates);
|
||||
res.json(profile);
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Aktualisieren des Profils:', error);
|
||||
res.status(500).json({
|
||||
message: 'Fehler beim Aktualisieren des Profils',
|
||||
error: error.message
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Holt alle verfügbaren Bundesländer
|
||||
*/
|
||||
async getStates(req, res) {
|
||||
try {
|
||||
const states = await ProfileService.getAllStates();
|
||||
res.json(states);
|
||||
} catch (error) {
|
||||
console.error('Fehler beim Abrufen der Bundesländer:', error);
|
||||
res.status(500).json({
|
||||
message: 'Fehler beim Abrufen der Bundesländer',
|
||||
error: error.message
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = new ProfileController();
|
||||
|
||||
Reference in New Issue
Block a user