Bestpreise

This commit is contained in:
2026-08-16 09:06:48 +00:00
parent e2d05e6809
commit 48ba6ae282
3 changed files with 1326 additions and 251 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -5,28 +5,36 @@ export const dynamic = 'force-dynamic';
export async function GET() {
try {
const res = await query(`
SELECT
h.*,
t.name AS trip_name,
ph.price_numeric::float AS latest_price,
ph.price_per_night::float AS latest_price_per_night,
ph.price_per_person::float AS latest_price_per_person,
ph.nights AS latest_nights,
ph.persons AS latest_persons
FROM hotels h
LEFT JOIN trips t ON h.trip_id = t.id
LEFT JOIN LATERAL (
SELECT price_numeric, price_per_night, price_per_person, nights, persons
FROM hotel_price_history
WHERE hotel_id::text = h.id::text
ORDER BY tracked_at DESC NULLS LAST, id DESC
LIMIT 1
) ph ON true
ORDER BY h.checkin_date ASC NULLS LAST, h.id ASC
`);
return NextResponse.json({ success: true, hotels: res.rows });
const res = await query(`
SELECT
h.*,
t.name AS trip_name,
ph.price_numeric::float AS latest_price,
ph.price_per_night::float AS latest_price_per_night,
ph.price_per_person::float AS latest_price_per_person,
ph.nights AS latest_nights,
ph.persons AS latest_persons,
bp.best_price,
bp.best_price_per_night
FROM hotels h
LEFT JOIN trips t ON h.trip_id = t.id
LEFT JOIN LATERAL (
SELECT price_numeric, price_per_night, price_per_person, nights, persons
FROM hotel_price_history
WHERE hotel_id::text = h.id::text
ORDER BY tracked_at DESC NULLS LAST, id DESC
LIMIT 1
) ph ON true
LEFT JOIN LATERAL (
SELECT
MIN(price_numeric)::float AS best_price,
MIN(price_per_night)::float AS best_price_per_night
FROM hotel_price_history
WHERE hotel_id::text = h.id::text AND price_numeric > 0
) bp ON true
ORDER BY h.checkin_date ASC NULLS LAST, h.id ASC
`);
return NextResponse.json({ success: true, hotels: res.rows });
} catch (error: any) {
console.error('Fehler in GET /api/hotels:', error.message);
try {
@@ -67,4 +75,7 @@ export async function POST(req: NextRequest) {
console.error('Fehler in POST /api/hotels:', error.message);
return NextResponse.json({ success: false, error: error.message }, { status: 500 });
}
}

View File

@@ -45,6 +45,8 @@ interface Hotel {
latest_price_per_person?: number | null;
latest_nights?: number | null;
latest_persons?: number | null;
best_price?: number | null;
best_price_per_night?: number | null;
rating?: number | null;
review_count?: number | null;
image_url?: string | null;
@@ -938,24 +940,63 @@ export default function TravelDashboard() {
</div>
</div>
{/* Preis-Box */}
{totalPrice !== null ? (
<div style={{ display: 'flex', gap: '0.5rem', flexWrap: 'wrap', marginBottom: '0.8rem', background: '#ecfdf5', padding: '0.5rem 0.7rem', borderRadius: '8px', border: '1px solid #a7f3d0', alignItems: 'center' }}>
<span style={{ fontWeight: '800', color: '#047857', fontSize: '0.92rem' }}>
💰 Gesamt: {totalPrice.toLocaleString('de-DE')} €
</span>
<span style={{ color: '#059669', fontSize: '0.8rem', fontWeight: '600' }}>
| 🌙 {pricePerNight?.toLocaleString('de-DE')} € / N.
</span>
<span style={{ color: '#059669', fontSize: '0.8rem' }}>
| 👤 {pricePerPersonPerNight?.toLocaleString('de-DE')} € / P.
</span>
</div>
) : (
<div style={{ marginBottom: '0.8rem', fontSize: '0.82rem', color: '#6b7280', fontStyle: 'italic' }}>
💰 Noch kein Preis erfasst
</div>
)}
{/* Preis-Box mit Aktuellem Kurs & Bestpreis */}
{totalPrice !== null ? (
<div style={{
background: '#f8fafc',
border: '1px solid #e2e8f0',
borderRadius: '10px',
padding: '0.65rem 0.85rem',
marginBottom: '0.8rem',
display: 'flex',
flexDirection: 'column',
gap: '0.4rem'
}}>
{/* Zeile 1: Aktueller Preis */}
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', flexWrap: 'wrap', gap: '0.4rem' }}>
<div style={{ display: 'flex', alignItems: 'center', gap: '0.4rem', flexWrap: 'wrap' }}>
<span style={{ fontSize: '0.8rem', fontWeight: '700', color: '#475569' }}>Aktuell:</span>
<span style={{ fontWeight: '800', color: '#0f172a', fontSize: '0.95rem' }}>
💰 {totalPrice.toLocaleString('de-DE')} €
</span>
<span style={{ color: '#64748b', fontSize: '0.78rem' }}>
(🌙 {pricePerNight?.toLocaleString('de-DE')} € / N. · 👤 {pricePerPersonPerNight?.toLocaleString('de-DE')} € / P.)
</span>
</div>
{hotel.best_price && totalPrice > hotel.best_price ? (
<span style={{ background: '#fee2e2', color: '#991b1b', border: '1px solid #fecaca', fontSize: '0.72rem', padding: '0.15rem 0.4rem', borderRadius: '4px', fontWeight: '700' }}>
▲ +{(totalPrice - hotel.best_price).toLocaleString('de-DE')} € über Tiefst
</span>
) : (
<span style={{ background: '#ecfdf5', color: '#047857', border: '1px solid #a7f3d0', fontSize: '0.72rem', padding: '0.15rem 0.4rem', borderRadius: '4px', fontWeight: '800' }}>
🔥 Tiefstpreis
</span>
)}
</div>
{/* Zeile 2: Bestpreis / Historischer Tiefststand */}
{hotel.best_price && (
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', borderTop: '1px dashed #e2e8f0', paddingTop: '0.35rem', fontSize: '0.78rem' }}>
<div style={{ display: 'flex', alignItems: 'center', gap: '0.4rem' }}>
<span style={{ fontWeight: '700', color: '#059669' }}>🏆 Bestpreis:</span>
<span style={{ fontWeight: '800', color: '#047857' }}>
{Number(hotel.best_price).toLocaleString('de-DE')} €
</span>
{hotel.best_price_per_night && (
<span style={{ color: '#64748b', fontSize: '0.74rem' }}>
(🌙 {Math.round(Number(hotel.best_price_per_night)).toLocaleString('de-DE')} € / N.)
</span>
)}
</div>
</div>
)}
</div>
) : (
<div style={{ marginBottom: '0.8rem', fontSize: '0.82rem', color: '#6b7280', fontStyle: 'italic' }}>
💰 Noch kein Preis erfasst
</div>
)}
{/* Meta Tags */}
<div style={{ display: 'flex', gap: '0.8rem', fontSize: '0.8rem', marginBottom: '0.8rem', color: '#374151', flexWrap: 'wrap' }}>