feat: setup CI/CD, add docker compose, and create CRUD dashboard
Deploy API / deploy (push) Failing after 2m12s
Deploy API / deploy (push) Failing after 2m12s
This commit is contained in:
+53
-59
@@ -1,73 +1,67 @@
|
||||
import { serve } from '@hono/node-server'
|
||||
import { serveStatic } from '@hono/node-server/serve-static'
|
||||
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>
|
||||
`)
|
||||
// API: Alle Units abrufen
|
||||
app.get('/api/units', async (c) => {
|
||||
const units = await prisma.unit.findMany()
|
||||
return c.json(units)
|
||||
})
|
||||
|
||||
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)
|
||||
// API: Eine Unit erstellen
|
||||
app.post('/api/units', async (c) => {
|
||||
const body = await c.req.json()
|
||||
const unit = await prisma.unit.create({ data: body })
|
||||
return c.json(unit)
|
||||
})
|
||||
|
||||
// API: Eine Unit bearbeiten
|
||||
app.put('/api/units/:id', async (c) => {
|
||||
const id = c.req.param('id')
|
||||
const body = await c.req.json()
|
||||
const unit = await prisma.unit.update({
|
||||
where: { id },
|
||||
data: body
|
||||
})
|
||||
return c.json(unit)
|
||||
})
|
||||
|
||||
// API: Eine Unit löschen
|
||||
app.delete('/api/units/:id', async (c) => {
|
||||
const id = c.req.param('id')
|
||||
await prisma.unit.delete({ where: { id } })
|
||||
return c.json({ success: true })
|
||||
})
|
||||
|
||||
// API: Events (Identisch zu Units)
|
||||
app.get('/api/events', async (c) => {
|
||||
const events = await prisma.event.findMany()
|
||||
return c.json(events)
|
||||
})
|
||||
app.post('/api/events', async (c) => {
|
||||
const body = await c.req.json()
|
||||
const event = await prisma.event.create({ data: body })
|
||||
return c.json(event)
|
||||
})
|
||||
app.put('/api/events/:id', async (c) => {
|
||||
const id = c.req.param('id')
|
||||
const body = await c.req.json()
|
||||
const event = await prisma.event.update({ where: { id }, data: body })
|
||||
return c.json(event)
|
||||
})
|
||||
app.delete('/api/events/:id', async (c) => {
|
||||
const id = c.req.param('id')
|
||||
await prisma.event.delete({ where: { id } })
|
||||
return c.json({ success: true })
|
||||
})
|
||||
|
||||
// Statische Dateien (Unser Dashboard)
|
||||
app.use('/*', serveStatic({ root: './public' }))
|
||||
|
||||
const port = 3000
|
||||
console.log(`Server is running on port ${port}`)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user