Compare commits

...
13 Commits
Author SHA1 Message Date
Technoir 05874500b8 Merge branch 'feature/21-create-lists-frontend', fixes #21 2026-10-09 21:35:12 +02:00
Technoir b14b0ac08b struktur überarbeitet
eine div index die alle inhalte hat, es wird jtz pro liste ein LI und
ein UL mehr erstellt. li hat id. Im li gibt es jtz auch einen
Bearbeitungsknopf
2026-10-09 21:34:41 +02:00
Technoir c72b14e594 whitespace digga 2026-10-09 21:33:45 +02:00
Technoir 5a48acba2f vorabgreifen für bearbeiten und löschen von listen 2026-10-09 21:33:38 +02:00
Technoir b5d61ff772 addList() implementiert und eventHandler für das hinzufügen von Listen am Form hinzugefügt 2026-10-09 21:33:26 +02:00
Technoir 66e8ac13ea liste wird nun in den listen hinzugefügt 2026-10-09 21:32:53 +02:00
Technoir 6aa624a507 response als json im return 2026-10-09 21:32:35 +02:00
Technoir 71d7d373eb ShoppingList li Element wird richtig erstellt 2026-10-09 21:32:25 +02:00
Technoir 0564d81b25 konstruktoren hinzugefügt 2026-10-09 21:32:10 +02:00
Technoir c724bafb06 refactor 2026-10-09 21:32:04 +02:00
Technoir d39acbd54a addList implementiert 2026-10-09 21:31:56 +02:00
Technoir ab7734915b bug: categoryID war noch id 2026-10-09 21:29:59 +02:00
Technoir 9361de6cb0 dateien hinzugefügt 2026-10-09 21:00:43 +02:00
9 changed files with 110 additions and 43 deletions

No files matched your search

