Compare commits

...
10 Commits
Author SHA1 Message Date
Technoir ed0df61e16 alle abgeschlossenene Items werden gelöscht, fixes #6
wir schicken eine delete request an /api/list/{listID}, im backend wird
dann geschaut, welche items in der liste mit der listID schon
abgeschlossen sind. Im frontend entfernen wir alle li dessen child input
checked=true und item__markAsDone klasse hat
2026-10-07 15:15:54 +02:00
Technoir abb1af276c bug: falscher json paraemter, soll isDone heißen nicht done 2026-10-07 15:13:42 +02:00
Technoir 2ade9c9744 checkboxen der erstellten items im frontend haben auch item__markAsDone klasse 2026-10-07 15:13:22 +02:00
Technoir 6bd55f6e86 deleteMapping methode entfernt und zu ShoppingListController verschoben 2026-10-07 15:13:02 +02:00
Technoir 226e7f68ce toString ausgabe hinzugefügt 2026-10-07 15:12:35 +02:00
Technoir e4df4f492d refactor, findByList zu findByList_Id 2026-10-07 15:11:24 +02:00
Technoir 4bbbdf7d10 bug: autocomplete standardmäßig on, lässt nach dem löschen von einem done item das nachrückende als done markieren, verwirrt nutzer 2026-10-07 15:10:52 +02:00
Technoir 1b321420a5 Items wenn abgehakt werden auch im backend als done markiert, fixes #13
Wir haben eine editItem() Methode erstellt, welches ein JSON mitbekommen
kriegt mit den Änderungen eines bestimmten items mit itemID. Das
ShoppingItemPatchDTO hat nullable Felder und im Controller wird nur das
geändert von einem item, was nicht null ist.
2026-10-07 14:14:19 +02:00
Technoir 344ae5c584 dto erstellt für PATCH auf items 2026-10-07 14:10:09 +02:00
Technoir cd12da1099 user story template hinzugefügt 2026-10-06 23:04:04 +02:00
12 changed files with 139 additions and 15 deletions

No files matched your search

