Files
yourpart3/backend/controllers/taxiMapController.js
Torsten Schulz (local) 935928af75 Änderung: Bereinigung und Optimierung der Taxi-Map-Logik
Änderungen:
- Entfernen der Methode `getMapByPosition` aus dem `TaxiMapController` und der zugehörigen Logik im `TaxiMapService`, um die Komplexität zu reduzieren.
- Anpassung der Datenbankmodelle für `TaxiMap`, `TaxiLevelStats` und `TaxiMapType`, um die Tabellennamen zu vereinheitlichen.
- Aktualisierung der Routen im `taxiMapRouter`, um die entfernte Funktionalität zu reflektieren.
- Hinzufügung von neuen Importen in `index.js`, um die neuen Modelle zu integrieren.
- Verbesserung der Benutzeroberfläche durch neue Erfolgsmeldungen in den Übersetzungsdateien für die Admin-Oberfläche.

Diese Anpassungen tragen zur Vereinfachung der Codebasis und zur Verbesserung der Benutzererfahrung im Taxi-Minispiel bei.
2025-09-15 19:28:57 +02:00

126 lines
4.1 KiB
JavaScript

import TaxiMapService from '../services/taxiMapService.js';
class TaxiMapController {
constructor() {
this.taxiMapService = new TaxiMapService();
// Bind all methods to the class instance
this.getMapTypes = this.getMapTypes.bind(this);
this.getMaps = this.getMaps.bind(this);
this.getMapById = this.getMapById.bind(this);
this.getDefaultMap = this.getDefaultMap.bind(this);
this.createMap = this.createMap.bind(this);
this.updateMap = this.updateMap.bind(this);
this.deleteMap = this.deleteMap.bind(this);
this.setDefaultMap = this.setDefaultMap.bind(this);
}
async getMapTypes(req, res) {
try {
const mapTypes = await this.taxiMapService.getMapTypes();
res.json({ success: true, data: mapTypes });
} catch (error) {
console.error('Error getting map types:', error);
res.status(500).json({ success: false, message: 'Fehler beim Laden der Map-Typen' });
}
}
async getMaps(req, res) {
try {
const maps = await this.taxiMapService.getMaps();
res.json({ success: true, data: maps });
} catch (error) {
console.error('Error getting maps:', error);
res.status(500).json({ success: false, message: 'Fehler beim Laden der Maps' });
}
}
async getMapById(req, res) {
try {
const { mapId } = req.params;
const map = await this.taxiMapService.getMapById(mapId);
if (!map) {
return res.status(404).json({ success: false, message: 'Map nicht gefunden' });
}
res.json({ success: true, data: map });
} catch (error) {
console.error('Error getting map by ID:', error);
res.status(500).json({ success: false, message: 'Fehler beim Laden der Map' });
}
}
async getDefaultMap(req, res) {
try {
const map = await this.taxiMapService.getDefaultMap();
if (!map) {
return res.status(404).json({ success: false, message: 'Keine Standard-Map gefunden' });
}
res.json({ success: true, data: map });
} catch (error) {
console.error('Error getting default map:', error);
res.status(500).json({ success: false, message: 'Fehler beim Laden der Standard-Map' });
}
}
async createMap(req, res) {
try {
const mapData = req.body;
const map = await this.taxiMapService.createMap(mapData);
res.status(201).json({ success: true, data: map });
} catch (error) {
console.error('Error creating map:', error);
res.status(500).json({ success: false, message: 'Fehler beim Erstellen der Map' });
}
}
async updateMap(req, res) {
try {
const { mapId } = req.params;
const updateData = req.body;
const map = await this.taxiMapService.updateMap(mapId, updateData);
res.json({ success: true, data: map });
} catch (error) {
console.error('Error updating map:', error);
if (error.message === 'Map not found') {
return res.status(404).json({ success: false, message: 'Map nicht gefunden' });
}
res.status(500).json({ success: false, message: 'Fehler beim Aktualisieren der Map' });
}
}
async deleteMap(req, res) {
try {
const { mapId } = req.params;
await this.taxiMapService.deleteMap(mapId);
res.json({ success: true, message: 'Map erfolgreich gelöscht' });
} catch (error) {
console.error('Error deleting map:', error);
if (error.message === 'Map not found') {
return res.status(404).json({ success: false, message: 'Map nicht gefunden' });
}
res.status(500).json({ success: false, message: 'Fehler beim Löschen der Map' });
}
}
async setDefaultMap(req, res) {
try {
const { mapId } = req.params;
await this.taxiMapService.setDefaultMap(mapId);
res.json({ success: true, message: 'Standard-Map erfolgreich gesetzt' });
} catch (error) {
console.error('Error setting default map:', error);
if (error.message === 'Map not found') {
return res.status(404).json({ success: false, message: 'Map nicht gefunden' });
}
res.status(500).json({ success: false, message: 'Fehler beim Setzen der Standard-Map' });
}
}
}
export default TaxiMapController;