Compare commits
445
Commits
ca0f7cda5d
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aef3ead025 | ||
|
|
9b18eb0f0f | ||
|
|
af63723f3c | ||
|
|
f122372f5d | ||
|
|
d8b5c64cf7 | ||
|
|
1d155c25fd | ||
|
|
a6e77fc107 | ||
|
|
c9132be067 | ||
|
|
bcf735af2f | ||
|
|
5c996a8a77 | ||
|
|
012c8b83a6 | ||
|
|
43588852f4 | ||
|
|
7f74c97c4d | ||
|
|
e611b98a9b | ||
|
|
179ec1206b | ||
|
|
e22cd8c650 | ||
|
|
bb60da6aaa | ||
|
|
af46c19651 | ||
|
|
c551b21701 | ||
|
|
6ae4a1d1f6 | ||
|
|
6508f589b3 | ||
|
|
110e5d415e | ||
|
|
3a1c954023 | ||
|
|
ea6a330fab | ||
|
|
27ebe17be5 | ||
|
|
84bf7b9129 | ||
|
|
d9d511ae29 | ||
|
|
e5dbf649f8 | ||
|
|
1bbff06760 | ||
|
|
8e3c6b8c36 | ||
|
|
57c541bbb7 | ||
|
|
d5389af958 | ||
|
|
ad4a9d12d5 | ||
|
|
3abf47e2ea | ||
|
|
fb5052d43d | ||
|
|
c0cbc5a49c | ||
|
|
16775b45ee | ||
|
|
0ac781114f | ||
|
|
d373ecce2b | ||
|
|
ea8ebf79b2 | ||
|
|
966705ec90 | ||
|
|
4bbc1b73d5 | ||
|
|
4f387d2b7f | ||
|
|
1c1d3f6571 | ||
|
|
7db358721d | ||
|
|
c1bd997e33 | ||
|
|
df20f8c426 | ||
|
|
c0cddc3ef8 | ||
|
|
e8d35385ca | ||
|
|
d4b5382f70 | ||
|
|
75d9591f2d | ||
|
|
3d01278a62 | ||
|
|
f38b8b547f | ||
|
|
083dfa6e7b | ||
|
|
ce55b3b2c8 | ||
|
|
a63ecc4de5 | ||
|
|
433445290c | ||
|
|
a5f0fa9ba3 | ||
|
|
0109a65d0b | ||
|
|
5a1bac447e | ||
|
|
d79be68bed | ||
|
|
719c63862e | ||
|
|
3962a58bc9 | ||
|
|
921d7aef72 | ||
|
|
4b83562e7b | ||
|
|
3b2de4a2e4 | ||
|
|
f2538a39bc | ||
|
|
c20841e475 | ||
|
|
003fba3a49 | ||
|
|
5b6a8e67bf | ||
|
|
569e5223f2 | ||
|
|
ea36b16a87 | ||
|
|
882c4d2707 | ||
|
|
719f633615 | ||
|
|
9f63b689fc | ||
|
|
1c796e4bad | ||
|
|
c8cddd01df | ||
|
|
1afabf80ce | ||
|
|
774212f63a | ||
|
|
3a5064f52f | ||
|
|
0a0a48233e | ||
|
|
3d82b3561d | ||
|
|
90be6ce76e | ||
|
|
b2c741510c | ||
|
|
37cf02dae5 | ||
|
|
2c9a205c1e | ||
|
|
a007e62c8e | ||
|
|
b3eed14ede | ||
|
|
0a9fea3665 | ||
|
|
5783814697 | ||
|
|
607db109b6 | ||
|
|
75cc93f141 | ||
|
|
6c8b61fdda | ||
|
|
200f23c5e1 | ||
|
|
fcd902fd26 | ||
|
|
cb9572e52c | ||
|
|
f8dfbbcd96 | ||
|
|
e6ccba0219 | ||
|
|
725879970f | ||
|
|
302419802b | ||
|
|
3f5856c86b | ||
|
|
8c347d124a | ||
|
|
0b69384fb7 | ||
|
|
2d19d9a06f | ||
|
|
70338266f2 | ||
|
|
00ac28aebf | ||
|
|
c9c38f07ad | ||
|
|
7af099f022 | ||
|
|
b4eb339657 | ||
|
|
79443930e2 | ||
|
|
08315359c7 | ||
|
|
b3ec0257d5 | ||
|
|
1dd335e166 | ||
|
|
f33b979bcb | ||
|
|
69389afdb7 | ||
|
|
593c540d81 | ||
|
|
dfff051b55 | ||
|
|
97de073621 | ||
|
|
6c227dcaad | ||
|
|
df90bf21d1 | ||
|
|
5f9ce78476 | ||
|
|
e008e2583e | ||
|
|
f2a5419064 | ||
|
|
a89225fce6 | ||
|
|
9e58b18e43 | ||
|
|
b2badea855 | ||
|
|
d222604fcf | ||
|
|
c99d5f4347 | ||
|
|
9b552b88f8 | ||
|
|
5886777854 | ||
|
|
730248f3e8 | ||
|
|
01dd5c9089 | ||
|
|
9c0d704748 | ||
|
|
e736170735 | ||
|
|
1290df93f6 | ||
|
|
ed05aa3a53 | ||
|
|
e715e66929 | ||
|
|
6233d27d7b | ||
|
|
76a4b201b8 | ||
|
|
4622e91f26 | ||
|
|
c6bc6cf8f9 | ||
|
|
a39eee06e9 | ||
|
|
4137b511bb | ||
|
|
2e11917ea1 | ||
|
|
148c33cf6e | ||
|
|
d9fd91ad8d | ||
|
|
b5293e246c | ||
|
|
b1aa5bec07 | ||
|
|
fd984529e7 | ||
|
|
7136a7b16c | ||
|
|
f005069ee2 | ||
|
|
9ed72aa23e | ||
|
|
377d888221 | ||
|
|
b6ad218fdb | ||
|
|
02e523cb62 | ||
|
|
11ee9dcf6e | ||
|
|
facf5a63d0 | ||
|
|
2d967fd5ad | ||
|
|
2ee3895a28 | ||
|
|
e84b02f8d5 | ||
|
|
97f2d91323 | ||
|
|
1c74a56586 | ||
|
|
5ce49d672b | ||
|
|
7b02a51867 | ||
|
|
d77a4918fe | ||
|
|
5957fa442a | ||
|
|
83cf78d00d | ||
|
|
ad9fc0e02a | ||
|
|
5e0b6d7477 | ||
|
|
3152c92ac0 | ||
|
|
9b10ce153d | ||
|
|
80220c903c | ||
|
|
297f338a17 | ||
|
|
714d523020 | ||
|
|
d572a55ce6 | ||
|
|
75ae18a6ca | ||
|
|
98a4483771 | ||
|
|
2298ac3895 | ||
|
|
d94dec9062 | ||
|
|
fe1f9fdfd9 | ||
|
|
fd68ce2f34 | ||
|
|
88be63384f | ||
|
|
ad942e38ff | ||
|
|
1aeeecb32b | ||
|
|
68daed2bcc | ||
|
|
35ef1a2bc8 | ||
|
|
da996b5922 | ||
|
|
f1fa9ffcb4 | ||
|
|
b4def65ec0 | ||
|
|
4ba8b4d823 | ||
|
|
f108692809 | ||
|
|
292c1922dd | ||
|
|
aa6b5c7444 | ||
|
|
d6b32f4991 | ||
|
|
80fdd6ccae | ||
|
|
2e062f60b9 | ||
|
|
96a0876035 | ||
|
|
a7d467f187 | ||
|
|
a49506fece | ||
|
|
75721a7465 | ||
|
|
71fd6ee420 | ||
|
|
1e1b8d0ec5 | ||
|
|
5a34db09f6 | ||
|
|
a467d3f4a7 | ||
|
|
7c81870665 | ||
|
|
6f503f311e | ||
|
|
9fa60a8d6d | ||
|
|
16dfd340ec | ||
|
|
8a6bef92f7 | ||
|
|
17b7f485f6 | ||
|
|
7bec1e7b5c | ||
|
|
b601083e7a | ||
|
|
3d8e7f308b | ||
|
|
c8808a9f23 | ||
|
|
a6063ad842 | ||
|
|
109a7a9610 | ||
|
|
9b442e7828 | ||
|
|
340e524945 | ||
|
|
37062e6c37 | ||
|
|
5135bcad5a | ||
|
|
bbc3cfe0f7 | ||
|
|
6d2c39c69b | ||
|
|
696d14bd39 | ||
|
|
ca6ebc9e35 | ||
|
|
d3bdc3d65e | ||
|
|
13e2af55a8 | ||
|
|
390b3b266c | ||
|
|
ddec4d8335 | ||
|
|
f83f3bf4b1 | ||
|
|
5ee6f07089 | ||
|
|
67c0a5e9b2 | ||
|
|
e8319d304a | ||
|
|
de56ba242c | ||
|
|
f84660f0be | ||
|
|
113e9cdb82 | ||
|
|
bb6d4abe9e | ||
|
|
844decd963 | ||
|
|
de72438a0b | ||
|
|
e8fcb5ed9c | ||
|
|
9f436720e9 | ||
|
|
18daded2c2 | ||
|
|
e579044ed5 | ||
|
|
f7d11a77d1 | ||
|
|
080f61a0c8 | ||
|
|
18ac0273bd | ||
|
|
c104754ff3 | ||
|
|
4a0c70fb98 | ||
|
|
05874500b8 | ||
|
|
b14b0ac08b | ||
|
|
c72b14e594 | ||
|
|
5a48acba2f | ||
|
|
b5d61ff772 | ||
|
|
66e8ac13ea | ||
|
|
6aa624a507 | ||
|
|
71d7d373eb | ||
|
|
0564d81b25 | ||
|
|
c724bafb06 | ||
|
|
d39acbd54a | ||
|
|
7202eea4cc | ||
|
|
ab7734915b | ||
|
|
9361de6cb0 | ||
|
|
4d69c8167a | ||
|
|
42cf4064a5 | ||
|
|
88dc53c761 | ||
|
|
7de26ba846 | ||
|
|
67829592ed | ||
|
|
19f9c1db7a | ||
|
|
db87bbe34e | ||
|
|
4ec5f88495 | ||
|
|
61e44916b2 | ||
|
|
f9188b09b1 | ||
|
|
3d18618d87 | ||
|
|
824c66a28d | ||
|
|
ed2cfe8be9 | ||
|
|
6a32200ce5 | ||
|
|
a7d94868f7 | ||
|
|
5064564886 | ||
|
|
ee6cee4d54 | ||
|
|
006e8b63db | ||
|
|
90bbbffae7 | ||
|
|
2cb98af4f1 | ||
|
|
46024bd589 | ||
|
|
50852cf3a0 | ||
|
|
61c9348c60 | ||
|
|
086e16fc82 | ||
|
|
a01f3c917a | ||
|
|
8f5452c09f | ||
|
|
fd9a328478 | ||
|
|
45cc85b7b4 | ||
|
|
33cd0b0fad | ||
|
|
1acd4af71f | ||
|
|
ed0df61e16 | ||
|
|
abb1af276c | ||
|
|
2ade9c9744 | ||
|
|
6bd55f6e86 | ||
|
|
226e7f68ce | ||
|
|
e4df4f492d | ||
|
|
4bbbdf7d10 | ||
|
|
1b321420a5 | ||
|
|
344ae5c584 | ||
|
|
81227cc56d | ||
|
|
b95c238492 | ||
|
|
146ef1f3e1 | ||
|
|
cd12da1099 | ||
|
|
bce0b982ee | ||
|
|
9b8887793e | ||
|
|
bfca2878b9 | ||
|
|
4c67f191a2 | ||
|
|
4f62c7f93e | ||
|
|
7698efd446 | ||
|
|
a99342cc98 | ||
|
|
47a3849220 | ||
|
|
51d4e1b451 | ||
|
|
ab8a85e1f1 | ||
|
|
65cdc95b72 | ||
|
|
600c39352a | ||
|
|
ffb4a7e2c6 | ||
|
|
2963dd40a6 | ||
|
|
fbd20f9089 | ||
|
|
9e8202d382 | ||
|
|
ccb37a666a | ||
|
|
fd0a3959a5 | ||
|
|
6cfe4d3510 | ||
|
|
18cf37f7c9 | ||
|
|
62953ffa61 | ||
|
|
d731c46c9c | ||
|
|
dd5308b495 | ||
|
|
002d09955a | ||
|
|
f4822ceb4d | ||
|
|
d5df05f87a | ||
|
|
ea34010c8d | ||
|
|
7428c7db25 | ||
|
|
2b2889cb63 | ||
|
|
6bedcb1836 | ||
|
|
a635d7c374 | ||
|
|
02eac10d9a | ||
|
|
a49ceea355 | ||
|
|
4f453c0263 | ||
|
|
409469e098 | ||
|
|
821f5c7216 | ||
|
|
77b5ed5991 | ||
|
|
6175817db2 | ||
|
|
ea3b07ed0f | ||
|
|
33964f2a30 | ||
|
|
49377a98a8 | ||
|
|
5b313a4364 | ||
|
|
afda716a66 | ||
|
|
f5add6b590 | ||
|
|
ca6c4bdf9e | ||
|
|
8307e50d24 | ||
|
|
09fa991077 | ||
|
|
be7b752ce7 | ||
|
|
19c2647cf6 | ||
|
|
2bed4c24a4 | ||
|
|
de864daf3d | ||
|
|
c371cf00df | ||
|
|
22e8606a0f | ||
|
|
782344494c | ||
|
|
ae5c28dc8f | ||
|
|
47815e073d | ||
|
|
c0ad79188b | ||
|
|
1db3b6a397 | ||
|
|
cc132a1341 | ||
|
|
b65b58aa39 | ||
|
|
02a5139e29 | ||
|
|
c2762d8011 | ||
|
|
fae479ae57 | ||
|
|
e36f4cc0b7 | ||
|
|
b71cf3ee42 | ||
|
|
4b6348a8f5 | ||
|
|
e7c7ec8deb | ||
|
|
f873174eb2 | ||
|
|
c535e7d22d | ||
|
|
c2f413329d | ||
|
|
bc558be02d | ||
|
|
b9a3d82078 | ||
|
|
b053685160 | ||
|
|
54a2815648 | ||
|
|
6710ea144d | ||
|
|
9aec8146dc | ||
|
|
a609dde372 | ||
|
|
faf1933147 | ||
|
|
5a56892f32 | ||
|
|
be92e93c3c | ||
|
|
3eae718204 | ||
|
|
063b55e793 | ||
|
|
38ab94a024 | ||
|
|
a3f2ab37c3 | ||
|
|
070e84c6d6 | ||
|
|
2f1da222b8 | ||
|
|
78abc6fa6b | ||
|
|
8d4027e044 | ||
|
|
d65a0da5ed | ||
|
|
5607412605 | ||
|
|
6879528bb1 | ||
|
|
433c1bac3a | ||
|
|
9684f8f64b | ||
|
|
08cb764eb8 | ||
|
|
0fb44f0fd3 | ||
|
|
3f89d22f02 | ||
|
|
c54799a5c6 | ||
|
|
80d981be74 | ||
|
|
371a8a508e | ||
|
|
071e4f4de2 | ||
|
|
7c4edd2c9a | ||
|
|
ea16dcb4d2 | ||
|
|
bb0853aa9c | ||
|
|
1e542236d0 | ||
|
|
a0c17a9541 | ||
|
|
4a032000ae | ||
|
|
1750f8059b | ||
|
|
49df5b01f5 | ||
|
|
f870421f66 | ||
|
|
be2a38fedc | ||
|
|
882bc0e577 | ||
|
|
5f3a6c56f9 | ||
|
|
4af57ba1de | ||
|
|
ce93c7a56e | ||
|
|
07b58ccad7 | ||
|
|
b3702c0029 | ||
|
|
3be624df0d | ||
|
|
5bb9a38796 | ||
|
|
04a4eb876a | ||
|
|
c3d0989606 | ||
|
|
868b120be8 | ||
|
|
e305d7338a | ||
|
|
6c6b367bc7 | ||
|
|
28fd846546 | ||
|
|
32d1e5cbc3 | ||
|
|
567308acc4 | ||
|
|
b92002f3cc | ||
|
|
c0e4057ae1 | ||
|
|
1591f6e3b2 | ||
|
|
ed6104cdba | ||
|
|
69b88f5aa9 | ||
|
|
5a3b588ce8 | ||
|
|
57bce4edba | ||
|
|
18386734aa | ||
|
|
cdec61a841 | ||
|
|
5d62034ec7 | ||
|
|
051cb4c4aa | ||
|
|
dcb77fb517 | ||
|
|
d79d5f410a | ||
|
|
96f860a1bb | ||
|
|
909d69bc67 |
No files matched your search
@@ -0,0 +1,57 @@
|
||||
name: User Story template
|
||||
about: Vorlage für eine User Story mit Backend- und Frontend-Aufgaben
|
||||
title: "[User Story]: "
|
||||
body:
|
||||
- type: textarea
|
||||
id: user-story
|
||||
attributes:
|
||||
label: User Story
|
||||
description: Die User Story erscheint im Issue als Zitat (Zeilen mit `>` beginnen).
|
||||
placeholder: Als <Rolle> möchte ich <Ziel>, damit <Nutzen>.
|
||||
value: "> "
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: "# Technisch"
|
||||
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: "## Backend"
|
||||
|
||||
- type: textarea
|
||||
id: backend-beschreibung
|
||||
attributes:
|
||||
label: Was muss gemacht werden
|
||||
description: Fließtext
|
||||
validations:
|
||||
required: false
|
||||
|
||||
- type: textarea
|
||||
id: backend-todos
|
||||
attributes:
|
||||
label: To-Do Liste
|
||||
description: Pro Zeile ein To-Do, beliebig viele.
|
||||
value: "- [ ] "
|
||||
validations:
|
||||
required: false
|
||||
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: "## Frontend"
|
||||
|
||||
- type: textarea
|
||||
id: frontend-beschreibung
|
||||
attributes:
|
||||
label: Was muss gemacht werden
|
||||
description: Fließtext
|
||||
validations:
|
||||
required: false
|
||||
|
||||
- type: textarea
|
||||
id: frontend-todos
|
||||
attributes:
|
||||
label: To-Do Liste
|
||||
description: Pro Zeile ein To-Do, beliebig viele.
|
||||
value: "- [ ] "
|
||||
@@ -0,0 +1,57 @@
|
||||
name: User Story template
|
||||
about: Vorlage für eine User Story mit Backend- und Frontend-Aufgaben
|
||||
title: "[User Story]: "
|
||||
body:
|
||||
- type: textarea
|
||||
id: user-story
|
||||
attributes:
|
||||
label: User Story
|
||||
description: Die User Story erscheint im Issue als Zitat (Zeilen mit `>` beginnen).
|
||||
placeholder: Als <Rolle> möchte ich <Ziel>, damit <Nutzen>.
|
||||
value: "> "
|
||||
validations:
|
||||
required: true
|
||||
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: "# Technisch"
|
||||
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: "## Backend"
|
||||
|
||||
- type: textarea
|
||||
id: backend-beschreibung
|
||||
attributes:
|
||||
label: Was muss gemacht werden
|
||||
description: Fließtext
|
||||
validations:
|
||||
required: false
|
||||
|
||||
- type: textarea
|
||||
id: backend-todos
|
||||
attributes:
|
||||
label: To-Do Liste
|
||||
description: Pro Zeile ein To-Do, beliebig viele.
|
||||
value: "- [ ] "
|
||||
validations:
|
||||
required: false
|
||||
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: "## Frontend"
|
||||
|
||||
- type: textarea
|
||||
id: frontend-beschreibung
|
||||
attributes:
|
||||
label: Was muss gemacht werden
|
||||
description: Fließtext
|
||||
validations:
|
||||
required: false
|
||||
|
||||
- type: textarea
|
||||
id: frontend-todos
|
||||
attributes:
|
||||
label: To-Do Liste
|
||||
description: Pro Zeile ein To-Do, beliebig viele.
|
||||
value: "- [ ] "
|
||||
+24
-19
@@ -1,23 +1,28 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
target
|
||||
|
||||
# Output
|
||||
.output
|
||||
.vercel
|
||||
.netlify
|
||||
.wrangler
|
||||
/.svelte-kit
|
||||
/build
|
||||
|
||||
# OS
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
|
||||
# Env
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
!.env.test
|
||||
|
||||
# Vite
|
||||
vite.config.js.timestamp-*
|
||||
vite.config.ts.timestamp-*
|
||||
# H2
|
||||
data
|
||||
@@ -1,4 +1,79 @@
|
||||
# Einkaufsliste
|
||||
|
||||
Dies ist die Dokumentation des Projektes Einkaufsliste der WInfo Klasse
|
||||
DBWINFO B/C 05.
|
||||
Repository für das Webapp-Projekt, was eine Einkaufsliste zur Verfügung stellt.
|
||||
Es ist möglich, mehrere Listen anzulegen. In einer Liste kann man
|
||||
Gegenstände und Kategorien erstellen.
|
||||
Gegenständen können, aber müssen nicht Kategorien gehören.
|
||||
|
||||
## Dokumentation
|
||||
|
||||
### Entwicklungsverlauf und User Stories
|
||||
|
||||
Dieses Projekt hat seine Dokumentation über Gitea vorgenommen.
|
||||
Die Entwicklungshistorie ist über die Commitliste einsehbar,
|
||||
User-Stories, Erweiterungen/Änderungen am Projekt und andere
|
||||
Entwicklungsentscheidungen wurden über Issues abgewickelt.
|
||||
Es wurden auch Meilensteine verwendet um die Issues zu organisieren.
|
||||
|
||||
Bugs und Fehler wurden nicht mit Issues dokumentiert, da
|
||||
sie entweder während der Entwicklung auf einem anderen Branch beseitigt worden sind
|
||||
(wenn der Fehler von der Entwicklung des Branches kam) oder spontan gefixt.
|
||||
Die Commits, welche Bugs fixen sind mit `bug:` bzw. `bugfix:`
|
||||
gekennzeichnet und in der Commit-Historie auffindbar.
|
||||
|
||||
## Architektur
|
||||
|
||||
Die Seite verfolgt einen hybriden Ansatz. Das Backend schickt dem Browser eine HTML-Datei,
|
||||
welche in Teilen mit Attributen bei Custom Elementen und Daten befüllt sind.
|
||||
Der Client rendert dann die Custom Elemente.
|
||||
Die Webseite selbst ist so ziemlich im Frontend benutzbar.
|
||||
Ein Neuladen der Seite ist nicht nötig, mit Ausnahme wenn man
|
||||
zwischen Listen und der Listenübersicht wechselt.
|
||||
|
||||
Mehr über die Architektur findet sich unter [`docs/`](docs/DATENMODELL-ARCHITEKTUR.md)
|
||||
|
||||
### Backend
|
||||
|
||||
Für das Backend wurde Spring mit Thymeleaf für das Bereitstellen von Seiten genutzt (`src/main/java/de/timaldinger/einkaufsliste`).
|
||||
Das Backend ist über eine RESTful-API ansprechbar. Die Datenbank ist H2.
|
||||
|
||||
### Frontend
|
||||
|
||||
Für das Frontend wurde Vanilla-JS und CSS benutzt.
|
||||
Hinweis: Kategorien und Gegenstände können bearbeitet werden indem man auf sie drückt!
|
||||
|
||||
## API Übersicht
|
||||
|
||||
| Pfad | Zugelassene Methoden | Angesprochene Modelle |
|
||||
| ----------------- | ------------------------ | --------------------- |
|
||||
| `/api/lists` | GET, POST, DELETE, PATCH | Einkaufslisten |
|
||||
| `/api/categories` | GET, POST, DELETE, PATCH | Kategorien |
|
||||
| `/api/items` | GET, POST, DELETE, PATCH | Gegenstände |
|
||||
|
||||
Die vollständige API-Dokumentation befindet sich unter [`docs/`](/docs/API.md)
|
||||
|
||||
## Aufsetzen
|
||||
|
||||
Auf der Maschine muss Java 25 und Maven installiert sein.
|
||||
|
||||
```
|
||||
# Repo clonen
|
||||
git clone https://gitea.von.timaldinger.de/Technoir/einkaufsliste-web.git
|
||||
# Im Ordner
|
||||
mvn spring-boot:run
|
||||
```
|
||||
|
||||
Nun kann man im Browser `localhost:8080` aufrufen.
|
||||
|
||||
## Sonstiges
|
||||
|
||||
### Weitere Dokumentation
|
||||
|
||||
Weitere Dokumentation befindet sich unter [`docs/`](/docs)
|
||||
|
||||
### Nutzung von KI
|
||||
|
||||
Es wurde Claude Code Opus 4.8 genutzt. Die KI wurde zum Debuggen,
|
||||
bei scheinbar nicht erkennbaren Fehlern, großen Refactors, Hilfe beim Stylen der Seite und als Nachschlagewerk genutzt.
|
||||
Konzept-, Architekturentscheidungen und Umsetzung des Projekts liegen an mir.
|
||||
Vorschläge von KI wurden geprüft und bewusst übernommen oder verworfen.
|
||||
@@ -1,9 +0,0 @@
|
||||
# User stories
|
||||
|
||||
Liste der User Stories und ihr Status:
|
||||
|
||||
## Als ein Nutzer möchte ich
|
||||
|
||||
- ... Gegenstände mit Namen und Menge hinzufügen
|
||||
- ... Kategorien erstellen können und darunter Gegenstände hinzufügen
|
||||
- ... Kategorien samt Inhalt speichern und wiederaufrufen können
|
||||
+297
@@ -0,0 +1,297 @@
|
||||
# API
|
||||
|
||||
Die API versucht möglichst RESTful zu sein. Es hat:
|
||||
|
||||
- Ressourcen im Plural
|
||||
- Client-Server Trennung, Änderung der Daten auf der Oberfläche geschieht über `fetch()` an die API
|
||||
- Einheitliche Schnittstelle
|
||||
|
||||
Die Schnittstelle erfolgt vollständig über JSON.
|
||||
|
||||
Es wurde auf Cache-fähigkeit verzichtet aus Zeitgründen. HATEOAS ist auch nicht vorhanden,
|
||||
da Zeitgründe und fragwürdig, ob es für ein Projekt diesen Umfangs nötig ist.
|
||||
|
||||
## API Pfade
|
||||
|
||||
IDs sind im UUID Format
|
||||
|
||||
### Listen `/api/lists`
|
||||
|
||||
| Pfad | Methoden | Beschreibung | Parameter | Codes Erfolg |
|
||||
| ------------ | -------- | --------------------------------------------------- | ----------------------------------------- | ------------ |
|
||||
| `/api/lists` | `GET` | Gibt alle vorhandenen Listen zurück mit Name und ID | / | 200 |
|
||||
| | `POST` | Erlaubt es eine neue Liste zu erstellen | `listName` für den gewünschten Listenname | 201 |
|
||||
|
||||
#### `GET /api/lists` - Alle Listen
|
||||
|
||||
##### Body Beispiel
|
||||
|
||||
Leer
|
||||
|
||||
##### Response Beispiel
|
||||
|
||||
```json
|
||||
[
|
||||
{
|
||||
"listName": "Liste 1",
|
||||
"listID": "ddb3ac36-8213-4f9d-bf1e-39c836768e57"
|
||||
},
|
||||
{
|
||||
"listName": "Liste 2",
|
||||
"listID": "8937a2fa-2ab1-4b1e-8ee2-17bb0358dc1f"
|
||||
},
|
||||
...
|
||||
]
|
||||
```
|
||||
|
||||
#### `POST /api/lists` - Erstellen einer Liste
|
||||
|
||||
##### Body Beispiel
|
||||
|
||||
```json
|
||||
{
|
||||
"listName": "Listenname"
|
||||
}
|
||||
```
|
||||
|
||||
##### Response Beispiel
|
||||
|
||||
```json
|
||||
{
|
||||
"listName": "Listenname",
|
||||
"listID": "ddb3ac36-8213-4f9d-bf1e-39c836768e57"
|
||||
}
|
||||
```
|
||||
|
||||
### Liste `/api/lists`
|
||||
|
||||
| Pfad | Methoden | Beschreibung | Parameter | Codes Erfolg |
|
||||
| ----------------- | -------- | ------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------- | ------------ |
|
||||
| `/api/lists/{id}` | GET | Gibt alle Gegenstände und Kategorien (mit ihren Gegenständen) in der Liste mit der UUID id zurück | `id`: UUID der Liste in der URL | 200 |
|
||||
| | PATCH | Verändert den Namen der Liste | `id`: UUID der Liste in der URL. Im Body `listName` für den neuen Namen | 204 |
|
||||
| | DELETE | löscht eine Liste | `id`: UUID Der Liste in der URL | 204 |
|
||||
|
||||
#### GET `/api/lists/{id}` - Inhalt der Liste
|
||||
|
||||
##### Body Beispiel
|
||||
|
||||
/
|
||||
|
||||
##### Response Beispiel
|
||||
|
||||
```json
|
||||
{
|
||||
"categories": [
|
||||
{
|
||||
"categoryName": "testkategorie",
|
||||
"items": [
|
||||
{
|
||||
"status": false,
|
||||
"itemName": "test",
|
||||
"itemAmount": "1",
|
||||
"itemID": "99403d02-4771-4a5a-b6a7-6f3af0a5ee84",
|
||||
"categoryID": "08bedce1-9b25-4fe6-9ede-4d9ee3a904d4",
|
||||
"listID": "9038b8ef-7be8-4dcb-9229-6f51b11be137"
|
||||
},
|
||||
{
|
||||
"status": true,
|
||||
"itemName": "test",
|
||||
"itemAmount": "2",
|
||||
"itemID": "fc2806f6-d430-49f8-8c56-a6e2bc9792a7",
|
||||
"categoryID": "08bedce1-9b25-4fe6-9ede-4d9ee3a904d4",
|
||||
"listID": "9038b8ef-7be8-4dcb-9229-6f51b11be137"
|
||||
}
|
||||
],
|
||||
"categoryID": "08bedce1-9b25-4fe6-9ede-4d9ee3a904d4"
|
||||
}
|
||||
],
|
||||
"itemsNoCategory": [ //Gegenstände ohne Kategorie
|
||||
{
|
||||
"status": false,
|
||||
"itemName": "test",
|
||||
"itemAmount": "3",
|
||||
"itemID": "38a0991e-4b51-42d7-b12c-0ddbcf6f583e",
|
||||
"categoryID": null,
|
||||
"listID": "9038b8ef-7be8-4dcb-9229-6f51b11be137"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
#### `PATCH /api/lists/{id}` - Bearbeiten der Liste
|
||||
|
||||
##### Body
|
||||
|
||||
```json
|
||||
{
|
||||
"listName": "neuer Listname"
|
||||
}
|
||||
```
|
||||
|
||||
##### Response
|
||||
|
||||
/
|
||||
|
||||
#### `DELETE /api/lists/{id}` - Löschen einer Liste
|
||||
|
||||
##### Body
|
||||
|
||||
/
|
||||
|
||||
##### Response
|
||||
|
||||
/
|
||||
|
||||
### Kategorien `/api/categories`
|
||||
|
||||
| Pfad | Methoden | Beschreibung | Parameter | Codes Erfolg |
|
||||
| ---------------------- | -------- | ------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- | ------------ |
|
||||
| `/api/categories/{id}` | `GET` | Gibt den Inhalt der Kategorie zurück | / | 200 |
|
||||
| | `POST` | Erlaubt es eine neue Kategorie zu erstellen | `categoryName` im Body für den gewünschten Kategorienamen | 201 |
|
||||
| | `PATCH` | Ändern vom Namen der Liste | `categoryName` im Body für neuen Kategorienamen | 204 |
|
||||
| | `DELETE` | Löschen einer Liste | `deleteAllItems=(true\|false)` als Queryparameter. Entscheidet, ob Gegenstände in der Kategorie mitgelöscht werden sollen | 204 |
|
||||
|
||||
#### `GET /api/categories/{id}` - Inhalt der Kategorie
|
||||
|
||||
##### Body Beispiel
|
||||
|
||||
/
|
||||
|
||||
##### Response Beispiel
|
||||
|
||||
```json
|
||||
{
|
||||
"categoryName": "testkategorie",
|
||||
"items": [
|
||||
{
|
||||
"status": false,
|
||||
"itemName": "test",
|
||||
"itemAmount": "1",
|
||||
"itemID": "99403d02-4771-4a5a-b6a7-6f3af0a5ee84",
|
||||
"categoryID": "08bedce1-9b25-4fe6-9ede-4d9ee3a904d4",
|
||||
"listID": "9038b8ef-7be8-4dcb-9229-6f51b11be137"
|
||||
}
|
||||
],
|
||||
"categoryID": "08bedce1-9b25-4fe6-9ede-4d9ee3a904d4"
|
||||
}
|
||||
```
|
||||
|
||||
#### `POST /api/categories` - Erstellen einer Kategorie
|
||||
|
||||
##### Body Beispiel
|
||||
|
||||
```json
|
||||
{
|
||||
"categoryName": "testKategorie",
|
||||
"listID": "9038b8ef-7be8-4dcb-9229-6f51b11be137"
|
||||
}
|
||||
```
|
||||
|
||||
##### Response Beispiel
|
||||
|
||||
```json
|
||||
{
|
||||
"categoryName": "testKategorie",
|
||||
"categoryID": "08bedce1-9b25-4fe6-9ede-4d9ee3a904d4"
|
||||
}
|
||||
```
|
||||
|
||||
#### `PATCH /api/categories/{id}` - Bearbeiten der Kategorie
|
||||
|
||||
##### Body Beispiel
|
||||
|
||||
```json
|
||||
{
|
||||
"categoryName": "Gemüse"
|
||||
}
|
||||
```
|
||||
|
||||
##### Response
|
||||
|
||||
/
|
||||
|
||||
#### `DELETE /api/categories/{id}?deleteAllItems=(true|false)`
|
||||
|
||||
##### Body
|
||||
|
||||
/
|
||||
|
||||
##### Response
|
||||
|
||||
/
|
||||
|
||||
### Gegenstände `/api/items`
|
||||
|
||||
| Pfad | Methoden | Beschreibung | Parameter | Codes Erfolg |
|
||||
| ----------------- | -------- | ----------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- | ------------ |
|
||||
| `/api/items/{id}` | `GET` | Gibt den Inhalt des Gegenstands zurück | / | 200 |
|
||||
| | `POST` | Erlaubt es einen neuen Gegenstand zu erstellen | `itemName,itemAmount,categoryID?,listID` im Body, für den Namen und Menge (entweder beide oder mindst einer muss vorhanden sein). | 201 |
|
||||
| | `PATCH` | Ändern vom Namen, Menge oder Status eines Gegenstands | `itemName, itemAmount, isDone, categoryID` im Body. | 204 |
|
||||
| | `DELETE` | Löschen eines Gegenstands | / | 204 |
|
||||
|
||||
#### `GET /api/items/{id}` - Inhalt des Gegenstands
|
||||
|
||||
##### Body Beispiel
|
||||
|
||||
/
|
||||
|
||||
##### Response Beispiel
|
||||
|
||||
```json
|
||||
{
|
||||
"status": false,
|
||||
"itemName": "Milch",
|
||||
"itemAmount": "1L",
|
||||
"itemID": "38a0991e-4b51-42d7-b12c-0ddbcf6f583e",
|
||||
"categoryID": "08bedce1-9b25-4fe6-9ede-4d9ee3a904d4",
|
||||
"listID": "9038b8ef-7be8-4dcb-9229-6f51b11be137"
|
||||
}
|
||||
```
|
||||
|
||||
#### `POST /api/items` - Erstellen eines Gegenstands
|
||||
|
||||
##### Body Beispiel
|
||||
|
||||
```json
|
||||
{
|
||||
"itemName": "Milch",
|
||||
"itemAmount": "1L",
|
||||
"categoryID": "08bedce1-9b25-4fe6-9ede-4d9ee3a904d4",
|
||||
"listID": "9038b8ef-7be8-4dcb-9229-6f51b11be137"
|
||||
}
|
||||
```
|
||||
|
||||
##### Response Beispiel
|
||||
|
||||
```json
|
||||
{
|
||||
"itemName": "Milch",
|
||||
"itemAmount": "1L",
|
||||
"itemID": "38a0991e-4b51-42d7-b12c-0ddbcf6f583e",
|
||||
"categoryID": "08bedce1-9b25-4fe6-9ede-4d9ee3a904d4"
|
||||
}
|
||||
```
|
||||
|
||||
#### `PATCH /api/items/{id}` - Bearbeiten eines Gegenstands
|
||||
|
||||
##### Body Beispiel
|
||||
|
||||
```json
|
||||
{
|
||||
"isDone": true
|
||||
}
|
||||
```
|
||||
|
||||
##### Response
|
||||
|
||||
/
|
||||
|
||||
#### `DELETE /api/items/{id}` - Löschen eines Gegenstands
|
||||
|
||||
##### Body
|
||||
|
||||
/
|
||||
|
||||
##### Response
|
||||
|
||||
/
|
||||
@@ -0,0 +1,168 @@
|
||||
# Datenmodell und Architektur
|
||||
|
||||
Das Projekt nutzt die Modelle `ShoppingList`, `ShoppingItem` und `ShoppingCategory`.
|
||||
Neben den Spring und Thymeleaf Bibliotheken wurde noch zusätzlich `lombok` genutzt.
|
||||
Lombok stellt Annotationen bereit um Boilerplatecode zu vermeiden.
|
||||
|
||||
## Diagramm
|
||||
|
||||
```mermaid
|
||||
erDiagram
|
||||
ShoppingList ||--o{ ShoppingCategory : hat
|
||||
ShoppingList ||--o{ ShoppingItem : hat
|
||||
ShoppingCategory ||--o{ ShoppingItem : enthält
|
||||
```
|
||||
|
||||
## Modelle
|
||||
|
||||
### ShoppingList
|
||||
|
||||
Eine ShoppingList hat beliebig viele ShoppingCategory und ShoppingItem.
|
||||
Der Name darf nicht leer sein.
|
||||
|
||||
### ShoppingCategory
|
||||
|
||||
Eine ShoppingCategory hat beliebig viele ShoppingItem.
|
||||
Der Name darf nicht leer sein.
|
||||
|
||||
### ShoppingItem
|
||||
|
||||
Ein ShoppingItem hat sowohl einen Namen als auch eine Menge.
|
||||
Der Nutzer hat und sollte die Freiheit haben,
|
||||
die Felder so zu befüllen wie er will.
|
||||
Es findet deshalb keine Eingabevalidierung in dem Sinne statt,
|
||||
dass bei Menge nur Mengeneinheiten stehen dürfen oder im Namen keine Zahlen.
|
||||
Die einzige Anforderung ist es, dass der Nutzer einen der beiden Felder
|
||||
ausfüllen muss.
|
||||
|
||||
## Architektur Backend (`src/main/java/de/timaldinger/einkaufsliste/`)
|
||||
|
||||
### Controller (`Controller/`)
|
||||
|
||||
Hier liegen die Controller welche HTTP-Anfragen abwickeln.
|
||||
`PageController` ist zuständig für das Bereitstellen von den einzelnen Seiten.
|
||||
Die restlichen Controller sind RESTController, welche die API-Schnittstelle
|
||||
behandeln. Sie sind nach der betroffenen Ressource aufgeteilt.
|
||||
|
||||
### Data Transfer Objects (`Dto/`)
|
||||
|
||||
Die Webapp nutzt sogenannte DTOs (Data transfer objects)
|
||||
um die geschickten JSON-Daten auf das Model abzubilden. Diese liegen unter `Dto/`.
|
||||
Dort sind die DTOs nochmal nach den HTTP-Methoden aufgeteilt, da je nach Methode
|
||||
der Nutzer unterschiedliche Daten mitschicken tut.
|
||||
|
||||
### Exceptions (`Exceptions/`)
|
||||
|
||||
Hier liegen benutzerdefinierte Fehlermeldungen, die an das Frontend geschickt werden
|
||||
(hauptsächlich für 400 und 404)
|
||||
und ein eigener Exception Handler `GlobalExceptionHandler.java`.
|
||||
Dieser wurde erstellt damit Fehlermeldungen
|
||||
besser dargestellt werden können und keine Spring-Fehlermeldungen an das Frontend
|
||||
geschickt werden.
|
||||
Er ist mit `@RestControllerAdvice` annotiert, das heißt,
|
||||
dass er für alle anderen Controller gilt. Er greift, wenn ein Fehler von
|
||||
einer Controllerklasse aus propagiert. Er implementiert Methoden annotiert
|
||||
mit `@ExceptionHandler`, welche angibt, für welche Funktion ein geworfener Fehler
|
||||
in einer Funktion des Controllers greift. Es werden in den Controllern die
|
||||
Custom Exceptions geworfen.
|
||||
|
||||
Die CustomException-Klassen erben von `RuntimeException`.
|
||||
|
||||
Das Record `ErrorResponse.java` stellt einen JSON-Body dar um daraus die Fehlermeldung
|
||||
zu bauen die an das Frontend geschickt wird.
|
||||
|
||||
### Mapper (`Mapper/`)
|
||||
|
||||
Klassen, welche die Models aus der Datenbank zu DTOs mappen. Nötig um GET
|
||||
Anfragen zu nutzen.
|
||||
|
||||
### Models (`Models/`)
|
||||
|
||||
Unter `Models/` liegen die Modelle. Die Modelle werden in der Datenbank
|
||||
so abgebildet wie sie in der Klasse definiert sind. Auch sind Relationen
|
||||
der Entities wie sie in der Datenbank seien sollen abgebildet mit
|
||||
Annotationen wie `@ManyToOne`. Es gibt eine abstrakte Klasse `ShoppingElement`,
|
||||
von welcher alle anderen Entities erben. Die Klasse hat eine Variable `id`,
|
||||
welche ihre Unterklassen dann auch haben. Die Klasse selbst wird nicht
|
||||
in der Datenbank abgebildet.
|
||||
|
||||
### Repository (`Repository/`)
|
||||
|
||||
Interfaces, die das JpaRepositories-Interface implementieren. Das JPARep wurde genommen,
|
||||
da man dort Bulkfunktionen wie `saveAll` und `findAll` nutzen kann,
|
||||
Rückgabetypen wie `List` erlaubt sind und diese auch eine `h2`-db
|
||||
Implementierung aufweist.
|
||||
|
||||
### Services (`Service/`)
|
||||
|
||||
Serviceklassen, welche Methoden für die Controller zur Verfügung stellen,
|
||||
um die jeweile HTTP-Request erfüllen zu können. Sie kapseln die Logik von den Controllern.
|
||||
|
||||
### Templating (`src/main/resources/templates`)
|
||||
|
||||
Da die Webapp einen Hybridansatz beim Rendering verfolgt, wurden Thymeleaf-Templates
|
||||
genutzt um die Seite beim Aufrufen bereitzustellen. Die `PageController` Klasse
|
||||
stellt diese bereit.
|
||||
|
||||
## Architektur Frontend (`src/main/resources/static`)
|
||||
|
||||
Genutzt wurde Vanilla-JS und CSS. Das CSS liegt unter `static/css` und das JS unter `static/js`.
|
||||
Jede aufrufbare Seite (`/` und `/list`) hat seinen eigenen Ordner, wo für die Seite
|
||||
spezifische JS Dateien liegen. Hier finden sich zwei Unterordner: `api/` und `frontend/`.
|
||||
Unter jenen Ordner befinden sich Funktionen die jeweils API und UI abwickeln.
|
||||
Die `.js` Datei die in dem Ordnerroot liegt, nutzt und bündelt diese.
|
||||
Die Trennung wurde getätigt um bessere Übersicht und
|
||||
sauberere Entwicklung zu ermöglichen.
|
||||
Unter `shared/` liegen Dateien, die von alle Seiten
|
||||
genutzt werden. Unter Models liegen die Implementierungen der CustomHTML-Elemente.
|
||||
|
||||
### Custom Elemente (`/static/js/models`)
|
||||
|
||||
Im Laufe der Entwicklung wurden CustomHTML Elemente genommen, um die ShoppingList,
|
||||
ShoppingCategory und ShoppingItems darzustellen und besser zu handhaben. Es wurde
|
||||
sich für ein LightDOM Ansatz entschieden, da zum einen die Eventpropagation einfacher
|
||||
zu gestalten ist (EventListener auf `div`) und zum anderen die CSS Klassen greifen.
|
||||
Mit einem Shadow-DOM Ansatz mit zB `templates` wäre das umständlicher.
|
||||
|
||||
### Index Seite (`/static/js/pages/index`)
|
||||
|
||||
Hier liegen nötige Javascriptdateien für die Root Seite `/`.
|
||||
Unter `/api` liegen die API Methoden, unter `/frontend` UI Methoden
|
||||
|
||||
### List Seite (`static/js/pages/list`)
|
||||
|
||||
Hier liegen nötige Javascriptdateien für die Seite `/list/{id}`.
|
||||
Unter `/api` liegen die API Methoden, unter `/frontend` UI Methoden.
|
||||
Da die Seite sowohl Kategorien als auch Gegenstände
|
||||
behandelt sind in den Ordnern jeweils API und UI Dateien für die beiden Elemente.
|
||||
Die Imports sind dann in den jeweilen `listUI.js` und `listAPI.js` gebündelt
|
||||
welche dann in die `list.js` importiert wird.
|
||||
|
||||
### Shared Module (`static/js/shared`)
|
||||
|
||||
#### editing.js
|
||||
|
||||
Hier liegt die Logik, welche genutzt wird um eines
|
||||
der Elemente (Liste, Kategorie, Gegenstand) zu bearbeiten.
|
||||
Zusammen mit `sharedUI.js` bildet sie den Ablauf ab.
|
||||
Die beiden Dateien sind bewusst getrennt,
|
||||
da die Funktion `editElement()` eine Mischung aus UI und API Aufrufe hat.
|
||||
Das Muster, dass API und UI Funktionen in getrennten Dateien leben,
|
||||
sollte beibehalten werden. Es wurde nur die editElement() Funktion
|
||||
generalisiert, da die Bearbeitung eines Elementes für alle drei Models
|
||||
gleich abläuft im Gegensatz zu dem Hinzufügen und Löschen dieser.
|
||||
|
||||
#### error.js
|
||||
|
||||
Globale Fehlermeldungsdarstellung. Eine Clientseitige Validierung findet
|
||||
nicht statt, da sie serverseitig behandelt werden.
|
||||
|
||||
#### helper.js
|
||||
|
||||
Hilfsfunktion für das Abwickeln von `fetch()` Anfragen.
|
||||
Zur Vereinheitlichung der Funktionen die API calls nutzen.
|
||||
|
||||
#### sharedUI.js
|
||||
|
||||
Stellt UI-Funktionen bereit, die alle Seiten nutzen. Momentan nur für
|
||||
Bearbeitung der Elemente.
|
||||
-29
@@ -1,29 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Einkaufsliste</title>
|
||||
<link href="css/style.css" rel="stylesheet">
|
||||
<script src="js/index.js" defer></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="title">
|
||||
<h1>Einkaufsliste</h1>
|
||||
</div>
|
||||
|
||||
<div class="list">
|
||||
<form class="list__inputForm">
|
||||
<input type="text" class="list__inputForm__itemName" name="itemName">
|
||||
<input type="text" class="list__inputForm__itemAmount" name="itemAmount">
|
||||
<button class="list__inputForm__submitButton" type="submit">Hinzufügen</button>
|
||||
</form>
|
||||
|
||||
|
||||
<ul class="list__displayedList">
|
||||
</ul>
|
||||
|
||||
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
-49
@@ -1,49 +0,0 @@
|
||||
|
||||
const form = document.querySelector(".list__inputForm");
|
||||
const itemList = document.querySelector(".list__displayedList");
|
||||
|
||||
let listItems = []; //list of items that the user has
|
||||
|
||||
|
||||
function handleListElement(itemName, itemAmount,) {
|
||||
listItems.push({ name: itemName, amount: itemAmount });
|
||||
renderList();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function renderList() {
|
||||
itemList.innerHTML = ""; //reset innerItemList
|
||||
|
||||
listItems.forEach((element, index) => {
|
||||
const li = document.createElement("li");
|
||||
const removeButton = document.createElement("button");
|
||||
|
||||
removeButton.textContent = "Löschen";
|
||||
removeButton.addEventListener("click", () => {
|
||||
listItems.splice(index, 1);
|
||||
renderList();
|
||||
});
|
||||
|
||||
li.textContent = element.name + " " + element.amount;
|
||||
li.appendChild(removeButton)
|
||||
|
||||
itemList.appendChild(li);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
function init() {
|
||||
|
||||
document.querySelector(".list__inputForm").addEventListener("submit", (event) => {
|
||||
if (!form.checkValidity()) return;
|
||||
event.preventDefault();
|
||||
formData = Object.fromEntries(new FormData(form));
|
||||
handleListElement(formData.itemName, formData.itemAmount);
|
||||
});
|
||||
}
|
||||
|
||||
init();
|
||||
@@ -0,0 +1,132 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>4.1.1</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>de.timaldinger</groupId>
|
||||
<artifactId>einkaufsliste</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name/>
|
||||
<description/>
|
||||
<url/>
|
||||
<licenses>
|
||||
<license/>
|
||||
</licenses>
|
||||
<developers>
|
||||
<developer/>
|
||||
</developers>
|
||||
<scm>
|
||||
<connection/>
|
||||
<developerConnection/>
|
||||
<tag/>
|
||||
<url/>
|
||||
</scm>
|
||||
<properties>
|
||||
<java.version>25</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-rest</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-webmvc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
<scope>runtime</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-rest-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-thymeleaf-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-webmvc-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>default-compile</id>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>default-testCompile</id>
|
||||
<phase>test-compile</phase>
|
||||
<goals>
|
||||
<goal>testCompile</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,52 @@
|
||||
package de.timaldinger.einkaufsliste.Controller;
|
||||
|
||||
import de.timaldinger.einkaufsliste.Exceptions.ResourceNotFoundException;
|
||||
import de.timaldinger.einkaufsliste.Models.ShoppingList;
|
||||
import de.timaldinger.einkaufsliste.Repository.ShoppingCategoryRepository;
|
||||
import de.timaldinger.einkaufsliste.Repository.ShoppingItemRepository;
|
||||
import de.timaldinger.einkaufsliste.Repository.ShoppingListRepository;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/")
|
||||
public class PageController {
|
||||
|
||||
@Autowired
|
||||
private ShoppingListRepository shoppingListRepository;
|
||||
|
||||
@Autowired
|
||||
private ShoppingCategoryRepository shoppingCategoryRepository;
|
||||
|
||||
@Autowired
|
||||
private ShoppingItemRepository shoppingItemRepository;
|
||||
|
||||
@GetMapping("/")
|
||||
public String index(Model model){
|
||||
model.addAttribute("lists", shoppingListRepository.findAll());
|
||||
return "index";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt die list.html Seite einer Liste zurück mit den Attributen list, categories und items
|
||||
* @param model
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/list/{id}")
|
||||
public String list(Model model, @PathVariable UUID id){
|
||||
ShoppingList list = shoppingListRepository.findById(id).orElseThrow(() -> new ResourceNotFoundException("Seite",id));
|
||||
List<ShoppingList> lists = shoppingListRepository.findAll();
|
||||
model.addAttribute("lists", lists);
|
||||
model.addAttribute("list", list);
|
||||
model.addAttribute("categories", shoppingCategoryRepository.findByList(list));
|
||||
model.addAttribute("items", shoppingItemRepository.findByList_IdAndCategoryIsNull(id));
|
||||
return "list";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package de.timaldinger.einkaufsliste.Controller;
|
||||
|
||||
import de.timaldinger.einkaufsliste.Dto.Get.ShoppingCategoryGetDTO;
|
||||
import de.timaldinger.einkaufsliste.Dto.Patch.ShoppingCategoryPatchDTO;
|
||||
import de.timaldinger.einkaufsliste.Dto.Post.ShoppingCategoryPostDTO;
|
||||
import de.timaldinger.einkaufsliste.Dto.Post.Response.ShoppingCategoryPostResponseDTO;
|
||||
import de.timaldinger.einkaufsliste.Service.ShoppingCategoryService;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.UUID;
|
||||
|
||||
@RestController
|
||||
public class ShoppingCategoryController {
|
||||
|
||||
@Autowired
|
||||
private ShoppingCategoryService shoppingCategoryService;
|
||||
|
||||
@GetMapping("/api/categories/{categoryID}")
|
||||
public ResponseEntity<ShoppingCategoryGetDTO> getCategory(@PathVariable UUID categoryID){
|
||||
return ResponseEntity.ok().body(shoppingCategoryService.getCategory(categoryID));
|
||||
}
|
||||
|
||||
@PostMapping("/api/categories")
|
||||
public ResponseEntity<ShoppingCategoryPostResponseDTO> addCategory(@Valid @RequestBody ShoppingCategoryPostDTO newCategory){
|
||||
ShoppingCategoryPostResponseDTO created = shoppingCategoryService.addCategory(newCategory);
|
||||
|
||||
URI location = ServletUriComponentsBuilder
|
||||
.fromCurrentRequest()
|
||||
.path("/{id}")
|
||||
.buildAndExpand(created.categoryID())
|
||||
.toUri();
|
||||
|
||||
return ResponseEntity.created(location).body(created);
|
||||
}
|
||||
|
||||
@PatchMapping("/api/categories/{categoryID}")
|
||||
public ResponseEntity<Void> editCategory(@PathVariable UUID categoryID, @Valid @RequestBody ShoppingCategoryPatchDTO toChange){
|
||||
shoppingCategoryService.editCategory(categoryID, toChange);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@DeleteMapping("/api/categories/{categoryID}")
|
||||
public ResponseEntity<Void> deleteCategory(@PathVariable UUID categoryID, @RequestParam(required = false) Boolean deleteAllItems){
|
||||
shoppingCategoryService.deleteCategory(categoryID, deleteAllItems);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package de.timaldinger.einkaufsliste.Controller;
|
||||
|
||||
import de.timaldinger.einkaufsliste.Dto.Get.ShoppingItemGetDTO;
|
||||
import de.timaldinger.einkaufsliste.Dto.Patch.ShoppingItemPatchDTO;
|
||||
import de.timaldinger.einkaufsliste.Dto.Post.ShoppingItemPostDTO;
|
||||
import de.timaldinger.einkaufsliste.Dto.Post.Response.ShoppingItemPostResponseDTO;
|
||||
import de.timaldinger.einkaufsliste.Service.ShoppingItemService;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.UUID;
|
||||
|
||||
@RestController
|
||||
public class ShoppingItemController {
|
||||
|
||||
@Autowired
|
||||
private ShoppingItemService shoppingItemService;
|
||||
|
||||
@GetMapping("/api/items/{itemID}")
|
||||
public ResponseEntity<ShoppingItemGetDTO> getItem(@PathVariable UUID itemID){
|
||||
return ResponseEntity.ok().body(shoppingItemService.getItem(itemID));
|
||||
}
|
||||
|
||||
@PostMapping("/api/items")
|
||||
public ResponseEntity<ShoppingItemPostResponseDTO> addItem(@Valid @RequestBody ShoppingItemPostDTO newItem){
|
||||
ShoppingItemPostResponseDTO created = shoppingItemService.addItem(newItem);
|
||||
|
||||
URI location = ServletUriComponentsBuilder
|
||||
.fromCurrentRequest()
|
||||
.path("/{id}")
|
||||
.buildAndExpand(created.itemID())
|
||||
.toUri();
|
||||
|
||||
return ResponseEntity.created(location).body(created);
|
||||
}
|
||||
|
||||
@PatchMapping("/api/items/{itemID}")
|
||||
public ResponseEntity<Void> editItem(@PathVariable UUID itemID, @Valid @RequestBody ShoppingItemPatchDTO toChange){
|
||||
shoppingItemService.editItem(itemID, toChange);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@DeleteMapping("/api/items/{itemID}")
|
||||
public ResponseEntity<Void> deleteItem(@PathVariable UUID itemID){
|
||||
shoppingItemService.deleteItem(itemID);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@DeleteMapping("/api/lists/{listID}/items")
|
||||
public ResponseEntity<Void> deleteAllDoneItems(@PathVariable UUID listID, @RequestParam boolean done){
|
||||
shoppingItemService.deleteAllDoneItems(listID, done);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package de.timaldinger.einkaufsliste.Controller;
|
||||
|
||||
import de.timaldinger.einkaufsliste.Dto.Get.ShoppingListGetDTO;
|
||||
import de.timaldinger.einkaufsliste.Dto.Get.ShoppingListsGetDTO;
|
||||
import de.timaldinger.einkaufsliste.Dto.Patch.ShoppingListPatchDTO;
|
||||
import de.timaldinger.einkaufsliste.Dto.Post.ShoppingListPostDTO;
|
||||
import de.timaldinger.einkaufsliste.Dto.Post.Response.ShoppingListPostResponseDTO;
|
||||
import de.timaldinger.einkaufsliste.Service.ShoppingListService;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@RestController
|
||||
public class ShoppingListController {
|
||||
|
||||
@Autowired
|
||||
private ShoppingListService shoppingListService;
|
||||
|
||||
@GetMapping("/api/lists")
|
||||
public ResponseEntity<List<ShoppingListsGetDTO>> getLists(){
|
||||
return ResponseEntity.ok().body(shoppingListService.getLists());
|
||||
}
|
||||
|
||||
@GetMapping("/api/lists/{listID}")
|
||||
public ResponseEntity<ShoppingListGetDTO> getList(@PathVariable UUID listID){
|
||||
return ResponseEntity.ok().body(shoppingListService.getList(listID));
|
||||
}
|
||||
|
||||
@PostMapping("/api/lists")
|
||||
public ResponseEntity<ShoppingListPostResponseDTO> addList(@Valid @RequestBody ShoppingListPostDTO newList){
|
||||
ShoppingListPostResponseDTO created = shoppingListService.addList(newList);
|
||||
|
||||
URI location = ServletUriComponentsBuilder
|
||||
.fromCurrentRequest()
|
||||
.path("/{id}")
|
||||
.buildAndExpand(created.listID())
|
||||
.toUri();
|
||||
|
||||
return ResponseEntity.created(location).body(created);
|
||||
}
|
||||
|
||||
@DeleteMapping("/api/lists/{listID}")
|
||||
public ResponseEntity<Void> deleteList(@PathVariable UUID listID){
|
||||
shoppingListService.deleteList(listID);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@PatchMapping("/api/lists/{listID}")
|
||||
public ResponseEntity<Void> editList(@PathVariable UUID listID, @Valid @RequestBody ShoppingListPatchDTO toChange){
|
||||
shoppingListService.editList(listID, toChange);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package de.timaldinger.einkaufsliste.Dto.Get;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public record ShoppingCategoryGetDTO(String categoryName, List<ShoppingItemGetDTO> items, UUID categoryID) {
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package de.timaldinger.einkaufsliste.Dto.Get;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public record ShoppingItemGetDTO(boolean status, String itemName, String itemAmount, UUID itemID, UUID categoryID, UUID listID) {
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package de.timaldinger.einkaufsliste.Dto.Get;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public record ShoppingListGetDTO(List<ShoppingCategoryGetDTO> categories, List<ShoppingItemGetDTO> itemsNoCategory) {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package de.timaldinger.einkaufsliste.Dto.Get;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public record ShoppingListsGetDTO(String listName, UUID listID){
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package de.timaldinger.einkaufsliste.Dto.Patch;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Size;
|
||||
|
||||
public record ShoppingCategoryPatchDTO(@NotBlank(message = "Kategoriename darf nicht leer sein!")
|
||||
@Size(max = 50, message = "Kategoriename darf nicht länger als 50 Zeichen sein!")
|
||||
String categoryName) {
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package de.timaldinger.einkaufsliste.Dto.Patch;
|
||||
|
||||
import jakarta.validation.constraints.AssertTrue;
|
||||
import jakarta.validation.constraints.Size;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public record ShoppingItemPatchDTO(@Size(max = 50, message = "Name darf nicht länger als 50 Zeichen sein!") String itemName,
|
||||
@Size(max = 50, message = "Menge darf nicht länger als 50 Zeichen sein!") String itemAmount,
|
||||
Boolean isDone, UUID categoryID) {
|
||||
|
||||
@AssertTrue(message = "Wenigstens eines der Felder muss ausgefüllt sein!")
|
||||
private boolean isAtleastOneNotBlank(){
|
||||
boolean n = itemName != null && !itemName.isBlank();
|
||||
boolean a = itemAmount != null && !itemAmount.isBlank();
|
||||
return n || a || isDone != null || categoryID != null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package de.timaldinger.einkaufsliste.Dto.Patch;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Size;
|
||||
|
||||
public record ShoppingListPatchDTO(@NotBlank(message = "Listenname darf nicht leer sein!")
|
||||
@Size(max = 50, message = "Listenname darf nicht länger als 50 Zeichen sein!")
|
||||
String listName) {
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package de.timaldinger.einkaufsliste.Dto.Post.Response;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public record ShoppingCategoryPostResponseDTO(String categoryName, UUID categoryID){
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package de.timaldinger.einkaufsliste.Dto.Post.Response;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public record ShoppingItemPostResponseDTO(String itemName, String itemAmount, UUID itemID, UUID categoryID) {
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package de.timaldinger.einkaufsliste.Dto.Post.Response;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public record ShoppingListPostResponseDTO(String listName, UUID listID){
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package de.timaldinger.einkaufsliste.Dto.Post;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Size;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public record ShoppingCategoryPostDTO(@NotBlank(message = "Kategoriename darf nicht leer sein!")
|
||||
@Size(max = 50, message = "Kategoriename darf nicht länger als 50 Zeichen sein!")
|
||||
String categoryName, UUID listID) {
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package de.timaldinger.einkaufsliste.Dto.Post;
|
||||
|
||||
import jakarta.validation.constraints.AssertTrue;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public record ShoppingItemPostDTO( @Size(max = 50, message = "Kategoriename darf nicht länger als 50 Zeichen sein!")
|
||||
String itemName,
|
||||
@Size(max = 50, message = "Kategoriename darf nicht länger als 50 Zeichen sein!")
|
||||
String itemAmount,
|
||||
UUID categoryID,
|
||||
@NotNull(message = "listID must not be empty!")
|
||||
UUID listID){
|
||||
|
||||
@AssertTrue(message = "Wenigstens eines der Felder muss ausgefüllt sein!")
|
||||
private boolean isAtleastOneNotBlank(){
|
||||
boolean n = itemName != null && !itemName.isBlank();
|
||||
boolean a = itemAmount != null && !itemAmount.isBlank();
|
||||
return n || a;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package de.timaldinger.einkaufsliste.Dto.Post;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.Size;
|
||||
|
||||
public record ShoppingListPostDTO(@NotBlank(message = "Listenname darf nicht leer sein!")
|
||||
@Size(max = 50, message = "Listenname darf nicht länger als 50 Zeichen sein!")
|
||||
String listName) {
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package de.timaldinger.einkaufsliste;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class EinkaufslisteApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(EinkaufslisteApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package de.timaldinger.einkaufsliste.Exceptions;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
public class BadRequestException extends RuntimeException {
|
||||
public BadRequestException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package de.timaldinger.einkaufsliste.Exceptions;
|
||||
|
||||
public record ErrorResponse(int status, String msg, String path) {
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package de.timaldinger.einkaufsliste.Exceptions;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.support.DefaultMessageSourceResolvable;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.HttpStatusCode;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.MethodArgumentNotValidException;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
import org.springframework.web.context.request.ServletWebRequest;
|
||||
import org.springframework.web.context.request.WebRequest;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestControllerAdvice
|
||||
public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
|
||||
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);
|
||||
|
||||
@ExceptionHandler(BadRequestException.class)
|
||||
public ResponseEntity<ErrorResponse> handleBadRequest(BadRequestException e, HttpServletRequest req) {
|
||||
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
|
||||
.body(new ErrorResponse(400, e.getMessage(), req.getRequestURI()));
|
||||
}
|
||||
@ExceptionHandler(ResourceNotFoundException.class)
|
||||
public ResponseEntity<ErrorResponse> handleResourceNotFound(ResourceNotFoundException e, HttpServletRequest req) {
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND)
|
||||
.body(new ErrorResponse(404, e.getMessage(), req.getRequestURI()));
|
||||
}
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
public ResponseEntity<ErrorResponse> handleAll(Exception e, HttpServletRequest req){
|
||||
log.error("{}",req.getRequestURI(), e);
|
||||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new ErrorResponse(500,"Internal error", req.getRequestURI()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nullable ResponseEntity<Object> handleExceptionInternal(Exception ex, @Nullable Object body, HttpHeaders headers, HttpStatusCode statusCode, WebRequest request) {
|
||||
var error = new ErrorResponse(statusCode.value(), ex.getMessage(),((ServletWebRequest) request).getRequest().getRequestURI());
|
||||
return new ResponseEntity<>(error,headers,statusCode);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected @Nullable ResponseEntity<Object> handleMethodArgumentNotValid(MethodArgumentNotValidException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) {
|
||||
String msg = ex.getBindingResult().getFieldErrors().stream()
|
||||
.map(DefaultMessageSourceResolvable::getDefaultMessage)
|
||||
.collect(Collectors.joining(", "));
|
||||
var error = new ErrorResponse(status.value(), msg ,((ServletWebRequest) request).getRequest().getRequestURI());
|
||||
return new ResponseEntity<>(error,headers,status);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package de.timaldinger.einkaufsliste.Exceptions;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
@ResponseStatus(HttpStatus.NOT_FOUND)
|
||||
public class ResourceNotFoundException extends RuntimeException {
|
||||
public ResourceNotFoundException(String resource, Object value){ super("Resource " + resource + ":"+value.toString()+" not found");}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package de.timaldinger.einkaufsliste.Mapper;
|
||||
|
||||
import de.timaldinger.einkaufsliste.Dto.Get.ShoppingCategoryGetDTO;
|
||||
import de.timaldinger.einkaufsliste.Models.ShoppingCategory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class ShoppingCategoryMapper {
|
||||
|
||||
@Autowired
|
||||
ShoppingItemMapper shoppingItemMapper;
|
||||
|
||||
public ShoppingCategoryGetDTO toGetDTO(ShoppingCategory category){
|
||||
return new ShoppingCategoryGetDTO(
|
||||
category.getCategoryName(),
|
||||
shoppingItemMapper.toGetDTOs(category.getItemsInCategory()),
|
||||
category.getId()
|
||||
);
|
||||
}
|
||||
|
||||
public List<ShoppingCategoryGetDTO> toGetDTOs(List<ShoppingCategory> categories){
|
||||
return categories.stream().map(this::toGetDTO).toList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package de.timaldinger.einkaufsliste.Mapper;
|
||||
|
||||
import de.timaldinger.einkaufsliste.Dto.Get.ShoppingItemGetDTO;
|
||||
import de.timaldinger.einkaufsliste.Models.ShoppingItem;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class ShoppingItemMapper {
|
||||
public ShoppingItemGetDTO toGetDTO(ShoppingItem item){
|
||||
return new ShoppingItemGetDTO(
|
||||
item.isDone(),
|
||||
item.getItemName(),
|
||||
item.getItemAmount(),
|
||||
item.getId(),
|
||||
item.getCategory() != null ? item.getCategory().getId() : null,
|
||||
item.getList().getId()
|
||||
);
|
||||
}
|
||||
|
||||
public List<ShoppingItemGetDTO> toGetDTOs(List<ShoppingItem> items){
|
||||
return items.stream().map(this::toGetDTO).toList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package de.timaldinger.einkaufsliste.Mapper;
|
||||
|
||||
import de.timaldinger.einkaufsliste.Dto.Get.ShoppingListsGetDTO;
|
||||
import de.timaldinger.einkaufsliste.Models.ShoppingList;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class ShoppingListMapper {
|
||||
|
||||
public List<ShoppingListsGetDTO> toListsGetDTOs(List<ShoppingList> list){
|
||||
return list.stream().map(this::toListsGetDTO).toList();
|
||||
}
|
||||
|
||||
public ShoppingListsGetDTO toListsGetDTO(ShoppingList list){
|
||||
return new ShoppingListsGetDTO(
|
||||
list.getListName(),
|
||||
list.getId()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package de.timaldinger.einkaufsliste.Models;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ShoppingCategory extends ShoppingElement{
|
||||
|
||||
private String categoryName;
|
||||
@OneToMany(mappedBy = "category") //eine Liste hat mehrere Kategorien, diese sind mappedBy category (Feld in ShoppingItem) damit keine extra Tabelle erzeugt wird
|
||||
private List<ShoppingItem> itemsInCategory;
|
||||
@ManyToOne //mehrere Kategorien (Many) gehören (to) einer Liste an (one)
|
||||
@JoinColumn(name="list_id", nullable = false)
|
||||
private ShoppingList list;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package de.timaldinger.einkaufsliste.Models;
|
||||
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.GenerationType;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.MappedSuperclass;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@MappedSuperclass
|
||||
public abstract class ShoppingElement{
|
||||
@Id @GeneratedValue(strategy = GenerationType.UUID)
|
||||
private UUID id;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package de.timaldinger.einkaufsliste.Models;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.*;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@ToString
|
||||
public class ShoppingItem extends ShoppingElement {
|
||||
|
||||
private String itemName;
|
||||
private String itemAmount;
|
||||
private boolean isDone;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "category_id", nullable = true)
|
||||
private ShoppingCategory category;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "list_id", nullable = false)
|
||||
private ShoppingList list;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package de.timaldinger.einkaufsliste.Models;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.sql.Date;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ShoppingList extends ShoppingElement {
|
||||
private String listName;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package de.timaldinger.einkaufsliste.Repository;
|
||||
|
||||
import de.timaldinger.einkaufsliste.Models.ShoppingList;
|
||||
import de.timaldinger.einkaufsliste.Models.ShoppingCategory;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface ShoppingCategoryRepository extends JpaRepository<ShoppingCategory, UUID>{
|
||||
List<ShoppingCategory> findByList(ShoppingList list);
|
||||
List<ShoppingCategory> findByList_Id(UUID listID);
|
||||
@Modifying
|
||||
@Query("DELETE FROM ShoppingCategory c WHERE c.list.id = :listID")
|
||||
void deleteByListId(@Param("listID") UUID listID);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package de.timaldinger.einkaufsliste.Repository;
|
||||
|
||||
import de.timaldinger.einkaufsliste.Models.ShoppingItem;
|
||||
import de.timaldinger.einkaufsliste.Models.ShoppingList;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface ShoppingItemRepository extends JpaRepository<ShoppingItem, UUID> {
|
||||
|
||||
List<ShoppingItem> findByList_IdAndCategoryIsNull(UUID list);
|
||||
List<ShoppingItem> findAllByCategory_Id(UUID categoryID);
|
||||
List<ShoppingItem> findByList_IdAndIsDoneIsTrue(UUID listID);
|
||||
@Modifying
|
||||
@Query("DELETE FROM ShoppingItem i WHERE i.list.id = :listID")
|
||||
void deleteByListId(@Param("listID") UUID listID);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package de.timaldinger.einkaufsliste.Repository;
|
||||
|
||||
import de.timaldinger.einkaufsliste.Models.ShoppingList;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public interface ShoppingListRepository extends JpaRepository<ShoppingList, UUID>{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package de.timaldinger.einkaufsliste.Service;
|
||||
|
||||
import de.timaldinger.einkaufsliste.Dto.Get.ShoppingCategoryGetDTO;
|
||||
import de.timaldinger.einkaufsliste.Dto.Patch.ShoppingCategoryPatchDTO;
|
||||
import de.timaldinger.einkaufsliste.Dto.Post.ShoppingCategoryPostDTO;
|
||||
import de.timaldinger.einkaufsliste.Dto.Post.Response.ShoppingCategoryPostResponseDTO;
|
||||
import de.timaldinger.einkaufsliste.Exceptions.BadRequestException;
|
||||
import de.timaldinger.einkaufsliste.Exceptions.ResourceNotFoundException;
|
||||
import de.timaldinger.einkaufsliste.Mapper.ShoppingCategoryMapper;
|
||||
import de.timaldinger.einkaufsliste.Models.ShoppingCategory;
|
||||
import de.timaldinger.einkaufsliste.Models.ShoppingItem;
|
||||
import de.timaldinger.einkaufsliste.Models.ShoppingList;
|
||||
import de.timaldinger.einkaufsliste.Repository.ShoppingCategoryRepository;
|
||||
import de.timaldinger.einkaufsliste.Repository.ShoppingItemRepository;
|
||||
import de.timaldinger.einkaufsliste.Repository.ShoppingListRepository;
|
||||
import jakarta.transaction.Transactional;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Service
|
||||
public class ShoppingCategoryService {
|
||||
|
||||
@Autowired
|
||||
private ShoppingCategoryMapper shoppingCategoryMapper;
|
||||
@Autowired
|
||||
private ShoppingCategoryRepository shoppingCategoryRepository;
|
||||
@Autowired
|
||||
private ShoppingListRepository shoppingListRepository;
|
||||
@Autowired
|
||||
private ShoppingItemRepository shoppingItemRepository;
|
||||
|
||||
public ShoppingCategoryGetDTO getCategory(UUID categoryID){
|
||||
ShoppingCategory category = shoppingCategoryRepository.findById(categoryID).orElseThrow(() -> new ResourceNotFoundException("categoryID", categoryID));
|
||||
return shoppingCategoryMapper.toGetDTO(category);
|
||||
}
|
||||
|
||||
public ShoppingCategoryPostResponseDTO addCategory(ShoppingCategoryPostDTO newCategory){
|
||||
ShoppingList list = shoppingListRepository.findById(newCategory.listID()).orElseThrow(() -> new ResourceNotFoundException("listID", newCategory.listID()));
|
||||
|
||||
ShoppingCategory category = new ShoppingCategory(newCategory.categoryName(), List.of(), list);
|
||||
shoppingCategoryRepository.save(category);
|
||||
|
||||
return new ShoppingCategoryPostResponseDTO(category.getCategoryName(), category.getId());
|
||||
}
|
||||
|
||||
public void editCategory(UUID categoryID, ShoppingCategoryPatchDTO toChange){
|
||||
ShoppingCategory category = shoppingCategoryRepository.findById(categoryID).orElseThrow(() -> new ResourceNotFoundException("categoryID", categoryID));
|
||||
|
||||
if(toChange.categoryName() != null) category.setCategoryName(toChange.categoryName());
|
||||
|
||||
shoppingCategoryRepository.save(category);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void deleteCategory(UUID categoryID, Boolean deleteAllItems){
|
||||
if(deleteAllItems == null){
|
||||
throw new BadRequestException("Missing required parameter deleteAllItems (can be either true or false)");
|
||||
}
|
||||
|
||||
shoppingCategoryRepository.findById(categoryID).orElseThrow(() -> new ResourceNotFoundException("categoryID", categoryID));
|
||||
|
||||
List<ShoppingItem> itemList = shoppingItemRepository.findAllByCategory_Id(categoryID);
|
||||
if(deleteAllItems){
|
||||
itemList.forEach((item) -> shoppingItemRepository.deleteById(item.getId()));
|
||||
}else{
|
||||
itemList.forEach((item) -> item.setCategory(null));
|
||||
shoppingItemRepository.saveAll(itemList);
|
||||
}
|
||||
|
||||
shoppingCategoryRepository.deleteById(categoryID);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package de.timaldinger.einkaufsliste.Service;
|
||||
|
||||
import de.timaldinger.einkaufsliste.Dto.Get.ShoppingItemGetDTO;
|
||||
import de.timaldinger.einkaufsliste.Dto.Patch.ShoppingItemPatchDTO;
|
||||
import de.timaldinger.einkaufsliste.Dto.Post.ShoppingItemPostDTO;
|
||||
import de.timaldinger.einkaufsliste.Dto.Post.Response.ShoppingItemPostResponseDTO;
|
||||
import de.timaldinger.einkaufsliste.Exceptions.BadRequestException;
|
||||
import de.timaldinger.einkaufsliste.Exceptions.ResourceNotFoundException;
|
||||
import de.timaldinger.einkaufsliste.Mapper.ShoppingItemMapper;
|
||||
import de.timaldinger.einkaufsliste.Models.ShoppingCategory;
|
||||
import de.timaldinger.einkaufsliste.Models.ShoppingItem;
|
||||
import de.timaldinger.einkaufsliste.Models.ShoppingList;
|
||||
import de.timaldinger.einkaufsliste.Repository.ShoppingCategoryRepository;
|
||||
import de.timaldinger.einkaufsliste.Repository.ShoppingItemRepository;
|
||||
import de.timaldinger.einkaufsliste.Repository.ShoppingListRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Service
|
||||
public class ShoppingItemService {
|
||||
|
||||
@Autowired
|
||||
private ShoppingItemMapper shoppingItemMapper;
|
||||
@Autowired
|
||||
private ShoppingItemRepository shoppingItemRepository;
|
||||
@Autowired
|
||||
private ShoppingCategoryRepository shoppingCategoryRepository;
|
||||
@Autowired
|
||||
private ShoppingListRepository shoppingListRepository;
|
||||
|
||||
public ShoppingItemGetDTO getItem(UUID itemID){
|
||||
ShoppingItem item = shoppingItemRepository.findById(itemID).orElseThrow(() -> new ResourceNotFoundException("itemID", itemID));
|
||||
return shoppingItemMapper.toGetDTO(item);
|
||||
}
|
||||
|
||||
public ShoppingItemPostResponseDTO addItem(ShoppingItemPostDTO newItem){
|
||||
ShoppingCategory category = null;
|
||||
if(newItem.categoryID() != null){
|
||||
category = shoppingCategoryRepository.findById(newItem.categoryID()).orElseThrow(() -> new ResourceNotFoundException("categoryID", newItem.categoryID()));
|
||||
}
|
||||
ShoppingList list = shoppingListRepository.findById(newItem.listID()).orElseThrow(() -> new ResourceNotFoundException("listID", newItem.listID()));
|
||||
|
||||
ShoppingItem item = new ShoppingItem(newItem.itemName(), newItem.itemAmount(), false, category, list);
|
||||
shoppingItemRepository.save(item);
|
||||
|
||||
return new ShoppingItemPostResponseDTO(item.getItemName(), item.getItemAmount(), item.getId(), category != null ? category.getId() : null);
|
||||
}
|
||||
|
||||
public void editItem(UUID itemID, ShoppingItemPatchDTO toChange){
|
||||
ShoppingItem item = shoppingItemRepository.findById(itemID).orElseThrow(() -> new ResourceNotFoundException("itemID", itemID));
|
||||
|
||||
if(toChange.itemName() != null) item.setItemName(toChange.itemName());
|
||||
if(toChange.itemAmount() != null) item.setItemAmount(toChange.itemAmount());
|
||||
if(toChange.isDone() != null) item.setDone(toChange.isDone());
|
||||
if(toChange.categoryID() != null) item.setCategory(shoppingCategoryRepository.findById(toChange.categoryID()).orElseThrow(() -> new ResourceNotFoundException("categoryID", toChange.categoryID())));
|
||||
|
||||
shoppingItemRepository.save(item);
|
||||
}
|
||||
|
||||
public void deleteItem(UUID itemID){
|
||||
shoppingItemRepository.findById(itemID).orElseThrow(() -> new ResourceNotFoundException("itemID", itemID));
|
||||
shoppingItemRepository.deleteById(itemID);
|
||||
}
|
||||
|
||||
public void deleteAllDoneItems(UUID listID, boolean done){
|
||||
if(!done) throw new BadRequestException("Parameter \"done\" must be true!");
|
||||
shoppingListRepository.findById(listID).orElseThrow(() -> new ResourceNotFoundException("listID", listID));
|
||||
|
||||
List<ShoppingItem> items = shoppingItemRepository.findByList_IdAndIsDoneIsTrue(listID);
|
||||
shoppingItemRepository.deleteAll(items);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package de.timaldinger.einkaufsliste.Service;
|
||||
|
||||
import de.timaldinger.einkaufsliste.Dto.Get.*;
|
||||
import de.timaldinger.einkaufsliste.Dto.Patch.ShoppingListPatchDTO;
|
||||
import de.timaldinger.einkaufsliste.Dto.Post.ShoppingListPostDTO;
|
||||
import de.timaldinger.einkaufsliste.Dto.Post.Response.ShoppingListPostResponseDTO;
|
||||
import de.timaldinger.einkaufsliste.Exceptions.ResourceNotFoundException;
|
||||
import de.timaldinger.einkaufsliste.Mapper.ShoppingCategoryMapper;
|
||||
import de.timaldinger.einkaufsliste.Mapper.ShoppingItemMapper;
|
||||
import de.timaldinger.einkaufsliste.Mapper.ShoppingListMapper;
|
||||
import de.timaldinger.einkaufsliste.Models.ShoppingList;
|
||||
import de.timaldinger.einkaufsliste.Repository.ShoppingCategoryRepository;
|
||||
import de.timaldinger.einkaufsliste.Repository.ShoppingItemRepository;
|
||||
import de.timaldinger.einkaufsliste.Repository.ShoppingListRepository;
|
||||
import jakarta.transaction.Transactional;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Service
|
||||
public class ShoppingListService {
|
||||
@Autowired
|
||||
private ShoppingItemRepository shoppingItemRepository;
|
||||
@Autowired
|
||||
private ShoppingListRepository shoppingListRepository;
|
||||
@Autowired
|
||||
private ShoppingCategoryRepository shoppingCategoryRepository;
|
||||
@Autowired
|
||||
private ShoppingCategoryMapper shoppingCategoryMapper;
|
||||
@Autowired
|
||||
private ShoppingItemMapper shoppingItemMapper;
|
||||
@Autowired
|
||||
private ShoppingListMapper shoppingListMapper;
|
||||
|
||||
public List<ShoppingListsGetDTO> getLists(){
|
||||
return shoppingListMapper.toListsGetDTOs(shoppingListRepository.findAll());
|
||||
}
|
||||
|
||||
public ShoppingListGetDTO getList(UUID listID){
|
||||
ShoppingList l = shoppingListRepository.findById(listID).orElseThrow(() -> new ResourceNotFoundException("listID", listID));
|
||||
|
||||
List<ShoppingCategoryGetDTO> categories = shoppingCategoryMapper.toGetDTOs(shoppingCategoryRepository.findByList(l));
|
||||
List<ShoppingItemGetDTO> items = shoppingItemMapper.toGetDTOs(shoppingItemRepository.findByList_IdAndCategoryIsNull(listID));
|
||||
|
||||
return new ShoppingListGetDTO(categories, items);
|
||||
}
|
||||
|
||||
public ShoppingListPostResponseDTO addList(ShoppingListPostDTO newList){
|
||||
ShoppingList list = new ShoppingList(newList.listName());
|
||||
shoppingListRepository.save(list);
|
||||
return new ShoppingListPostResponseDTO(list.getListName(), list.getId());
|
||||
}
|
||||
|
||||
public void editList(UUID listID, ShoppingListPatchDTO toChange){
|
||||
ShoppingList list = shoppingListRepository.findById(listID).orElseThrow(() -> new ResourceNotFoundException("listID", listID));
|
||||
|
||||
if(toChange.listName() != null) list.setListName(toChange.listName());
|
||||
|
||||
shoppingListRepository.save(list);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void deleteList(UUID listID){
|
||||
shoppingListRepository.findById(listID).orElseThrow(() -> new ResourceNotFoundException("listID", listID));
|
||||
|
||||
shoppingItemRepository.deleteByListId(listID);
|
||||
shoppingCategoryRepository.deleteByListId(listID);
|
||||
shoppingListRepository.deleteById(listID);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
spring.application.name=einkaufsliste
|
||||
|
||||
spring.datasource.url=jdbc:h2:file:./data/einkaufsliste
|
||||
spring.jpa.hibernate.ddl-auto=update
|
||||
spring.h2.console.enabled=true
|
||||
|
||||
server.error.include-stacktrace=never
|
||||
@@ -0,0 +1,144 @@
|
||||
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
|
||||
:root {
|
||||
/* Akzent (teal) */
|
||||
--c-accent: #0f766e;
|
||||
--c-accent-hover: #134e4a;
|
||||
--c-accent-soft: #f0fdfa;
|
||||
|
||||
/* Spacing-Skala */
|
||||
--space-1: .25rem; /* 4px */
|
||||
--space-2: .5rem; /* 8px */
|
||||
--space-3: 1rem; /* 16px */
|
||||
--space-4: 1.5rem; /* 24px */
|
||||
--space-5: 2rem; /* 32px */
|
||||
--space-6: 3rem; /* 48px */
|
||||
|
||||
/* Neutrale (zinc) */
|
||||
--c-bg: #ffffff;
|
||||
--c-surface: #fafafa;
|
||||
--c-border: #e4e4e7;
|
||||
--c-muted: #71717a;
|
||||
--c-text: #18181b;
|
||||
|
||||
--c-danger: #dc2626;
|
||||
|
||||
--radius: 6px;
|
||||
--maxw: 640px;
|
||||
--shadow: 0 4px 12px rgb(0 0 0 / .12);
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: system-ui, sans-serif;
|
||||
color: var(--c-text);
|
||||
background-color: var(--c-bg);
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
|
||||
.index, .title, .nav, body > .list {
|
||||
max-width: var(--maxw);
|
||||
margin-inline: auto;
|
||||
padding: var(--space-3);
|
||||
}
|
||||
|
||||
/* ---- Links ---- */
|
||||
a, a:link, a:visited { color: var(--c-text); }
|
||||
|
||||
/* ---- Formular-Elemente ---- */
|
||||
|
||||
input:not([type="checkbox"]):not([type="radio"]), select {
|
||||
font: inherit;
|
||||
padding: var(--space-2) var(--space-3);
|
||||
border: 1px solid var(--c-border);
|
||||
border-radius: var(--radius);
|
||||
background: var(--c-bg);
|
||||
color: var(--c-text);
|
||||
}
|
||||
input::placeholder { color: var(--c-muted); }
|
||||
|
||||
input.is-invalid:not([type="checkbox"]):not([type="radio"]),
|
||||
input:user-invalid:not([type="checkbox"]):not([type="radio"]),
|
||||
select.is-invalid {
|
||||
border-color: var(--c-danger);
|
||||
}
|
||||
|
||||
.is-invalid:focus-visible {
|
||||
outline-color: var(--c-danger);
|
||||
}
|
||||
|
||||
button {
|
||||
font: inherit;
|
||||
padding: var(--space-2) var(--space-3);
|
||||
border: 1px solid transparent;
|
||||
border-radius: var(--radius);
|
||||
background: var(--c-accent);
|
||||
color: #fff;
|
||||
cursor: pointer;
|
||||
}
|
||||
button:hover { background: var(--c-accent-hover); }
|
||||
|
||||
:focus-visible {
|
||||
outline: 2px solid var(--c-accent);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
|
||||
/* ---- Bearbeitung ---- */
|
||||
.error-message{
|
||||
flex-basis: 100%;
|
||||
font-size: .75rem;
|
||||
color: var(--c-danger);
|
||||
}
|
||||
|
||||
.editForm {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: var(--space-2);
|
||||
align-items: center;
|
||||
margin: var(--space-1);
|
||||
}
|
||||
|
||||
|
||||
/* ---- Navigation ---- */
|
||||
.nav { border-bottom: 1px solid var(--c-border); }
|
||||
.nav__links {
|
||||
list-style: none;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-4);
|
||||
}
|
||||
.nav a { text-decoration: none; }
|
||||
.nav a:hover { color: var(--c-accent); }
|
||||
|
||||
.nav__dropdown { position: relative; cursor: default; }
|
||||
|
||||
.nav__dropdownMenu {
|
||||
display: none;
|
||||
position: absolute;
|
||||
top: 100%;
|
||||
left: 0;
|
||||
min-width: 12rem;
|
||||
margin-top: 0;
|
||||
list-style: none;
|
||||
background: var(--c-bg);
|
||||
border: 1px solid var(--c-border);
|
||||
border-radius: var(--radius);
|
||||
box-shadow: var(--shadow);
|
||||
padding: var(--space-2);
|
||||
}
|
||||
.nav__dropdown:hover .nav__dropdownMenu,
|
||||
.nav__dropdown.is-open .nav__dropdownMenu { display: block; }
|
||||
|
||||
.nav__list a { display: block; padding: var(--space-1) var(--space-2); }
|
||||
.nav__list a:hover { background: var(--c-surface); border-radius: var(--radius); }
|
||||
|
||||
|
||||
|
||||
@media (max-width: 640px) {
|
||||
button {
|
||||
padding: var(--space-1) var(--space-2);
|
||||
font-size: .875rem;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
.addListForm {
|
||||
display: flex;
|
||||
gap: var(--space-2);
|
||||
margin-bottom: var(--space-4);
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.addListForm input { flex: 1; }
|
||||
|
||||
.displayedList {
|
||||
list-style: none;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--space-2);
|
||||
}
|
||||
|
||||
.index .list {
|
||||
padding: var(--space-2) var(--space-3);
|
||||
background: var(--c-surface);
|
||||
border: 1px solid var(--c-border);
|
||||
border-radius: var(--radius);
|
||||
}
|
||||
|
||||
shopping-list {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-2);
|
||||
width: 100%;
|
||||
}
|
||||
.list__name {
|
||||
flex: 1;
|
||||
text-decoration: none;
|
||||
font-weight: 500;
|
||||
}
|
||||
.list__name:hover { color: var(--c-accent); }
|
||||
|
||||
.list__editButton,
|
||||
.list__deleteButton {
|
||||
background: var(--c-bg);
|
||||
color: var(--c-text);
|
||||
border: 1px solid var(--c-border);
|
||||
}
|
||||
.list__editButton:hover,
|
||||
.list__deleteButton:hover { background: var(--c-surface); }
|
||||
.list__deleteButton { color: var(--c-danger); }
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
.title h1 { font-size: 2rem; }
|
||||
|
||||
.addCategoryForm,
|
||||
.addItemForm {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: var(--space-2);
|
||||
margin-bottom: var(--space-3);
|
||||
}
|
||||
.addItemForm__nameInput,
|
||||
.addItemForm__amountInput { flex: 1; min-width: 8rem; }
|
||||
|
||||
.deleteAllDoneItemsButton {
|
||||
margin-bottom: var(--space-4);
|
||||
background: var(--c-bg);
|
||||
color: var(--c-danger);
|
||||
border: 1px solid var(--c-border);
|
||||
}
|
||||
.deleteAllDoneItemsButton:hover { background: var(--c-surface); }
|
||||
|
||||
.displayedList {
|
||||
list-style: none;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--space-2);
|
||||
}
|
||||
|
||||
shopping-category {
|
||||
display: block;
|
||||
border-left: 3px solid var(--c-border);
|
||||
border-radius: var(--radius)
|
||||
}
|
||||
|
||||
.category__header{
|
||||
display: flex;
|
||||
}
|
||||
.category__innerHeader {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-2);
|
||||
padding: var(--space-2);
|
||||
}
|
||||
.category__name{
|
||||
font-size: 1.5rem;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.category__deleteButton {
|
||||
background: var(--c-bg);
|
||||
color: var(--c-danger);
|
||||
border: 1px solid var(--c-border);
|
||||
}
|
||||
.category__deleteButton:hover { background: var(--c-surface); }
|
||||
|
||||
.category__deleteAllLabel {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-1);
|
||||
font-size: .875rem;
|
||||
color: var(--c-muted);
|
||||
margin-left: auto;
|
||||
}
|
||||
shopping-category > ul {
|
||||
list-style: none;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--space-1);
|
||||
padding-left: var(--space-3);
|
||||
margin-top: var(--space-2);
|
||||
}
|
||||
|
||||
.item { padding: var(--space-1) 0; }
|
||||
|
||||
shopping-item:hover , shopping-category:hover {
|
||||
background-color: var(--c-surface);
|
||||
}
|
||||
|
||||
.category__name:hover, .item__name:hover, .item__amount:hover {
|
||||
text-decoration: underline ;
|
||||
}
|
||||
|
||||
shopping-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--space-4);
|
||||
padding: var(--space-1);
|
||||
width: 100%;
|
||||
}
|
||||
.item__text {
|
||||
display: inline-flex;
|
||||
gap: var(--space-1);
|
||||
flex: 1;
|
||||
}
|
||||
.item__amount { color: var(--c-muted); }
|
||||
|
||||
shopping-item:has(.item__doneCheckbox:checked) .item__text {
|
||||
text-decoration: line-through;
|
||||
color: var(--c-muted);
|
||||
}
|
||||
|
||||
.item__deleteButton {
|
||||
padding: var(--space-1) var(--space-2);
|
||||
font-size: .875rem;
|
||||
background: var(--c-bg);
|
||||
color: var(--c-danger);
|
||||
border: 1px solid var(--c-border);
|
||||
}
|
||||
.item__deleteButton:hover { background: var(--c-surface); }
|
||||
@@ -0,0 +1,63 @@
|
||||
export class ShoppingCategory extends HTMLElement {
|
||||
|
||||
static get observedAttributes() { return ["category-name"] }
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this._rendered = false;
|
||||
}
|
||||
|
||||
connectedCallback() {
|
||||
if (this._rendered) return;
|
||||
|
||||
const categoryHeaderDiv = document.createElement("div");
|
||||
const categoryHeaderInnerDiv = document.createElement("div");
|
||||
const span = document.createElement("span");
|
||||
const deleteCategoryButton = document.createElement("button");
|
||||
const deleteAllItemsLabel = document.createElement("label");
|
||||
const deleteAllItemsCheckbox = document.createElement("input");
|
||||
const ul = document.createElement("ul");
|
||||
|
||||
|
||||
|
||||
categoryHeaderDiv.classList.add("category__header");
|
||||
categoryHeaderInnerDiv.classList.add("category__innerHeader");
|
||||
|
||||
span.textContent = this.getAttribute("category-name");
|
||||
span.classList.add("category__name");
|
||||
|
||||
deleteAllItemsLabel.classList.add("category__deleteAllLabel");
|
||||
deleteAllItemsLabel.textContent = "Gegenstände mit Kategorie löschen?";
|
||||
|
||||
deleteCategoryButton.classList.add("category__deleteButton");
|
||||
deleteCategoryButton.textContent = "Kategorie löschen";
|
||||
|
||||
deleteAllItemsCheckbox.setAttribute("type", "checkbox");
|
||||
|
||||
deleteAllItemsLabel.append(deleteAllItemsCheckbox);
|
||||
|
||||
categoryHeaderInnerDiv.append(span, deleteCategoryButton, deleteAllItemsLabel);
|
||||
|
||||
categoryHeaderDiv.append(categoryHeaderInnerDiv);
|
||||
|
||||
this.prepend(categoryHeaderDiv);
|
||||
|
||||
if (!this.querySelector("ul")) this.append(ul);
|
||||
|
||||
this._rendered = true;
|
||||
|
||||
}
|
||||
|
||||
attributeChangedCallback(name, oldVal, newVal) {
|
||||
if (!this._rendered) return;
|
||||
if (newVal == oldVal) return;
|
||||
switch (name) {
|
||||
case "category-name":
|
||||
this.querySelector(".category__name").textContent = newVal;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
export class ShoppingItem extends HTMLElement {
|
||||
|
||||
static get observedAttributes() { return ["item-name", "item-amount"] }
|
||||
constructor() {
|
||||
super();
|
||||
this._rendered = false;
|
||||
}
|
||||
|
||||
connectedCallback() {
|
||||
if (this._rendered) return;
|
||||
|
||||
console.log(`rendering element shopping-item`);
|
||||
const doneCheckbox = document.createElement("input");
|
||||
const textSpan = document.createElement("span");
|
||||
const nameSpan = document.createElement("span");
|
||||
const amountSpan = document.createElement("span");
|
||||
const deleteButton = document.createElement("button");
|
||||
|
||||
|
||||
doneCheckbox.classList.add("item__doneCheckbox");
|
||||
doneCheckbox.setAttribute("type", "checkbox");
|
||||
doneCheckbox.setAttribute("autocomplete", "off");
|
||||
doneCheckbox.checked = this.getAttribute("is-checked") === "true";
|
||||
|
||||
textSpan.classList.add("item__text");
|
||||
|
||||
nameSpan.classList.add("item__name");
|
||||
amountSpan.classList.add("item__amount");
|
||||
|
||||
nameSpan.textContent = this.getAttribute("item-name");
|
||||
amountSpan.textContent = this.getAttribute("item-amount");
|
||||
|
||||
deleteButton.classList.add("item__deleteButton");
|
||||
deleteButton.setAttribute("type", "button ");
|
||||
deleteButton.textContent = "Löschen";
|
||||
|
||||
textSpan.append(nameSpan, amountSpan);
|
||||
|
||||
this.append(doneCheckbox, textSpan, deleteButton);
|
||||
this._rendered = true;
|
||||
|
||||
}
|
||||
|
||||
attributeChangedCallback(name, oldVal, newVal) {
|
||||
if (!this._rendered) return;
|
||||
if (newVal == oldVal) return;
|
||||
switch (name) {
|
||||
case "item-name":
|
||||
this.querySelector(".item__name").textContent = newVal;
|
||||
break;
|
||||
case "item-amount":
|
||||
this.querySelector(".item__amount").textContent = newVal;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
export class ShoppingList extends HTMLElement {
|
||||
|
||||
static get observedAttributes() { return ["list-name"] }
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this._rendered = false
|
||||
}
|
||||
|
||||
connectedCallback() {
|
||||
if (this._rendered) return;
|
||||
|
||||
const a = document.createElement("a");
|
||||
const editButton = document.createElement("button");
|
||||
const deleteButton = document.createElement("button");
|
||||
|
||||
const listID = this.closest("li").dataset.id;
|
||||
|
||||
a.setAttribute("href", `/list/${listID}`);
|
||||
a.classList.add("list__name");
|
||||
a.textContent = this.getAttribute("list-name");
|
||||
|
||||
editButton.classList.add("list__editButton");
|
||||
editButton.textContent = "Liste bearbeiten";
|
||||
|
||||
deleteButton.classList.add("list__deleteButton");
|
||||
deleteButton.textContent = "Liste löschen";
|
||||
|
||||
this.append(a, editButton, deleteButton);
|
||||
this._rendered = true;
|
||||
}
|
||||
|
||||
attributeChangedCallback(name, oldVal, newVal) {
|
||||
if (!this._rendered) return;
|
||||
if (oldVal == newVal) return;
|
||||
|
||||
const listLi = this.closest("li");
|
||||
|
||||
switch (name) {
|
||||
case "list-name":
|
||||
this.querySelector(".list__name").textContent = newVal;
|
||||
document.querySelector(`.nav__list[data-id='${listLi.dataset.id}'] > a`).textContent = newVal;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
export function addList(listName) {
|
||||
return fetch(`/api/lists`,
|
||||
{
|
||||
method: "POST",
|
||||
body: JSON.stringify({ listName: listName }),
|
||||
headers: { "Content-Type": "application/json" }
|
||||
});
|
||||
}
|
||||
|
||||
export function deleteList(id) {
|
||||
return fetch(`/api/lists/${id}`, { method: "DELETE" });
|
||||
}
|
||||
|
||||
export function editList(listID, toChange) {
|
||||
return fetch(`/api/lists/${listID}`,
|
||||
{
|
||||
method: "PATCH",
|
||||
body: JSON.stringify(toChange),
|
||||
headers: { "Content-Type": "application/json" }
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
|
||||
|
||||
export function addList(listAsJSON) {
|
||||
const list = document.querySelector(".displayedList");
|
||||
const li = document.createElement("li");
|
||||
const navList = document.querySelector(".nav__dropdownMenu");
|
||||
const listElement = document.createElement("shopping-list");
|
||||
|
||||
const navLi = document.createElement("li");
|
||||
const a = document.createElement("a");
|
||||
|
||||
li.dataset.id = listAsJSON.listID;
|
||||
li.classList.add("list");
|
||||
listElement.setAttribute("list-name", listAsJSON.listName);
|
||||
|
||||
li.append(listElement);
|
||||
list.append(li);
|
||||
|
||||
|
||||
navLi.dataset.id = listAsJSON.listID;
|
||||
navLi.classList.add("nav__list")
|
||||
a.setAttribute("href", `/list/${listAsJSON.listID}`);
|
||||
a.textContent = listAsJSON.listName;
|
||||
navLi.append(a);
|
||||
navList.append(navLi);
|
||||
}
|
||||
|
||||
export function deleteList(listElement) {
|
||||
|
||||
document.querySelector(`li.nav__list[data-id='${listElement.dataset.id}']`).remove();
|
||||
listElement.remove();
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
import { ShoppingList } from "../../models/ShoppingList.js";
|
||||
import { editElement } from "../../shared/editing.js";
|
||||
import { showError } from "../../shared/error.js";
|
||||
import { handleResponse } from "../../shared/helper.js";
|
||||
import { setElementAttributes } from "../../shared/sharedUI.js";
|
||||
import * as api from "./api/indexAPI.js";
|
||||
import * as ui from "./frontend/indexUI.js"
|
||||
|
||||
const addListForm = document.querySelector(".addListForm");
|
||||
|
||||
async function addList(listName) {
|
||||
const response = await handleResponse(api.addList(listName), `error creating list`);
|
||||
if (response.ok) {
|
||||
ui.addList(response.json);
|
||||
} else {
|
||||
const name = document.querySelector(".addListForm__inputName");
|
||||
showError({ highlightFields: [name], elementForMessage: addListForm, message: response.json.msg });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async function deleteList(listElement) {
|
||||
const response = await handleResponse(api.deleteList(listElement.dataset.id), `error deleting list`);
|
||||
if (response.ok) ui.deleteList(listElement);
|
||||
}
|
||||
|
||||
function init() {
|
||||
|
||||
customElements.define("shopping-list", ShoppingList);
|
||||
|
||||
addListForm.addEventListener("submit", (e) => {
|
||||
e.preventDefault();
|
||||
const formData = Object.fromEntries(new FormData(addListForm));
|
||||
addList(formData.listName?.trim());
|
||||
});
|
||||
|
||||
document.querySelector(".index").addEventListener("click", (event) => {
|
||||
if (event.target.matches(".list__editButton")) {
|
||||
const id = event.target.closest("li").dataset.id;
|
||||
const shoppingListElement = event.target.closest("shopping-list");
|
||||
const listName = shoppingListElement.querySelector(".list__name").textContent;
|
||||
|
||||
editElement({
|
||||
element: shoppingListElement, apiCall: api.editList, id: id,
|
||||
fields: [
|
||||
{ name: "listName", value: listName, class: "editForm__name", attr: "list-name" }
|
||||
]
|
||||
, onSuccess: (f) => {
|
||||
setElementAttributes(shoppingListElement, { "list-name": f.listName });
|
||||
//nav wird hier ^ aktualisiert
|
||||
}
|
||||
, onFailure: (response) => {
|
||||
|
||||
const editForm = document.querySelector(".editForm");
|
||||
const name = document.querySelector("input.editForm__name");
|
||||
|
||||
showError({ highlightFields: [name], elementForMessage: editForm, message: response.json.msg });
|
||||
}
|
||||
|
||||
, errmsg: `liste konnte nicht aktualsiiert werden`
|
||||
|
||||
})
|
||||
} else if (event.target.matches(".list__deleteButton")) {
|
||||
deleteList(event.target.closest("li"));
|
||||
}
|
||||
});
|
||||
|
||||
document.querySelector(".nav").addEventListener("click", (event) => {
|
||||
|
||||
if (event.target.matches(".nav__dropdown")) {
|
||||
event.target.closest("li").classList.add("is-open");
|
||||
event.stopPropagation();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
document.querySelector("body").addEventListener("click", (event) => {
|
||||
if (!event.target.matches(".nav__dropdown")) {
|
||||
document.querySelector(".is-open")?.classList.remove("is-open");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', init);
|
||||
@@ -0,0 +1,21 @@
|
||||
export function addCategory(listID, categoryName) {
|
||||
return fetch(`/api/categories`,
|
||||
{
|
||||
method: "POST"
|
||||
, body: JSON.stringify({ "categoryName": categoryName, "listID": listID })
|
||||
, headers: { "Content-Type": "application/json" }
|
||||
});
|
||||
}
|
||||
|
||||
export function editCategory(categoryID, toChange) {
|
||||
return fetch(`/api/categories/${categoryID}`,
|
||||
{
|
||||
method: "PATCH",
|
||||
body: JSON.stringify(toChange),
|
||||
headers: { "Content-Type": "application/json" }
|
||||
});
|
||||
}
|
||||
|
||||
export function deleteCategory(deleteAllItems, categoryID) {
|
||||
return fetch(`/api/categories/${categoryID}?deleteAllItems=${deleteAllItems}`, { method: "DELETE" });
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
export function addItem(listID, itemName, itemAmount, categoryID) {
|
||||
return fetch(`/api/items`,
|
||||
{
|
||||
method: "POST",
|
||||
body: JSON.stringify({
|
||||
"itemName": itemName,
|
||||
"itemAmount": itemAmount,
|
||||
"categoryID": categoryID,
|
||||
"listID": listID
|
||||
}),
|
||||
headers: { "Content-Type": "application/json" }
|
||||
});
|
||||
}
|
||||
|
||||
export function deleteItem(itemID) {
|
||||
|
||||
return fetch(`/api/items/${itemID}`, { method: "DELETE" });
|
||||
|
||||
}
|
||||
|
||||
export function editItem(itemID, toChange) {
|
||||
return fetch(`/api/items/${itemID}`,
|
||||
{
|
||||
method: "PATCH",
|
||||
body: JSON.stringify(toChange),
|
||||
headers: { "Content-Type": "application/json" }
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
export function deleteAllDoneItems(listID) {
|
||||
return fetch(`/api/lists/${listID}/items?done=true`, { method: "DELETE" });
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export * from "./itemAPI.js";
|
||||
export * from "./categoryAPI.js"
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
export function addCategory(categoryAsJSON) {
|
||||
const list = document.querySelector(".displayedList");
|
||||
const category = document.createElement("shopping-category");
|
||||
const li = document.createElement("li");
|
||||
|
||||
li.classList.add("category");
|
||||
li.dataset.id = categoryAsJSON.categoryID;
|
||||
category.setAttribute("category-name", categoryAsJSON.categoryName);
|
||||
|
||||
li.append(category); //fügt Kategorie der Liste hinzu
|
||||
|
||||
list.append(li);
|
||||
|
||||
const categorySelect = document.querySelector(".addItemForm__categorySelect");
|
||||
const newCategoryOption = document.createElement("option");
|
||||
newCategoryOption.setAttribute("value", categoryAsJSON.categoryID);
|
||||
newCategoryOption.textContent = categoryAsJSON.categoryName;
|
||||
|
||||
categorySelect.append(newCategoryOption);
|
||||
}
|
||||
|
||||
export function deleteCategory(deleteAllItems, categoryID) {
|
||||
const category = document.querySelector(`li[data-id='${categoryID}']`);
|
||||
if (!deleteAllItems) {
|
||||
const ul = category.querySelector("ul");
|
||||
if (ul) document.querySelector(".displayedList").append(...ul.children);
|
||||
}
|
||||
category.remove()
|
||||
document.querySelector(`option[value='${categoryID}']`).remove();
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
export function addItem(itemAsJSON) {
|
||||
let list;
|
||||
if (!itemAsJSON.categoryID) {
|
||||
list = document.querySelector(".displayedList");
|
||||
} else {
|
||||
list = document.querySelector(`li[data-id='${itemAsJSON.categoryID}']`).querySelector("ul");
|
||||
}
|
||||
const li = document.createElement("li");
|
||||
const item = document.createElement("shopping-item");
|
||||
|
||||
li.dataset.id = itemAsJSON.itemID;
|
||||
li.classList.add("item");
|
||||
|
||||
item.setAttribute("item-name", itemAsJSON.itemName);
|
||||
item.setAttribute("item-amount", itemAsJSON.itemAmount);
|
||||
|
||||
li.append(item);
|
||||
list.append(li);
|
||||
}
|
||||
|
||||
export function deleteItem(li) {
|
||||
li.remove();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
export * from "./itemUI.js";
|
||||
export * from "./categoryUI.js";
|
||||
|
||||
export function deleteAllDoneItems() {
|
||||
const doneItems = document.querySelectorAll("li.item:has(shopping-item[is-checked=true])");
|
||||
doneItems.forEach((li) => {
|
||||
li.remove();
|
||||
})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,187 @@
|
||||
import { ShoppingCategory } from "../../models/ShoppingCategory.js";
|
||||
import { ShoppingItem } from "../../models/ShoppingItem.js";
|
||||
import * as api from "./api/listAPI.js"
|
||||
import * as ui from "./frontend/listUI.js"
|
||||
import { handleResponse } from "../../shared/helper.js";
|
||||
import { editElement } from "../../shared/editing.js";
|
||||
import * as sharedUI from "../../shared/sharedUI.js";
|
||||
import { showError } from "../../shared/error.js";
|
||||
|
||||
const addCategoryForm = document.querySelector(".addCategoryForm");
|
||||
const addItemForm = document.querySelector(".addItemForm");
|
||||
const currentList = document.querySelector(".list");
|
||||
const deleteAllDoneItemsButton = document.querySelector(".deleteAllDoneItemsButton");
|
||||
|
||||
async function addItem(itemName, itemAmount, categoryID) {
|
||||
console.log(` adding item with id:${currentList.dataset.id}, name: ${itemName}, amount: ${itemAmount}, category: ${categoryID}`)
|
||||
|
||||
const response = await handleResponse(api.addItem(currentList.dataset.id, itemName, itemAmount, categoryID), `item couldnt be created!`);
|
||||
if (response.ok) {
|
||||
ui.addItem(response.json);
|
||||
} else {
|
||||
const form = document.querySelector(".addItemForm");
|
||||
const name = document.querySelector(".addItemForm__nameInput");
|
||||
const amount = document.querySelector(".addItemForm__amountInput");
|
||||
showError({ highlightFields: [name, amount], elementForMessage: form, message: response.json.msg });
|
||||
}
|
||||
}
|
||||
|
||||
async function addCategory(categoryName) {
|
||||
console.log(`adding category ${categoryName}`)
|
||||
|
||||
const response = await handleResponse(api.addCategory(currentList.dataset.id, categoryName), `category couldnt be added!`);
|
||||
if (response.ok) {
|
||||
ui.addCategory(response.json);
|
||||
} else {
|
||||
const form = document.querySelector(".addCategoryForm");
|
||||
const name = document.querySelector(".addCategoryForm__nameInput");
|
||||
showError({ highlightFields: [name], elementForMessage: form, message: response.json.msg });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async function deleteItem(li) {
|
||||
console.log(`deleting item ${li.dataset.id}`)
|
||||
|
||||
const response = await handleResponse(api.deleteItem(li.dataset.id), `error deleting item`);
|
||||
if (response.ok) ui.deleteItem(li);
|
||||
}
|
||||
|
||||
async function deleteCategory(deleteAllItems, categoryID) {
|
||||
console.log(`deleting category with allItems: ${deleteAllItems} id: ${categoryID}`);
|
||||
const response = await handleResponse(api.deleteCategory(deleteAllItems, categoryID), `error deleting category`);
|
||||
|
||||
if (response.ok) ui.deleteCategory(deleteAllItems, categoryID);
|
||||
}
|
||||
|
||||
async function deleteAllDoneItems() {
|
||||
console.log(`deleting all done items...`)
|
||||
const response = await handleResponse(api.deleteAllDoneItems(currentList.dataset.id), `error deleting all done items`);
|
||||
if (response.ok) ui.deleteAllDoneItems();
|
||||
}
|
||||
|
||||
function init() {
|
||||
|
||||
|
||||
customElements.define("shopping-item", ShoppingItem);
|
||||
customElements.define("shopping-category", ShoppingCategory);
|
||||
|
||||
addCategoryForm.addEventListener("submit", (event) => {
|
||||
event.preventDefault();
|
||||
let formData = Object.fromEntries(new FormData(addCategoryForm));
|
||||
addCategory(formData.categoryName?.trim());
|
||||
});
|
||||
|
||||
addItemForm.addEventListener("submit", event => {
|
||||
event.preventDefault();
|
||||
let formData = Object.fromEntries(new FormData(addItemForm));
|
||||
addItem(formData.itemName?.trim(), formData.itemAmount?.trim(), formData.itemCategoryID);
|
||||
});
|
||||
|
||||
deleteAllDoneItemsButton.addEventListener("click", event => {
|
||||
deleteAllDoneItems();
|
||||
});
|
||||
|
||||
//event delegation ist schon geil
|
||||
document.querySelector(".displayedList").addEventListener("click", (event) => {
|
||||
if (event.target.matches(".item__deleteButton")) {
|
||||
deleteItem(event.target.closest("li"));
|
||||
|
||||
} else if (event.target.matches(".category__deleteButton")) {
|
||||
|
||||
const li = event.target.closest("li");
|
||||
const checkbox = li.querySelector("input[type=checkbox]");
|
||||
deleteCategory(checkbox.checked, li.dataset.id);
|
||||
|
||||
} else if (event.target.closest(".item__text")) {
|
||||
|
||||
const shoppingItemElement = event.target.closest("shopping-item");
|
||||
const id = event.target.closest("li").dataset.id;
|
||||
|
||||
let itemName = shoppingItemElement.querySelector(".item__name").textContent;
|
||||
let itemAmount = shoppingItemElement.querySelector(".item__amount").textContent;
|
||||
/*
|
||||
* { name: "", value: "", class: "", attr: ""}
|
||||
*/
|
||||
|
||||
editElement({
|
||||
element: shoppingItemElement, apiCall: api.editItem, id: id,
|
||||
fields: [
|
||||
{ name: "itemName", value: itemName, class: "editForm__name", attr: "item-name" },
|
||||
{ name: "itemAmount", value: itemAmount, class: "editForm__amount", attr: "item-amount" }
|
||||
]
|
||||
, onSuccess: (f) => { sharedUI.setElementAttributes(shoppingItemElement, { "item-name": f.itemName, "item-amount": f.itemAmount }) }
|
||||
, onFailure: (response) => {
|
||||
|
||||
const editForm = document.querySelector(".editForm");
|
||||
const name = document.querySelector("input.editForm__name");
|
||||
const amount = document.querySelector("input.editForm__amount")
|
||||
|
||||
showError({ highlightFields: [name, amount], elementForMessage: editForm, message: response.json.msg });
|
||||
}
|
||||
, errmsg: `konnte Item nicht bearbeiten`
|
||||
});
|
||||
|
||||
} else if (event.target.closest(".category__name")) {
|
||||
|
||||
const categoryElement = event.target.closest("shopping-category");
|
||||
const categoryInnerHeader = event.target.closest(".category__innerHeader");
|
||||
const id = event.target.closest("li").dataset.id;
|
||||
|
||||
let categoryName = categoryElement.querySelector(".category__name").textContent;
|
||||
|
||||
editElement({
|
||||
element: categoryInnerHeader, apiCall: api.editCategory, id: id,
|
||||
fields: [
|
||||
{ name: "categoryName", value: categoryName, class: "editForm__name", attr: "category-name" },
|
||||
]
|
||||
, onSuccess: (f) => {
|
||||
sharedUI.setElementAttributes(categoryElement, { "category-name": f.categoryName })
|
||||
document.querySelector(`option[value='${id}']`).textContent = f.categoryName;
|
||||
}
|
||||
, onFailure: (response) => {
|
||||
|
||||
const editForm = document.querySelector(".editForm");
|
||||
const name = document.querySelector(".editForm__name");
|
||||
|
||||
showError({ highlightFields: [name], elementForMessage: editForm, message: response.json.msg });
|
||||
|
||||
}
|
||||
, errmsg: `konnte Kategorie nicht bearbeiten`
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
document.querySelector(".nav").addEventListener("click", (event) => {
|
||||
|
||||
if (event.target.matches(".nav__dropdown")) {
|
||||
event.target.closest("li").classList.add("is-open");
|
||||
event.stopPropagation();
|
||||
}
|
||||
});
|
||||
|
||||
document.querySelector(".displayedList").addEventListener("change", (e) => {
|
||||
if (e.target.matches(".item__doneCheckbox")) {
|
||||
const item = e.target.closest("li");
|
||||
e.target.closest("shopping-item").setAttribute("is-checked", e.target.checked);
|
||||
api.editItem(item.dataset.id, { isDone: e.target.checked });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
document.querySelector("body").addEventListener("click", (event) => {
|
||||
if (!event.target.matches(".nav__dropdown")) {
|
||||
document.querySelector(".is-open")?.classList.remove("is-open");
|
||||
}
|
||||
});
|
||||
|
||||
console.log("javascript initialized!");
|
||||
}
|
||||
|
||||
|
||||
|
||||
document.addEventListener('DOMContentLoaded', init);
|
||||
@@ -0,0 +1,39 @@
|
||||
import { abortEditing, createEditForm } from "./sharedUI.js";
|
||||
import { handleResponse } from "./helper.js";
|
||||
|
||||
export async function editElement({ element, fields, apiCall, id, onSuccess, onFailure, errmsg }) {
|
||||
const formElement = createEditForm(fields);
|
||||
|
||||
element.replaceWith(formElement);
|
||||
|
||||
formElement.querySelector("input").focus();
|
||||
|
||||
formElement.addEventListener("submit", async (event) => {
|
||||
event.preventDefault();
|
||||
|
||||
let formData = Object.fromEntries(new FormData(formElement));
|
||||
|
||||
for (const key in formData) {
|
||||
if (typeof formData[key] === "string") formData[key] = formData[key].trim();
|
||||
}
|
||||
|
||||
let result = await handleResponse(apiCall(id, formData), errmsg);
|
||||
|
||||
|
||||
if (result.ok) {
|
||||
abortEditing(formElement, element);
|
||||
onSuccess(formData);
|
||||
} else {
|
||||
onFailure(result);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
formElement.addEventListener("click", (e) => {
|
||||
if (e.target.matches(".editForm__abortButton")) abortEditing(formElement, element);
|
||||
})
|
||||
|
||||
formElement.addEventListener("keydown", (e) => {
|
||||
if (e.key == "Escape") abortEditing(formElement, element);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
export function createErrorSpan(msg) {
|
||||
const span = document.createElement("span");
|
||||
span.textContent = msg;
|
||||
span.classList.add("error-message");
|
||||
return span;
|
||||
}
|
||||
|
||||
|
||||
export function showError({ highlightFields, elementForMessage, message }) {
|
||||
|
||||
highlightFields.forEach(field => {
|
||||
field.classList.add("is-invalid");
|
||||
});
|
||||
|
||||
const errSpan = createErrorSpan(message);
|
||||
|
||||
elementForMessage.append(errSpan);
|
||||
|
||||
let errorTimer;
|
||||
clearTimeout(errorTimer);
|
||||
errorTimer = (setTimeout(() => {
|
||||
|
||||
highlightFields.forEach(field => {
|
||||
field.classList.remove("is-invalid");
|
||||
})
|
||||
|
||||
elementForMessage.removeChild(errSpan);
|
||||
}, 5000));
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
|
||||
export async function handleResponse(promise, errorMsg) {
|
||||
const response = await promise;
|
||||
|
||||
//weil 204 kein body ist un damit unparsbar, geben wir vorab true zurück
|
||||
if (response.status == 204) {
|
||||
return { ok: true, json: null };
|
||||
}
|
||||
|
||||
const json = await response.json();
|
||||
|
||||
if (!response.ok) {
|
||||
console.error(errorMsg);
|
||||
return { ok: false, json: json };
|
||||
}
|
||||
|
||||
return { ok: true, json: json };
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
export function abortEditing(formElement, old) {
|
||||
formElement.replaceWith(old);
|
||||
}
|
||||
|
||||
export function createEditForm(fields) {
|
||||
const editForm = document.createElement("form");
|
||||
const abortButton = document.createElement("button");
|
||||
const saveButton = document.createElement("button");
|
||||
|
||||
const inputs = fields.map(f => {
|
||||
const input = document.createElement("input");
|
||||
input.setAttribute("name", f.name);
|
||||
input.setAttribute("value", f.value);
|
||||
input.classList.add(f.class);
|
||||
return input;
|
||||
});
|
||||
|
||||
abortButton.setAttribute("type", "button");
|
||||
abortButton.classList.add("editForm__abortButton");
|
||||
abortButton.textContent = "Abbrechen";
|
||||
|
||||
saveButton.textContent = "Speichern";
|
||||
saveButton.classList.add("editForm__saveButton");
|
||||
saveButton.setAttribute("type", "submit");
|
||||
|
||||
|
||||
editForm.append(...inputs, saveButton, abortButton);
|
||||
editForm.classList.add("editForm");
|
||||
|
||||
return editForm;
|
||||
}
|
||||
|
||||
export function setElementAttributes(element, attributes) {
|
||||
|
||||
for (const [attr, val] of Object.entries(attributes)) element.setAttribute(attr, val);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<!DOCTYPE html>
|
||||
<html
|
||||
xmlns="http://www.w3.org/1999/xhtml"
|
||||
xmlns:th="http://www.thymeleaf.org">
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
|
||||
<meta name="description" content="" />
|
||||
<meta name="author" content="" />
|
||||
<link href="/css/base.css" rel="stylesheet">
|
||||
<link href="/css/index.css" rel="stylesheet" >
|
||||
<title>Einkaufsliste</title>
|
||||
<script src="/js/pages/index/index.js" type="module"></script>
|
||||
|
||||
<body>
|
||||
|
||||
<nav class="nav">
|
||||
<ul class="nav__links">
|
||||
<li class="nav__link"><a href="/">Alle Einkaufslisten</a></li>
|
||||
<li class="nav__dropdown">Listen
|
||||
<ul class="nav__dropdownMenu">
|
||||
<li th:each="list : ${lists}" th:data-id="${list.id}" class="nav__list">
|
||||
<a th:text="${list.listName}" th:href="@{/list/{id}(id=${list.id})}"></a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
<div class="index">
|
||||
<form class="addListForm">
|
||||
<input class="addListForm__inputName" type="text" name="listName"/>
|
||||
<button type="submit">Neue Liste erstellen</button>
|
||||
</form>
|
||||
|
||||
<ul class="displayedList">
|
||||
<li th:each="list : ${lists}" class="list" th:data-id="${list.id}">
|
||||
<shopping-list th:attr="list-name=${list.listName}"></shopping-list>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Einkaufsliste</title>
|
||||
<link href="/css/base.css" rel="stylesheet">
|
||||
<link href="/css/list.css" rel="stylesheet">
|
||||
<script src="/js/pages/list/list.js" type="module"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<nav class="nav">
|
||||
<ul class="nav__links">
|
||||
<li class="nav__link"><a href="/">Alle Einkaufslisten</a></li>
|
||||
<li class="nav__dropdown">Listen
|
||||
<ul class="nav__dropdownMenu">
|
||||
<li th:each="list : ${lists}" th:data-id="${list.id}" class="nav__list">
|
||||
<a th:text="${list.listName}" th:href="@{/list/{id}(id=${list.id})}"></a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
<div class="title">
|
||||
<h1 th:text="${list.listName}"></h1>
|
||||
</div>
|
||||
|
||||
<div class="list" th:data-id="${list.id}">
|
||||
<form class="addCategoryForm">
|
||||
<span>Neue Kategorie hinzufügen:</span>
|
||||
<input type="text" class="addCategoryForm__nameInput" name="categoryName" placeholder="Neue Kategorie hinzufügen...">
|
||||
<button class="addCategoryForm__submitButton" type="submit">Hinzufügen</button>
|
||||
</form>
|
||||
|
||||
<br>
|
||||
|
||||
<form class="addItemForm">
|
||||
<span>Neuen Gegenstand hinzufügen:</span>
|
||||
<input type="text" class="addItemForm__nameInput" name="itemName" placeholder="Gegenstand eingeben...">
|
||||
<input type="text" class="addItemForm__amountInput" name="itemAmount" placeholder="Menge eingeben...">
|
||||
<select class="addItemForm__categorySelect" name="itemCategoryID">
|
||||
<option value="">Keine</option>
|
||||
<option th:each="category : ${categories}" th:text="${category.categoryName}" th:value="${category.id}"></option>
|
||||
</select>
|
||||
<button class="addItemForm__submitButton" type="submit">Hinzufügen</button>
|
||||
</form>
|
||||
|
||||
<button class="deleteAllDoneItemsButton">Alle fertigen Items löschen</button>
|
||||
|
||||
|
||||
<ul class="displayedList">
|
||||
<!-- Es werden erste alle Kategorien erstellt, jede Kategorie muss ein ul in einem li sein um Verschachtelung zu ermöglichen -->
|
||||
<li th:each="category: ${categories}" th:data-id="${category.id}" class="category">
|
||||
<shopping-category th:attr="category-name=${category.categoryName}">
|
||||
<ul>
|
||||
<li th:each="item: ${category.itemsInCategory}" th:data-id="${item.id}" class="item">
|
||||
<shopping-item th:attr="item-name=${item.itemName}, item-amount=${item.itemAmount}, is-checked=${item.isDone}"></shopping-item>
|
||||
</li>
|
||||
</ul>
|
||||
</shopping-category>
|
||||
</li>
|
||||
|
||||
<li th:each="item: ${items}" th:data-id="${item.id}" class="item"> <!-- erstellung items ohne Kategorie -->
|
||||
<shopping-item th:attr="item-name=${item.itemName}, item-amount=${item.itemAmount}, is-checked=${item.isDone}"></shopping-item>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,13 @@
|
||||
package de.timaldinger.einkaufsliste;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class EinkaufslisteApplicationTests {
|
||||
|
||||
@Test
|
||||
void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user