+57
View File
@@ -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: "- [ ] "
@@ -37,12 +37,6 @@ public class PageController {
return "index";
}
@DeleteMapping("/api/list/{id}")
public String deleteList(Model model, @PathVariable UUID id){
shoppingListRepository.deleteById(id);
return "redirect:/";
}
/**
* Gibt die list.html Seite einer Liste zurück mit den Attributen list, categories und items
* @param model
@@ -54,7 +48,7 @@ public class PageController {
ShoppingList list = shoppingListRepository.findById(id).orElseThrow();
model.addAttribute("list", list);
model.addAttribute("categories", shoppingCategoryRepository.findByShoppingList(list));
model.addAttribute("items", shoppingItemRepository.findByListAndCategoryIsNull(list));
model.addAttribute("items", shoppingItemRepository.findByList_IdAndCategoryIsNull(id));
return "list";
}
}
@@ -1,6 +1,7 @@
package de.timaldinger.einkaufsliste.Controller;
import de.timaldinger.einkaufsliste.Dto.ShoppingItemDTO;
import de.timaldinger.einkaufsliste.Dto.ShoppingItemPatchDTO;
import de.timaldinger.einkaufsliste.Dto.ShoppingItemResponseDTO;
import de.timaldinger.einkaufsliste.Models.ShoppingCategory;
import de.timaldinger.einkaufsliste.Models.ShoppingItem;
@@ -40,6 +41,20 @@ public class ShoppingItemController {
return new ShoppingItemResponseDTO(name, amount, item.getId(), c != null? c.getId() : null);
}
@PatchMapping("/api/item/{itemID}")
public ResponseEntity<Void> editItem(@PathVariable UUID itemID ,@RequestBody ShoppingItemPatchDTO toChange){
ShoppingItem item = shoppingItemRepository.findById(itemID).orElseThrow();
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());
shoppingItemRepository.save(item);
return ResponseEntity.noContent().build();
}
@DeleteMapping("/api/item/{itemID}")
public ResponseEntity<Void> deleteItem(@PathVariable UUID itemID){
if(!shoppingItemRepository.existsById(itemID)){
@@ -26,5 +26,13 @@ public class ShoppingListController {
@Autowired
private ShoppingItemRepository shoppingItemRepository;
@DeleteMapping("/api/list/{listID}")
public ResponseEntity<Void> deleteAllDoneItems(@PathVariable UUID listID, @RequestParam(required = false) boolean deleteAllDoneItems){
if(deleteAllDoneItems){
List<ShoppingItem> items = shoppingItemRepository.findByList_IdAndIsDoneIsTrue(listID);
shoppingItemRepository.deleteAll(items);
}
return ResponseEntity.noContent().build();
}
}
@@ -0,0 +1,6 @@
package de.timaldinger.einkaufsliste.Dto;
import java.util.UUID;
public record ShoppingItemPatchDTO(String itemName, String itemAmount, Boolean isDone, UUID categoryID) {
}
@@ -4,16 +4,14 @@ import jakarta.persistence.Entity;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.validation.constraints.NotBlank;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.*;
@Getter
@Setter
@Entity
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class ShoppingItem extends ShoppingElement {
@NotBlank
@@ -9,6 +9,7 @@ import java.util.UUID;
public interface ShoppingItemRepository extends JpaRepository<ShoppingItem, UUID> {
List<ShoppingItem> findByListAndCategoryIsNull(ShoppingList list);
List<ShoppingItem> findByList_IdAndCategoryIsNull(UUID list);
List<ShoppingItem> findAllByCategory_Id(UUID categoryID);
List<ShoppingItem> findByList_IdAndIsDoneIsTrue(UUID listID);
}
@@ -26,6 +26,8 @@ export class ShoppingItem {
li.classList.add("item");
checkboxDone.setAttribute("type", "checkbox");
checkboxDone.setAttribute("autocomplete", "off");
checkboxDone.classList.add("item__markAsDone");
span.textContent = this.itemName + " " + this.itemAmount;
+17 -1
View File
@@ -5,6 +5,7 @@ import * as ui from "./listFrontend.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.id}, name: ${itemName}, amount: ${itemAmount}, category: ${categoryID}`)
@@ -32,6 +33,12 @@ function deleteCategory(deleteAllItems, categoryID) {
ui.deleteCategory(deleteAllItems, categoryID);
}
function deleteAllDoneItems() {
console.log(`deleting all done items...`)
api.deleteAllDoneItems(currentList.id);
ui.deleteAllDoneItems();
}
function init() {
addCategoryForm.addEventListener("submit", (event) => {
event.preventDefault();
@@ -43,7 +50,11 @@ function init() {
event.preventDefault();
let formData = Object.fromEntries(new FormData(addItemForm));
addItem(formData.itemName, formData.itemAmount, formData.itemCategoryID);
})
});
deleteAllDoneItemsButton.addEventListener("click", event => {
deleteAllDoneItems();
});
//event delegation ist schon geil
document.querySelector(".displayedList").addEventListener("click", (event) => {
@@ -55,6 +66,11 @@ function init() {
deleteCategory(checkbox.checked, li.id);
}
document.querySelector(".displayedList").addEventListener("change", (e) => {
if (e.target.matches(".item__markAsDone")) {
const item = e.target.closest("li");
api.editItem(item.id, { isDone: e.target.checked });
}
});
console.log("javascript initialized!");
@@ -29,6 +29,17 @@ export async function deleteItem(itemID) {
}
export async function editItem(itemID, toChange) {
const response = await fetch(`/api/item/${itemID}`,
{
method: "PATCH",
body: JSON.stringify(toChange),
headers: { "Content-Type": "application/json" }
});
return response;
}
export async function addCategory(listID, categoryName) {
const newCategory = await fetch(`/api/category`,
{
@@ -48,3 +59,14 @@ export async function deleteCategory(deleteAllItems, categoryID) {
}
return response;
}
export async function deleteAllDoneItems(listID) {
const response = await fetch(`/api/list/${listID}?deleteAllDoneItems=true`, { method: "DELETE" });
if (response.status == 204) {
console.log(`items have been deleted`);
}
return response;
}
@@ -34,4 +34,9 @@ export function deleteCategory(deleteAllItems, categoryID) {
category.remove()
}
export function deleteAllDoneItems() {
const doneItems = document.querySelectorAll("li.item:has(input[type=checkbox]:checked)");
doneItems.forEach((li) => {
li.remove();
})
}
+2 -2
View File
@@ -45,7 +45,7 @@
<!-- Items der Kategorie -->
<ul>
<li th:each="item: ${category.itemsInCategory}" th:id="${item.id}" class="item"> <!-- erstellung von einem Item -->
<input type="checkbox" class="item__markAsDone">
<input type="checkbox" class="item__markAsDone" th:checked="${item.isDone}">
<span th:text="|${item.itemName} ${item.itemAmount}|"></span>
<button class="item__deleteButton">Löschen</button>
</li>
@@ -53,7 +53,7 @@
</li>
<li th:each="item: ${items}" th:id="${item.id}" class="item"> <!-- erstellung items ohne Kategorie -->
<input type="checkbox" class="item__markAsDone">
<input type="checkbox" class="item__markAsDone" th:checked="${item.isDone}" autocomplete="off">
<span th:text="|${item.itemName} ${item.itemAmount}|"></span>
<button class="item__deleteButton">Löschen</button>
</li>