Compare commits

...
19 Commits
Author SHA1 Message Date
Technoir d5df05f87a auflisten von items ohne Kategorie 2026-10-05 22:01:56 +02:00
Technoir ea34010c8d richtiges erstellen von verschachtelten listen
es wird ein <li> erstellt, welches die Kategorie repräsentiert, in
diesem li gibt es eine <ul>, wo für jedes item in der Kategorie ein
neues <li> angelegt wird
2026-10-05 22:01:45 +02:00
Technoir 7428c7db25 Kategorien sind nun auswählbar
die value entspricht der categoryID um sie genau zuordnen zu können
2026-10-05 22:00:30 +02:00
Technoir 2b2889cb63 bugfix: listID schon im scheiß parameter 2026-10-05 21:56:53 +02:00
Technoir 6bedcb1836 delete Item IMpolementeier 2026-10-05 21:56:17 +02:00
Technoir a635d7c374 bugfix: currentList iwrd bei list.js schon als die ID der liste übergeben 2026-10-05 21:56:10 +02:00
Technoir 02eac10d9a deleteItem() implementier 2026-10-05 21:55:32 +02:00
Technoir a49ceea355 evenListener für das löschen von Items hinzugefügt
es wird das jeweilige <li> Element übergeben, dies vereinfacht die
Handhabung für API und UI Handling
2026-10-05 21:55:13 +02:00
Technoir 4f453c0263 event listener für Forms hinzugefügt 2026-10-05 21:54:11 +02:00
Technoir 409469e098 Item kann gelöscht werden 2026-10-05 21:53:14 +02:00
Technoir 821f5c7216 Kategorie kann hinzugefügt weren 2026-10-05 21:53:08 +02:00
Technoir 77b5ed5991 import entfernt weil nicht nötig 2026-10-05 21:52:31 +02:00
Technoir 6175817db2 addItem ruft api und ui addItem auf mit richtigen parameter + logging 2026-10-05 21:52:10 +02:00
Technoir ea3b07ed0f styles für Kategorien hinzugefügt 2026-10-05 21:51:28 +02:00
Technoir 33964f2a30 category kann optional sein 2026-10-05 21:51:19 +02:00
Technoir 49377a98a8 trailing / vom Pfad entfernt 2026-10-05 21:51:02 +02:00
Technoir 5b313a4364 löschen von items Möglich 2026-10-05 21:50:50 +02:00
Technoir afda716a66 eine category wird auf viele Items gemapped durch das Feld category in ShoppingListItem 2026-10-05 21:50:33 +02:00
Technoir f5add6b590 refactor 2026-10-05 21:48:56 +02:00
8 changed files with 100 additions and 28 deletions

No files matched your search