@@ -1,6 +1,9 @@
package de.timaldinger.einkaufsliste.Controller;
import de.timaldinger.einkaufsliste.Dto.Post.ShoppingListPostDTO;
import de.timaldinger.einkaufsliste.Dto.Response.ShoppingListResponseDTO;
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;
@@ -21,6 +24,15 @@ public class ShoppingListController {
@Autowired
private ShoppingItemRepository shoppingItemRepository;
@PostMapping("/api/list")
public ShoppingListResponseDTO addList(@RequestBody ShoppingListPostDTO newList){
ShoppingList list = new ShoppingList(newList.listName(), null, null, 0, 0);
shoppingListRepository.save(list);
return new ShoppingListResponseDTO(list.getListName(), list.getId());
}
@DeleteMapping("/api/list/{listID}")
public ResponseEntity<Void> deleteAllDoneItems(@PathVariable UUID listID, @RequestParam(required = false) boolean deleteAllDoneItems){
if(deleteAllDoneItems){
@@ -2,5 +2,5 @@ package de.timaldinger.einkaufsliste.Dto.Response;
import java.util.UUID;
public record ShoppingListResponseDTO (String listName, UUID shoppingListID){
public record ShoppingListResponseDTO (String listName, UUID listID){
}
@@ -2,7 +2,9 @@ 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;
@@ -10,6 +12,8 @@ import java.sql.Date;
@Getter
@Setter
@Entity
@AllArgsConstructor
@NoArgsConstructor
public class ShoppingList extends ShoppingElement {
@NotBlank
private String listName;
@@ -1,11 +1,39 @@
export class ShoppingList{
constructor(id){
this.shoppingListName;
this.lastModified = "";
this.created = "";
this.id = id;
this.remove = false;
}
}
export class ShoppingList {
constructor(name) {
this.listName = name;
this.lastModified = "";
this.created = "";
this.listID = 0;
}
static fromJSON(listAsJSON) {
const list = new ShoppingList(listAsJSON.listName);
list.listID = listAsJSON.listID;
return list;
}
render() {
const li = document.createElement("li");
const a = document.createElement("a");
const editButton = document.createElement("button");
const deleteButton = document.createElement("button");
li.classList.add("list");
li.id = this.listID;
a.setAttribute("href", `/list/${this.listID}`);
a.textContent = this.listName;
editButton.classList.add("list__editButton");
editButton.textContent = "Liste bearbeiten";
deleteButton.classList.add("list__deleteButton");
deleteButton.textContent = "Liste löschen";
li.append(a, editButton, deleteButton);
return li;
}
}
@@ -0,0 +1,21 @@
export async function addList(listName) {
const response = await fetch(`/api/list`,
{
method: "POST",
body: JSON.stringify({ listName: listName }),
headers: { "Content-Type": "application/json" }
}
);
return response.json();
}
export async function deleteList(id) {
const response = await fetch(`/api/list/${id}`, { method: "DELETE" })
.then(r => console.log("Liste entfernt"))
return response;
}
@@ -0,0 +1,8 @@
import { ShoppingList } from "../../../models/ShoppingList.js";
export function addList(listAsJSON) {
const list = document.querySelector(".displayedList");
const listElement = ShoppingList.fromJSON(listAsJSON);
list.append(listElement.render());
}
@@ -1,32 +1,31 @@
import { ShoppingList } from "./ShoppingList.js";
import { ShoppingList } from "../../models/ShoppingList.js";
import * as api from "./api/indexAPI.js";
import * as ui from "./frontend/indexUI.js"
const addListForm = document.querySelector(".addListForm");
const deleteListButtons = document.querySelectorAll('.shoppingListOverview__deleteListButton');
const shoppingLists = [];
async function addList(listName) {
const listAsJson = await api.addList(listName);
console.log(`${listAsJson}`);
if (listAsJson) ui.addList(listAsJson);
}
function fillList() {
document.querySelectorAll('.shoppingListOverview__shoppingList')
.forEach(list => {
shoppingLists.push(new ShoppingList(list.id));
console.log(list.id);
});
function editList() {
}
function deleteList(id) {
fetch(`/api/list/${id}`, { method: "DELETE" }).then(r => console.log("Liste entfernt"))
function deleteList() {
}
function init() {
deleteListButtons.forEach(button => {
button.addEventListener("click", () => {
const id = button.dataset.id; // liest data-id
deleteList(id);
});
addListForm.addEventListener("submit", (e) => {
e.preventDefault();
const formData = Object.fromEntries(new FormData(addListForm));
addList(formData.listName);
});
fillList();
}
document.addEventListener('DOMContentLoaded', init);
@@ -88,11 +88,8 @@ async function editCategory(categoryElement) {
formElement.addEventListener("keydown", (e) => {
if (e.key == "Escape") formElement.replaceWith(categoryDiv);
})
}
function deleteItem(li) {
api.deleteItem(li.id);
ui.deleteItem(li);
+10 -12
View File
@@ -11,21 +11,19 @@ xmlns:th="http://www.thymeleaf.org">
<script src="/js/pages/index/index.js" type="module"></script>
<body>
<div class="index">
<form class="addListForm">
<input type="text" name="listName" required />
<button type="submit">Neue Liste erstellen</button>
</form>
<div class="createShoppingList">
<form th:action="@{api/list}" method="post">
<input type="text" name="listName" required />
<button type="submit">Neue Liste erstellen</button>
</form>
</div>
<div class="shoppingListOverwiev">
<ul th:each="shoppingList : ${lists}" >
<li class="shoppingListOverview__shoppingList" th:id="${shoppingList.id}" th:attr="name=${shoppingList.listName}">
<a th:text="${shoppingList.listName}" th:href="@{/list/{id}(id=${shoppingList.id})}"></a>
<button type="button" class="shoppingListOverview__deleteListButton" th:attr="data-id=${shoppingList.id}">Liste löschen</button>
<ul class="displayedList">
<li th:each="list : ${lists}" class="list" th:id="${list.id}">
<a th:text="${list.listName}" th:href="@{/list/{id}(id=${list.id})}"></a>
<button type="button" class="list__editButton">Liste bearbeiten</button>
<button type="button" class="list__deleteButton">Liste löschen</button>
</li>
</ul>
</div>
</body>