From e0310d041021a04b0123a3683ffa113c3932c427 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Fri, 3 May 2024 08:33:17 +0200 Subject: [PATCH 1/4] Ignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 6367d07..6bceebb 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,4 @@ krusty.sqlite3 *.sqlite3 *.db +*.tar.gz From 9425d585bf6e55ba1cebbc52b4cf9881dee837bf Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Fri, 3 May 2024 08:34:18 +0200 Subject: [PATCH 2/4] Updated sql --- app/Migrations/create-schema.sql | 2 +- app/Migrations/initial-data.sql | 33 +++++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/app/Migrations/create-schema.sql b/app/Migrations/create-schema.sql index 483694f..4078831 100644 --- a/app/Migrations/create-schema.sql +++ b/app/Migrations/create-schema.sql @@ -26,7 +26,7 @@ CREATE TABLE IF NOT EXISTS orders ( -- Recipes for all the cookies (essentially a list of cookies) CREATE TABLE IF NOT EXISTS recipes ( recipe_id int PRIMARY KEY, - recipe_name varchar(100) -- Cookie name + recipe_name varchar(100) UNIQUE -- Cookie name ); -- "The company has a raw materials warehouse in which diff --git a/app/Migrations/initial-data.sql b/app/Migrations/initial-data.sql index 4dbbd05..1fd9348 100644 --- a/app/Migrations/initial-data.sql +++ b/app/Migrations/initial-data.sql @@ -1,6 +1,6 @@ -- Inserts here -INSERT OR IGNORE INTO - customers (customer_id, customer_name, customer_address) +INSERT +OR IGNORE INTO customers (customer_id, customer_name, customer_address) VALUES (1, 'Bjudkakor AB', 'Ystad'), (2, 'Finkakor AB', 'Helsingborg'), @@ -11,12 +11,35 @@ VALUES (7, 'Skånekakor AB', 'Perstorp'), (8, 'Småbröd AB', 'Malmö'); -INSERT INTO - recipes (recipe_name) +INSERT +OR IGNORE INTO recipes (recipe_name) VALUES ('Nut ring'), ('Nut cookie'), ('Amneris'), ('Tango'), ('Almond delight'), - ('Berliner'); \ No newline at end of file + ('Berliner'); + +INSERT +OR IGNORE INTO ingredients (ingredient_name, amount, unit) +VALUES + ('Bread crumbs', 500000, 'g'), + ('Butter', 500000, 'g'), + ('Chocolate', 500000, 'g'), + ('Chopped almonds', 500000, 'g'), + ('Cinnamon', 500000, 'g'), + ('Egg whites', 500000, 'ml'), + ('Eggs', 500000, 'g'), + ('Fine-ground nuts', 500000, 'g'), + ('Flour', 500000, 'g'), + ('Ground, roasted nuts', 500000, 'g'), + ('Icing sugar', 500000, 'g'), + ('Marzipan', 500000, 'g'), + ('Potato starch', 500000, 'g'), + ('Roasted, chopped nuts', 500000, 'g'), + ('Sodium bicarbonate', 500000, 'g'), + ('Sugar', 500000, 'g'), + ('Vanilla', 500000, 'g'), + ('Vanilla sugar', 500000, 'g'), + ('Wheat flour', 500000, 'g'); \ No newline at end of file From 43668dc8d34940965f2c4dc00884eea6aacaf8c6 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Fri, 3 May 2024 08:34:33 +0200 Subject: [PATCH 3/4] Passing more tests --- app/src/main/java/krusty/Database.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/krusty/Database.java b/app/src/main/java/krusty/Database.java index 26ef811..e14a4e5 100644 --- a/app/src/main/java/krusty/Database.java +++ b/app/src/main/java/krusty/Database.java @@ -22,8 +22,8 @@ public class Database { // "jdbc:sqlite:.sqlite3" to use a file-based database instead. // Nore that ":memory:" is an **SQLite specific** magic string that tells the // underlying SQLite engine to store the database in memory. - // private static final String jdbcString = "jdbc:sqlite::memory:"; - private static final String jdbcString = "jdbc:sqlite:krusty.db"; + private static final String jdbcString = "jdbc:sqlite::memory:"; + // private static final String jdbcString = "jdbc:sqlite:krusty.db"; private Connection conn = null; public String getCustomers(Request req, Response res) { @@ -34,11 +34,14 @@ public class Database { } public String getRawMaterials(Request req, Response res) { - return "{}"; + String result = selectQuery("ingredients", "raw-materials", "ingredient_name", "amount", "unit"); + result = result.replaceAll("ingredient_name", "name"); + return result; } public String getCookies(Request req, Response res) { String result = selectQuery("recipes", "cookies", "recipe_name"); + result = result.replaceAll("recipe_name", "name"); return result; } From b9c8cf5b0567b84d0de3a1781d6e1a05760677d0 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Fri, 3 May 2024 08:34:42 +0200 Subject: [PATCH 4/4] Release in makefile --- makefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/makefile b/makefile index dec224d..97c755c 100644 --- a/makefile +++ b/makefile @@ -17,4 +17,9 @@ migrate: sqlite3 app/krusty.db < app/Migrations/create-schema.sql sqlite3 app/krusty.db < app/Migrations/initial-data.sql +GITHASH := $(shell git rev-parse --short HEAD) +# Tar everything that isnt gitignored +release: + git ls-files -z | xargs -0 tar -czf krusty-imbus_$(GITHASH).tar.gz + .PHONY: run clean test build