diff --git a/.gitignore b/.gitignore index fa49873..5acca89 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ node_modules -dist -.idea \ No newline at end of file +frontend/dist +frontend/node_modules +.idea +config.json +pizza-collage \ No newline at end of file diff --git a/index.html b/frontend/index.html similarity index 100% rename from index.html rename to frontend/index.html diff --git a/package-lock.json b/frontend/package-lock.json similarity index 100% rename from package-lock.json rename to frontend/package-lock.json diff --git a/package.json b/frontend/package.json similarity index 100% rename from package.json rename to frontend/package.json diff --git a/frontend/src/StoccaTreRoot/index.tsx b/frontend/src/StoccaTreRoot/index.tsx new file mode 100644 index 0000000..66d2a26 --- /dev/null +++ b/frontend/src/StoccaTreRoot/index.tsx @@ -0,0 +1,27 @@ +import { h, Rung } from "@djledda/ladder"; +import StoccaTreLogo from "@/assets/stocca-tre-logo.svg"; +import "./stocca-tre-root.scss"; + +export default class StoccaTreRoot extends Rung { + constructor() { + super({}); + } + + build(): Node { + return
+
+
+ {"Stocca +
+ +
+
; + } +} \ No newline at end of file diff --git a/frontend/src/StoccaTreRoot/stocca-tre-root.scss b/frontend/src/StoccaTreRoot/stocca-tre-root.scss new file mode 100644 index 0000000..0ffec03 --- /dev/null +++ b/frontend/src/StoccaTreRoot/stocca-tre-root.scss @@ -0,0 +1,29 @@ +.stocca-tre-root { + .headstock { + width: 1200px; + text-align: center; + background-color: var(--bg-color); + height: 100%; + margin: auto; + + .logo { + margin: 20px auto auto auto; + --height: 100px; + padding: calc(0.2 * var(--height)); + height: var(--height); + } + + ul.tabs { + list-style: none; + padding: 0; + width: 100%; + display: flex; + flex-direction: row; + li { + flex: 1; + padding: 20px; + display: inline-block; + } + } + } +} \ No newline at end of file diff --git a/frontend/src/assets/stocca-tre-logo.svg b/frontend/src/assets/stocca-tre-logo.svg new file mode 100644 index 0000000..7cfa09e --- /dev/null +++ b/frontend/src/assets/stocca-tre-logo.svg @@ -0,0 +1,131 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/filetypes.d.ts b/frontend/src/filetypes.d.ts similarity index 100% rename from src/filetypes.d.ts rename to frontend/src/filetypes.d.ts diff --git a/frontend/src/global.scss b/frontend/src/global.scss new file mode 100644 index 0000000..2e52c1d --- /dev/null +++ b/frontend/src/global.scss @@ -0,0 +1,10 @@ +:root { + --bg-color: #e8e2e2; + --red-deep: #aa0000; + --red-shallow: #ec563f; +} + +html, body { + padding: 0; + margin: 0; +} \ No newline at end of file diff --git a/src/main.ts b/frontend/src/main.ts similarity index 59% rename from src/main.ts rename to frontend/src/main.ts index b40f696..a1f794d 100644 --- a/src/main.ts +++ b/frontend/src/main.ts @@ -1,4 +1,5 @@ import { bootstrap } from '@djledda/ladder'; import StoccaTreRoot from './StoccaTreRoot'; +import './global.scss'; bootstrap(new StoccaTreRoot(), "root"); \ No newline at end of file diff --git a/vite.config.ts b/frontend/vite.config.ts similarity index 100% rename from vite.config.ts rename to frontend/vite.config.ts diff --git a/server/Ingredient.ts b/server/Ingredient.ts new file mode 100644 index 0000000..e2da97d --- /dev/null +++ b/server/Ingredient.ts @@ -0,0 +1,34 @@ +import { StoccaTreDbConn, WithoutId } from "./database.ts"; + +export type Ingredient = { + id: number, + name: string, + displayName: string, + displayNameDE: string, +}; + +export default class IngredientService { + private dbConnection: StoccaTreDbConn; + private mapById: Map = new Map(); + private allGotten = false; + + constructor(database: StoccaTreDbConn) { + this.dbConnection = database; + } + + async addIngredient(ingredient: WithoutId): Promise { + const result = await this.dbConnection.query( + `INSERT INTO ingredients (id, name, displayName, displayNameDE) VALUES (NULL, '${ingredient.name}', '${ingredient.displayName}', '${ingredient.displayNameDE}');` + ); + return result; + } + + async getAllIngredients(): Promise> { + if (!this.allGotten) { + const result = await this.dbConnection.query("SELECT * FROM ingredients"); + result.forEach((ingredient) => this.mapById.set(ingredient.id, ingredient)); + this.allGotten = true; + } + return this.mapById.values(); + } +} \ No newline at end of file diff --git a/server/database.ts b/server/database.ts new file mode 100644 index 0000000..a48786e --- /dev/null +++ b/server/database.ts @@ -0,0 +1,16 @@ +import { Client } from "https://deno.land/x/mysql/mod.ts"; +import dbconfig from "./config.json" assert { type: "json" }; + +export type WithoutId = Omit; +export interface StoccaTreDbConn { + query(query: string): Promise; +} +export default async function createNewDbConnection(): Promise { + return await new Client().connect({ + hostname: dbconfig.hostname, + username: dbconfig.username, + db: "stocca_tre", + password: dbconfig.password, + }); +} + diff --git a/server/main.ts b/server/main.ts new file mode 100644 index 0000000..8d85772 --- /dev/null +++ b/server/main.ts @@ -0,0 +1,25 @@ +import createNewDbConnection from "./database.ts"; +import IngredientService from "./Ingredient.ts"; + +const server = Deno.listen({ port: 8080 }); + +console.log(`HTTP webserver running. Access it at: http://localhost:8080/`); + +const database = await createNewDbConnection(); +const ingredientService = new IngredientService(database); + +for await (const conn of server) { + serveHttp(conn); +} + +async function serveHttp(conn: Deno.Conn) { + const httpConn = Deno.serveHttp(conn); + + for await (const requestEvent of httpConn) { + const body = []; + for (const ingredient of (await ingredientService.getAllIngredients())) { + body.push(ingredient); + } + requestEvent.respondWith(Response.json(body, { status: 200 })); + } +} \ No newline at end of file diff --git a/server/package.json b/server/package.json new file mode 100644 index 0000000..d44b062 --- /dev/null +++ b/server/package.json @@ -0,0 +1,10 @@ +{ + "name": "stocca-tre-server", + "version": "0.0.1", + "scripts": { + "start": "deno run --allow-net main.ts" + }, + "description": "Backend for StoccaTre", + "author": "Daniel Ledda", + "license": "MIT" +} diff --git a/src/StoccaTreRoot/index.tsx b/src/StoccaTreRoot/index.tsx deleted file mode 100644 index a83a9f3..0000000 --- a/src/StoccaTreRoot/index.tsx +++ /dev/null @@ -1,24 +0,0 @@ -import { h, Rung } from "@djledda/ladder"; -import StoccaTreLogo from "@/assets/stocca-tre-logo.svg"; -import "./stocca-tre-root.scss"; - -export default class StoccaTreRoot extends Rung { - constructor() { - super({}); - } - - build(): Node { - return
- {"Stocca -

Die Pizzeria im dritten Stock.

-
-

- Pizza-Bestellungen: -

- - Keine Pizzen aktuell verfügbar!!!!! - Später mal wieder vorbeischauen. Die Pizzen müssen ja noch lange gehen... - -
; - } -} \ No newline at end of file diff --git a/src/StoccaTreRoot/stocca-tre-root.scss b/src/StoccaTreRoot/stocca-tre-root.scss deleted file mode 100644 index 7d52df9..0000000 --- a/src/StoccaTreRoot/stocca-tre-root.scss +++ /dev/null @@ -1,5 +0,0 @@ -.stocca-tre-root { - .no-pizza { - color: red; - } -} \ No newline at end of file diff --git a/src/assets/stocca-tre-logo.svg b/src/assets/stocca-tre-logo.svg deleted file mode 100644 index 49185af..0000000 --- a/src/assets/stocca-tre-logo.svg +++ /dev/null @@ -1,99 +0,0 @@ - - - - - - - - - - - - - - - - - tre - pizzeria - - -