Compare commits
13
Commits
7202eea4cc
...
05874500b8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
05874500b8 | ||
|
|
b14b0ac08b | ||
|
|
c72b14e594 | ||
|
|
5a48acba2f | ||
|
|
b5d61ff772 | ||
|
|
66e8ac13ea | ||
|
|
6aa624a507 | ||
|
|
71d7d373eb | ||
|
|
0564d81b25 | ||
|
|
c724bafb06 | ||
|
|
d39acbd54a | ||
|
|
ab7734915b | ||
|
|
9361de6cb0 |
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){
|
||||
|
||||
+1
-1
@@ -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);
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in new issue
Block a user