@@ -9,11 +9,11 @@ import de.timaldinger.einkaufsliste.Repository.ShoppingListCategoryRepository;
import de.timaldinger.einkaufsliste.Repository.ShoppingListItemRepository;
import de.timaldinger.einkaufsliste.Repository.ShoppingListRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseEntity;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.thymeleaf.expression.Lists;
import java.util.List;
@@ -42,14 +42,28 @@ public class ShoppingListController {
return category;
}
@PostMapping("/api/list/{listID}/item/")
@PostMapping("/api/list/{listID}/item")
public ShoppingListItem addItem(@PathVariable UUID listID, @RequestBody ShoppingListItemDTO newItem){
String name = newItem.itemName();
String amount = newItem.itemAmount();
ShoppingListCategory c = shoppingListCategoryRepository.findById(newItem.category()).orElseThrow();
ShoppingListCategory c;
if(newItem.categoryID() != null){
c = shoppingListCategoryRepository.findById(newItem.categoryID()).orElseThrow();
}else{
c = null;
}
ShoppingList list = shoppingListRepository.findById(listID).orElseThrow();
ShoppingListItem item = new ShoppingListItem(name, amount, false, c, list);
shoppingListItemRepository.save(item);
return item;
}
@DeleteMapping("/api/item/{itemID}")
public ResponseEntity<Void> deleteItem(@PathVariable UUID itemID){
if(!shoppingListItemRepository.existsById(itemID)){
return ResponseEntity.notFound().build();
}
shoppingListItemRepository.deleteById(itemID);
return ResponseEntity.noContent().build();
}
}
@@ -2,5 +2,5 @@ package de.timaldinger.einkaufsliste.Dto;
import java.util.UUID;
public record ShoppingListItemDTO (String itemName, String itemAmount, UUID category){
public record ShoppingListItemDTO (String itemName, String itemAmount, UUID categoryID){
}
@@ -18,7 +18,7 @@ public class ShoppingListCategory extends ShoppingElement{
@NotBlank
private String categoryName;
@OneToMany
@OneToMany(mappedBy = "category")
private List<ShoppingListItem> itemsInCategory;
@ManyToOne
@JoinColumn(name="list_id", nullable = false)
+6
View File
@@ -0,0 +1,6 @@
.displayedList__categoryName--bold {
font-weight: bold;
}
.displayedList__categoryName--big {
font-size = 3rem;
}
+39 -2
View File
@@ -1,14 +1,51 @@
import { ShoppingListItem } from "../shared/";
import { ShoppingCategory } from "./ShoppingCategory.js";
import * as api from "./listAPI.js"
import * as ui from "./listFrontend.js"
const addCategoryForm = document.querySelector(".addCategoryForm");
const addItemForm = document.querySelector(".addItemForm");
const currentList = document.querySelector(".list");
function addItem(itemName, itemAmount, categoryID) {
console.log(`${currentList.id}, ${itemName}, ${itemAmount}, ${categoryID}`)
api.addItem(currentList.id, itemName, itemAmount, categoryID);
ui.addItem();
}
function addCategory(categoryName) {
console.log(`adding category ${categoryName}`)
api.addCategory(currentList.id, categoryName);
ui.addCategory(categoryName);
return 0;
}
function deleteItem(li) {
api.deleteItem(li.id);
ui.deleteItem(li);
}
function init() {
addCategoryForm.addEventListener("submit", (event) => {
event.preventDefault();
let formData = Object.fromEntries(new FormData(addCategoryForm));
addCategory(formData.categoryName);
});
addItemForm.addEventListener("submit", event => {
event.preventDefault();
let formData = Object.fromEntries(new FormData(addItemForm));
addItem(formData.itemName, formData.itemAmount, formData.itemCategoryID);
})
document.querySelectorAll(".item__buttonDelete").forEach(button => {
button.addEventListener("click", event => {
const li = button.closest("li");
deleteItem(li);
})
})
console.log("javascript initialized!");
return 0;
}
+10 -7
View File
@@ -1,7 +1,6 @@
export function addItem(currentList, itemName, itemAmount, categoryID) {
let id = currentList.id;
fetch(`/api/list/${id}/item`,
export function addItem(listID, itemName, itemAmount, categoryID) {
fetch(`/api/list/${listID}/item`,
{
method: "POST",
body: JSON.stringify({
@@ -17,13 +16,17 @@ export function addItem(currentList, itemName, itemAmount, categoryID) {
}
export function deleteItem() {
export function deleteItem(itemID) {
fetch(`/api/item/${itemID}`, { method: "DELETE" })
.then(r => console.log("item deleted"));
return 0;
}
export function addCategory() {
let id = currentList.id;
fetch(`/api/list/${id}/category/`,
export function addCategory(listID, categoryName) {
fetch(`/api/list/${listID}/category/`,
{
method: "POST"
, body: JSON.stringify({ "categoryName": categoryName })
@@ -3,8 +3,8 @@ export function addItem() {
}
export function deleteItem() {
export function deleteItem(li) {
li.remove();
}
export function addCategory() {
+21 -9
View File
@@ -26,7 +26,9 @@
<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="itemCategory">
<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>
@@ -35,16 +37,26 @@
<ul class="displayedList">
<li> <!-- Es werden erste alle Kategorien erstellt -->
<ul class="displayedList__categoryName--bold displayedList__categoryName--big"
th:each="category: ${categories}"
th:id="${category.id}"
th:text="${category.categoryName}"> <!-- für jede Kategorie wird ein ul erstellt in welcher dann die Items aufgeführt werden -->
<li th:each="item: ${category.itemsInCategory}">
<span th:text="${item.itemName}"></span>
</li>
<!-- 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:id="${category.id}">
<span class="displayedList__categoryName--bold displayedList__categoryName--big" th:text="${category.categoryName}"></span>
<!-- Items der Kategorie -->
<ul>
<li th:each="item: ${category.itemsInCategory}" th:id="${item.id}"> <!-- erstellung von einem Item -->
<input type="checkbox" class="item__markAsDone">
<span th:text="${item.itemName}"></span>
<span th:text="${item.itemAmount}"></span>
<button class="item__buttonDelete">Löschen</button>
</li>
</ul>
</li>
<li th:each="item: ${items}" th:id="${item.id}"> <!-- erstellung items ohne Kategorie -->
<input type="checkbox" class="item__markAsDone">
<span th:text="${item.itemName}"></span>
<span th:text="${item.itemAmount}"></span>
<button class="item__buttonDelete">Löschen</button>
</li>
</ul>
</div>