Feature: Termine-Anzeige auf der Startseite
- Neue CSV-Datei backend/data/termine.csv für Termine-Speicherung - Backend-Controller und Router für /api/termine Endpoint - TermineWidget Component zur Anzeige von bevorstehenden Terminen - Integration in LoggedInView (Startseite für eingeloggte User) - Zeigt Datum, Titel, Beschreibung, Ort und Uhrzeit an - Sortiert nach Datum, filtert automatisch vergangene Termine
This commit is contained in:
@@ -16,6 +16,7 @@ import match3Router from './routers/match3Router.js';
|
||||
import taxiRouter from './routers/taxiRouter.js';
|
||||
import taxiMapRouter from './routers/taxiMapRouter.js';
|
||||
import taxiHighscoreRouter from './routers/taxiHighscoreRouter.js';
|
||||
import termineRouter from './routers/termineRouter.js';
|
||||
import cors from 'cors';
|
||||
import './jobs/sessionCleanup.js';
|
||||
|
||||
@@ -52,6 +53,7 @@ app.use('/api/forum', forumRouter);
|
||||
app.use('/api/falukant', falukantRouter);
|
||||
app.use('/api/friendships', friendshipRouter);
|
||||
app.use('/api/blog', blogRouter);
|
||||
app.use('/api/termine', termineRouter);
|
||||
|
||||
// Serve frontend SPA for non-API routes to support history mode clean URLs
|
||||
const frontendDir = path.join(__dirname, '../frontend');
|
||||
|
||||
43
backend/controllers/termineController.js
Normal file
43
backend/controllers/termineController.js
Normal file
@@ -0,0 +1,43 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
|
||||
class TermineController {
|
||||
async getTermine(req, res) {
|
||||
try {
|
||||
const csvPath = path.join(__dirname, '../data/termine.csv');
|
||||
const csvContent = fs.readFileSync(csvPath, 'utf-8');
|
||||
|
||||
const lines = csvContent.trim().split('\n');
|
||||
const headers = lines[0].split(',');
|
||||
|
||||
const termine = lines.slice(1).map(line => {
|
||||
const values = line.split(',');
|
||||
const termin = {};
|
||||
headers.forEach((header, index) => {
|
||||
termin[header] = values[index] || '';
|
||||
});
|
||||
return termin;
|
||||
});
|
||||
|
||||
// Sortiere nach Datum
|
||||
termine.sort((a, b) => new Date(a.datum) - new Date(b.datum));
|
||||
|
||||
// Filtere nur zukünftige Termine
|
||||
const heute = new Date();
|
||||
heute.setHours(0, 0, 0, 0);
|
||||
const zukuenftigeTermine = termine.filter(t => new Date(t.datum) >= heute);
|
||||
|
||||
res.status(200).json(zukuenftigeTermine);
|
||||
} catch (error) {
|
||||
console.error('Error reading termine.csv:', error);
|
||||
res.status(500).json({ error: 'Could not load termine' });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default new TermineController();
|
||||
|
||||
7
backend/data/termine.csv
Normal file
7
backend/data/termine.csv
Normal file
@@ -0,0 +1,7 @@
|
||||
datum,titel,beschreibung,ort,uhrzeit
|
||||
2025-10-07,Vereinsmeisterschaften 2025 Doppel,Die Vereinsmeisterschaften 2025 im Doppel finden im Rahmen des Erwachsenentrainings statt.,,,
|
||||
2026-01-17,Vereinsmeisterschaften 2025 Einzel,Die Vereinsmeisterschaften 2025 im Einzel finden in der Schulturnhalle statt. Bitte vormerken!,,10:00
|
||||
2025-12-18,Weihnachtsfeier 2025,Die Weihnachtsfeier 2025 findet im Gasthaus „Zum Einhorn" in FFM-Bonames statt. Beginn 19:00 Uhr (bitte vormerken),Gasthaus „Zum Einhorn" FFM-Bonames,19:00
|
||||
2025-09-14,VR-Cup,Zwei VR-Cups am 14.09.2025 (jeweils 12 und 16 Uhr),,12:00 und 16:00
|
||||
2025-10-19,VR-Cup,Zwei VR-Cups am 19.10.2025 (jeweils 12 und 16 Uhr),,12:00 und 16:00
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 4 and column 91.
|
9
backend/routers/termineRouter.js
Normal file
9
backend/routers/termineRouter.js
Normal file
@@ -0,0 +1,9 @@
|
||||
import express from 'express';
|
||||
import termineController from '../controllers/termineController.js';
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router.get('/', termineController.getTermine);
|
||||
|
||||
export default router;
|
||||
|
||||
Reference in New Issue
Block a user