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();