Compare commits
19
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d5df05f87a | ||
|
|
ea34010c8d | ||
|
|
7428c7db25 | ||
|
|
2b2889cb63 | ||
|
|
6bedcb1836 | ||
|
|
a635d7c374 | ||
|
|
02eac10d9a | ||
|
|
a49ceea355 | ||
|
|
4f453c0263 | ||
|
|
409469e098 | ||
|
|
821f5c7216 | ||
|
|
77b5ed5991 | ||
|
|
6175817db2 | ||
|
|
ea3b07ed0f | ||
|
|
33964f2a30 | ||
|
|
49377a98a8 | ||
|
|
5b313a4364 | ||
|
|
afda716a66 | ||
|
|
f5add6b590 |
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)
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
.displayedList__categoryName--bold {
|
||||
font-weight: bold;
|
||||
}
|
||||
.displayedList__categoryName--big {
|
||||
font-size = 3rem;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in new issue
Block a user