diff --git a/.env b/.env new file mode 100644 index 0000000..7c2ec79 --- /dev/null +++ b/.env @@ -0,0 +1,11 @@ +PORT=3010 + +NODE_ENV=development + +SESSION_SECRET=MijnSuperGeheimeSleutel123! + +DATABASE=database.sqlite + +OPENAI_API_KEY=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 + +OPENAI_MODEL=gpt-5.4-mini diff --git a/.gitignore b/.gitignore index 46acc44..f50fddb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,4 @@ node_modules/ -.env -database.sqlite database.sqlite-shm database.sqlite-wal tmp-delete-test.sqlite diff --git a/controllers/ShoppingListController.js b/controllers/ShoppingListController.js index 00dc966..ee82fa3 100644 --- a/controllers/ShoppingListController.js +++ b/controllers/ShoppingListController.js @@ -72,6 +72,17 @@ class ShoppingListController { res.json({ success: true }); } + deleteList(req, res) { + const list = ShoppingListRepository.findById(req.params.id, req.user.household_id); + if (!list) return res.status(404).json({ error: "Lijst niet gevonden" }); + + const result = ShoppingListRepository.deleteList(list.id); + if (result.changes === 0) return res.status(404).json({ error: "Lijst niet gevonden" }); + + this.broadcastUpdate(req, list.id); + res.json({ success: true }); + } + broadcastUpdate(req, listId) { if (req.app.locals.io) { req.app.locals.io.to(`list:${listId}`).emit("list:updated", { listId }); diff --git a/database.sqlite b/database.sqlite new file mode 100644 index 0000000..f838b6e Binary files /dev/null and b/database.sqlite differ diff --git a/repositories/ShoppingListRepository.js b/repositories/ShoppingListRepository.js index a6e0b05..06426ff 100644 --- a/repositories/ShoppingListRepository.js +++ b/repositories/ShoppingListRepository.js @@ -77,6 +77,14 @@ class ShoppingListRepository { DELETE FROM shopping_list_items WHERE id = ? AND list_id = ? `).run(itemId, listId); } + + deleteList(listId) { + db.prepare(` + DELETE FROM shopping_list_items WHERE list_id = ? + `).run(listId); + return db.prepare(`DELETE FROM shopping_lists WHERE id = ? + `).run(listId); + } } module.exports = new ShoppingListRepository(); diff --git a/routes/web.js b/routes/web.js index 26d3c6f..dfd0b9a 100644 --- a/routes/web.js +++ b/routes/web.js @@ -179,4 +179,11 @@ router.delete( ShoppingListController.deleteItem.bind(ShoppingListController) ); +router.delete( + "/lists/:id", + auth, + ShoppingListController.deleteList.bind(ShoppingListController) +); + + module.exports = router; \ No newline at end of file diff --git a/storage/database.sqlite b/storage/database.sqlite new file mode 100644 index 0000000..b74fbcd Binary files /dev/null and b/storage/database.sqlite differ diff --git a/views/lists/index.ejs b/views/lists/index.ejs index 2cbd1e2..1f7e884 100644 --- a/views/lists/index.ejs +++ b/views/lists/index.ejs @@ -4,27 +4,45 @@
Je hebt nog geen boodschappenlijsten.
- <% } else { %> -Je hebt nog geen boodschappenlijsten.
+ <% } else { %> +