diff --git a/back-end/src/db/migrations/20210123122225_createReservationsTable.js b/back-end/src/db/migrations/20210123122225_createReservationsTable.js index 654eaf1..6c93230 100644 --- a/back-end/src/db/migrations/20210123122225_createReservationsTable.js +++ b/back-end/src/db/migrations/20210123122225_createReservationsTable.js @@ -13,5 +13,5 @@ exports.up = function (knex) { exports.down = function(knex) { return knex.schema.dropTable("reservations") - .then(() => console.log("Dropped Table")) + .then(() => console.log("Dropped Reservation Table")) }; diff --git a/back-end/src/db/migrations/20240530112512_createTablesTable.js b/back-end/src/db/migrations/20240530112512_createTablesTable.js new file mode 100644 index 0000000..97d4630 --- /dev/null +++ b/back-end/src/db/migrations/20240530112512_createTablesTable.js @@ -0,0 +1,14 @@ + +exports.up = function(knex) { + return knex.schema.createTable("tables", (table) => { + table.increments("table_id").primary(); + table.string("table_name") + table.integer("capacity") + table.timestamps(true, true); + }); +}; + +exports.down = function(knex) { + return knex.schema.dropTable("tables") + .then(() => console.log("Dropped Table Table")) +}; diff --git a/back-end/src/db/seeds/01-tables.js b/back-end/src/db/seeds/01-tables.js new file mode 100644 index 0000000..ffcc567 --- /dev/null +++ b/back-end/src/db/seeds/01-tables.js @@ -0,0 +1,9 @@ +const tables = require("./01-tables.json") + + +exports.seed = function(knex) { + return knex.raw("TRUNCATE TABLE tables RESTART IDENTITY CASCADE") + .then(function (){ + return knex("tables").insert(tables) + }) +}; diff --git a/back-end/src/db/seeds/01-tables.json b/back-end/src/db/seeds/01-tables.json new file mode 100644 index 0000000..97d3671 --- /dev/null +++ b/back-end/src/db/seeds/01-tables.json @@ -0,0 +1,18 @@ +[ + { + "table_name": "Bar #1", + "capacity": 1 + }, + { + "table_name": "Bar #2", + "capacity": 1 + }, + { + "table_name": "#1", + "capacity": 6 + }, + { + "table_name": "#2", + "capacity": 6 + } +] diff --git a/back-end/src/tables/tables.controller.js b/back-end/src/tables/tables.controller.js index d23a1d0..5a98821 100644 --- a/back-end/src/tables/tables.controller.js +++ b/back-end/src/tables/tables.controller.js @@ -3,10 +3,8 @@ const service = require("./tables.service") const moment = require("moment") async function list(req, res) { - console.log("list") - res.json({ - data: await service.list(), - }); + console.log("list tables") + res.json({ data: await service.list() }); } module.exports = { diff --git a/front-end/src/dashboard/Dashboard.js b/front-end/src/dashboard/Dashboard.js index 1bfbb1b..d45bad1 100644 --- a/front-end/src/dashboard/Dashboard.js +++ b/front-end/src/dashboard/Dashboard.js @@ -1,6 +1,6 @@ import React, { useEffect, useState } from "react"; import {useLocation, useNavigate} from "react-router-dom" -import { listReservations } from "../utils/api"; +import { listReservations, listTables } from "../utils/api"; import ErrorAlert from "../layout/ErrorAlert"; import { today, previous, next } from "../utils/date-time"; @@ -13,6 +13,7 @@ import { today, previous, next } from "../utils/date-time"; function Dashboard() { const [reservations, setReservations] = useState([]); const [reservationsError, setReservationsError] = useState(null); + const [tables, setTables] = useState([]) let navigate = useNavigate() let location = useLocation() @@ -28,6 +29,8 @@ function Dashboard() { function loadDashboard() { const abortController = new AbortController(); setReservationsError(null); + listTables(abortController.signal) + .then(setTables); listReservations({ date }, abortController.signal) .then(setReservations) .catch(setReservationsError); @@ -46,6 +49,7 @@ function Dashboard() {

Reservation Time: {reservation.reservation_time} --- {reservation.reservation_date}

Number of People: {reservation.people}

+ @@ -53,6 +57,22 @@ function Dashboard() { : null )); + const tableItems = tables.map((table, index) => ( +
  • +
    +
    +
    Table {table.table_name}
    +

    Table Capacity: {table.capacity}

    + + + +
    +
    +
  • + + + )) + return (

    Dashboard

    @@ -65,9 +85,14 @@ function Dashboard() { {JSON.stringify(reservations)}
    - - - +
    +

    Reservations

    +
      {reservationItems}
    +
    +
    +

    Tables

    +
      {tableItems}
    +
    ); } diff --git a/front-end/src/layout/CreateEditTable.js b/front-end/src/layout/CreateEditTable.js index 70957b2..df57a40 100644 --- a/front-end/src/layout/CreateEditTable.js +++ b/front-end/src/layout/CreateEditTable.js @@ -45,7 +45,8 @@ function CreateEditTable(){
    } /> } /> } /> + } /> } /> }/> } /> diff --git a/front-end/src/utils/api.js b/front-end/src/utils/api.js index 646fc7c..de14688 100644 --- a/front-end/src/utils/api.js +++ b/front-end/src/utils/api.js @@ -69,6 +69,14 @@ export async function listReservations(params, signal) { } +export async function listTables(params, signal) { + const url = new URL(`${API_BASE_URL}/tables`); + Object.entries(params).forEach(([key, value]) => + url.searchParams.append(key, value.toString()) +) +return await fetchJson(url, { headers, signal }, []) +} + /** * Saves the reservation to the database.