Init: RoggioApp Architecture, Prisma Schema, API MVP
This commit is contained in:
Executable
+78
@@ -0,0 +1,78 @@
|
||||
import { serve } from '@hono/node-server'
|
||||
import { Hono } from 'hono'
|
||||
import { PrismaClient } from '@prisma/client'
|
||||
|
||||
const app = new Hono()
|
||||
const prisma = new PrismaClient()
|
||||
|
||||
app.get('/', (c) => {
|
||||
return c.html(`
|
||||
<html>
|
||||
<head>
|
||||
<title>BookMe - Roggio API</title>
|
||||
<style>
|
||||
body { font-family: monospace; background: #282a36; color: #f8f8f2; padding: 2rem; }
|
||||
h1 { color: #50fa7b; }
|
||||
.unit { border: 1px solid #6272a4; padding: 1rem; margin-bottom: 1rem; border-radius: 8px; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>BookMe API (RoggioApp MVP)</h1>
|
||||
<p>Willkommen an der API-Schnittstelle. Test-Endpunkte:</p>
|
||||
<ul>
|
||||
<li><a href="/api/apartments" style="color: #ff79c6;">/api/apartments</a> - Zeigt alle mietbaren Einheiten (dynamisch berechnet)</li>
|
||||
</ul>
|
||||
</body>
|
||||
</html>
|
||||
`)
|
||||
})
|
||||
|
||||
app.get('/api/apartments', async (c) => {
|
||||
const units = await prisma.unit.findMany({
|
||||
include: {
|
||||
children: {
|
||||
include: { children: true }
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const apartments = units.filter(u => {
|
||||
const traits = u.traits as any
|
||||
return traits && traits.is_rentable === true
|
||||
}).map(apartment => {
|
||||
let totalArea = 0;
|
||||
let totalSleepCapacity = 0;
|
||||
|
||||
apartment.children.forEach(room => {
|
||||
const rTraits = room.traits as any;
|
||||
if (rTraits?.area_sqm) totalArea += rTraits.area_sqm;
|
||||
|
||||
room.children.forEach(inv => {
|
||||
const iTraits = inv.traits as any;
|
||||
if (iTraits?.sleep_capacity) totalSleepCapacity += iTraits.sleep_capacity;
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
id: apartment.id,
|
||||
name: apartment.name,
|
||||
base_price: (apartment.traits as any).base_price,
|
||||
calculated_stats: {
|
||||
area_sqm: totalArea,
|
||||
sleep_capacity: totalSleepCapacity
|
||||
},
|
||||
rooms: apartment.children.map(r => r.name)
|
||||
}
|
||||
})
|
||||
|
||||
return c.json(apartments)
|
||||
})
|
||||
|
||||
const port = 3000
|
||||
console.log(`Server is running on port ${port}`)
|
||||
|
||||
serve({
|
||||
fetch: app.fetch,
|
||||
port,
|
||||
hostname: '0.0.0.0'
|
||||
})
|
||||
Reference in New Issue
Block a user