Compare commits
10
Commits
bce0b982ee
...
ed0df61e16
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ed0df61e16 | ||
|
|
abb1af276c | ||
|
|
2ade9c9744 | ||
|
|
6bd55f6e86 | ||
|
|
226e7f68ce | ||
|
|
e4df4f492d | ||
|
|
4bbbdf7d10 | ||
|
|
1b321420a5 | ||
|
|
344ae5c584 | ||
|
|
cd12da1099 |
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: "- [ ] "
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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();
|
||||
})
|
||||
}
|
||||
@@ -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>
|
||||
|
||||
Reference in new issue
Block a user