From 47e036e8be1cab9ab757796382807eb6f8750109 Mon Sep 17 00:00:00 2001 From: Antoine Pelletier Date: Sat, 11 Oct 2025 03:30:14 +0200 Subject: [PATCH] feat: improve agep page --- .gitignore | 1 + backend/server.js | 13 +-- src/App.vue | 4 +- src/assets/base.css | 34 +++++++- src/assets/main.css | 16 ++-- src/components/BookingForm.vue | 147 ++++++++++++++++++++++++++------- src/pages/AdminPage.vue | 13 ++- 7 files changed, 179 insertions(+), 49 deletions(-) diff --git a/.gitignore b/.gitignore index 94a2baf..be36951 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,4 @@ yarn-error.log* # Others public/*.tmp +/backend/migrations/create_bookings.sql diff --git a/backend/server.js b/backend/server.js index 9fce22f..f7721eb 100644 --- a/backend/server.js +++ b/backend/server.js @@ -2,8 +2,6 @@ import express from 'express' import cors from 'cors' import dotenv from 'dotenv' import { pool } from './db.js' -import fs from 'fs' -import path from 'path' dotenv.config() @@ -24,13 +22,13 @@ app.get('/api/bikes', async (req, res) => { // Create a booking app.post('/api/bookings', async (req, res) => { try { - const { bike_type, start_date, end_date, name, email } = req.body + const { bike_type, start_date, end_date, start_time, end_time, name, email } = req.body if (!bike_type || !start_date || !end_date || !name || !email) { return res.status(400).json({ error: 'Missing fields' }) } - const text = `INSERT INTO bookings(bike_type, start_date, end_date, name, email) VALUES($1, $2, $3, $4, $5) RETURNING *` - const values = [bike_type, start_date, end_date, name, email] + const text = `INSERT INTO bookings(bike_type, start_date, start_time, end_date, end_time, name, email) VALUES($1, $2, $3, $4, $5, $6, $7) RETURNING *` + const values = [bike_type, start_date, start_time || null, end_date, end_time || null, name, email] const result = await pool.query(text, values) res.status(201).json({ booking: result.rows[0] }) } catch (err) { @@ -57,7 +55,9 @@ async function ensureTables() { id SERIAL PRIMARY KEY, bike_type INTEGER NOT NULL, start_date DATE NOT NULL, + start_time TIME, end_date DATE NOT NULL, + end_time TIME, name TEXT NOT NULL, email TEXT NOT NULL, created_at TIMESTAMP WITH TIME ZONE DEFAULT now() @@ -66,6 +66,9 @@ async function ensureTables() { try { await pool.query(createSql) + // Ensure new columns exist if the table was created earlier without time columns + await pool.query(`ALTER TABLE bookings ADD COLUMN IF NOT EXISTS start_time TIME;`) + await pool.query(`ALTER TABLE bookings ADD COLUMN IF NOT EXISTS end_time TIME;`) console.log('Database: bookings table is present (created if it did not exist)') } catch (err) { // If DATABASE_URL is not configured or DB not reachable, warn but still allow server to start for frontend dev diff --git a/src/App.vue b/src/App.vue index 7798e46..b0d2ae3 100644 --- a/src/App.vue +++ b/src/App.vue @@ -29,7 +29,7 @@ function toggleTheme() {