Compare commits
10
Commits
fae479ae57
...
22e8606a0f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
22e8606a0f | ||
|
|
782344494c | ||
|
|
ae5c28dc8f | ||
|
|
47815e073d | ||
|
|
c0ad79188b | ||
|
|
1db3b6a397 | ||
|
|
cc132a1341 | ||
|
|
b65b58aa39 | ||
|
|
02a5139e29 | ||
|
|
c2762d8011 |
No files matched your search
@@ -23,3 +23,6 @@ target
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
|
||||
# H2
|
||||
data
|
||||
@@ -1,6 +1,8 @@
|
||||
package de.timaldinger.einkaufsliste.Controller;
|
||||
|
||||
import de.timaldinger.einkaufsliste.Models.ShoppingList;
|
||||
import de.timaldinger.einkaufsliste.Repository.ShoppingListCategoryRepository;
|
||||
import de.timaldinger.einkaufsliste.Repository.ShoppingListItemRepository;
|
||||
import de.timaldinger.einkaufsliste.Repository.ShoppingListRepository;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -8,15 +10,23 @@ import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/")
|
||||
public class PageController {
|
||||
@Autowired
|
||||
private ShoppingListRepository repository;
|
||||
|
||||
@PostMapping("/list")
|
||||
@Autowired
|
||||
private ShoppingListRepository shoppingListRepository;
|
||||
|
||||
@Autowired
|
||||
private ShoppingListCategoryRepository shoppingListCategoryRepository;
|
||||
|
||||
@Autowired
|
||||
private ShoppingListItemRepository shoppingListItemRepository;
|
||||
|
||||
@PostMapping("api/list")
|
||||
public String addList(@Valid @ModelAttribute ShoppingList newList){
|
||||
shoppingListRepository.save(newList);
|
||||
return "redirect:/";
|
||||
@@ -28,15 +38,24 @@ public class PageController {
|
||||
return "index";
|
||||
}
|
||||
|
||||
@DeleteMapping("/list/{id}")
|
||||
@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
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/list/{id}")
|
||||
public String list(Model model, @PathVariable UUID id){
|
||||
model.addAttribute("list", repository.findById(id));
|
||||
ShoppingList list = shoppingListRepository.findById(id).orElseThrow();
|
||||
model.addAttribute("list", list);
|
||||
model.addAttribute("categories", shoppingListCategoryRepository.findByShoppingList(list));
|
||||
model.addAttribute("items", shoppingListItemRepository.findByListAndCategoryIsNull(list));
|
||||
return "list";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package de.timaldinger.einkaufsliste.Controller;
|
||||
|
||||
import de.timaldinger.einkaufsliste.Dto.ShoppingCategoryDTO;
|
||||
import de.timaldinger.einkaufsliste.Models.ShoppingList;
|
||||
import de.timaldinger.einkaufsliste.Models.ShoppingListCategory;
|
||||
import de.timaldinger.einkaufsliste.Models.ShoppingListItem;
|
||||
import de.timaldinger.einkaufsliste.Repository.ShoppingListCategoryRepository;
|
||||
import de.timaldinger.einkaufsliste.Repository.ShoppingListRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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.thymeleaf.expression.Lists;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@RestController
|
||||
public class ShoppingListController {
|
||||
|
||||
@Autowired
|
||||
private ShoppingListCategoryRepository shoppingListCategoryRepository;
|
||||
@Autowired
|
||||
private ShoppingListRepository shoppingListRepository;
|
||||
|
||||
@PostMapping("/api/list/{listID}/category/")
|
||||
public ShoppingListCategory addCategory(@PathVariable UUID listID, @RequestBody ShoppingCategoryDTO newCategory){
|
||||
|
||||
String name = newCategory.categoryName();
|
||||
ShoppingList list = shoppingListRepository.findById(listID).orElseThrow();
|
||||
|
||||
ShoppingListCategory category = new ShoppingListCategory(name, List.of(),list);
|
||||
|
||||
shoppingListCategoryRepository.save(category);
|
||||
|
||||
return category;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package de.timaldinger.einkaufsliste.Dto;
|
||||
|
||||
public record ShoppingCategoryDTO(String categoryName) {
|
||||
}
|
||||
@@ -2,7 +2,9 @@ package de.timaldinger.einkaufsliste.Models;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.List;
|
||||
@@ -10,6 +12,8 @@ import java.util.List;
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ShoppingListCategory extends ShoppingElement{
|
||||
|
||||
@NotBlank
|
||||
|
||||
+2
-4
@@ -2,14 +2,12 @@ package de.timaldinger.einkaufsliste.Repository;
|
||||
|
||||
import de.timaldinger.einkaufsliste.Models.ShoppingList;
|
||||
import de.timaldinger.einkaufsliste.Models.ShoppingListCategory;
|
||||
import de.timaldinger.einkaufsliste.Models.ShoppingListItem;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface ShoppingListCategoryRepository extends JpaRepository<ShoppingListCategory, UUID>{
|
||||
List<ShoppingListItem> findByList(Optional<ShoppingList> list);
|
||||
List<ShoppingListItem> findByListAndCategoryIsNull(ShoppingList list);
|
||||
List<ShoppingListCategory> findByShoppingList(ShoppingList list);
|
||||
|
||||
}
|
||||
@@ -4,7 +4,10 @@ import de.timaldinger.einkaufsliste.Models.ShoppingElement;
|
||||
import de.timaldinger.einkaufsliste.Models.ShoppingListItem;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface ShoppingListItemRepository extends JpaRepository<ShoppingListItem, UUID> {
|
||||
|
||||
List<ShoppingListItem> findByListAndCategoryIsNull(Object list);
|
||||
}
|
||||
@@ -1,9 +1,12 @@
|
||||
package de.timaldinger.einkaufsliste.Repository;
|
||||
|
||||
import de.timaldinger.einkaufsliste.Models.ShoppingList;
|
||||
import de.timaldinger.einkaufsliste.Models.ShoppingListItem;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface ShoppingListRepository extends JpaRepository<ShoppingList, UUID>{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import { ShoppingList } from "./ShoppingList.js";
|
||||
|
||||
|
||||
const deleteListButtons = document.querySelectorAll('.shoppingListOverview__deleteListButton');
|
||||
const shoppingLists = [];
|
||||
|
||||
|
||||
function fillList() {
|
||||
document.querySelectorAll('.shoppingListOverview__shoppingList')
|
||||
.forEach(list => {
|
||||
shoppingLists.push(new ShoppingList(list.id));
|
||||
console.log(list.id);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function deleteList(id) {
|
||||
fetch(`/api/list/${id}`, { method: "DELETE" }).then(r => console.log("Liste entfernt"))
|
||||
}
|
||||
|
||||
|
||||
function init() {
|
||||
deleteListButtons.forEach(button => {
|
||||
button.addEventListener("click", () => {
|
||||
const id = button.dataset.id; // liest data-id
|
||||
deleteList(id);
|
||||
});
|
||||
});
|
||||
fillList();
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', init);
|
||||
@@ -6,10 +6,18 @@ const addCategoryForm = document.querySelector(".addCategoryForm")
|
||||
const itemListElement = document.querySelector(".displayedList");
|
||||
const deleteAllDoneItemsButton = document.querySelector(".deleteAllDoneItemsButton");
|
||||
|
||||
const currentList = document.querySelector(".list");
|
||||
|
||||
let listElements = []; // Liste der erstellten Items und Kategorien
|
||||
|
||||
function addNewCategory(categoryName) {
|
||||
|
||||
let id = currentList.id;
|
||||
fetch(`/api/list/${id}/category/`,
|
||||
{
|
||||
method: "POST"
|
||||
, body: JSON.stringify({ "categoryName": categoryName })
|
||||
, headers: { "Content-Type": "application/json" }
|
||||
}).then(r => console.log("Add new category"));
|
||||
listElements.push(new ShoppingCategory(categoryName, renderAddItemPrompt, renderItemList));
|
||||
renderItemList();
|
||||
return 0;
|
||||
|
||||
@@ -1,38 +1,39 @@
|
||||
<!DOCTYPE html>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>niggas</title>
|
||||
</head>
|
||||
<body>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Einkaufsliste</title>
|
||||
<link href="/css/style.css" rel="stylesheet">
|
||||
<script src="/js/list/main.js" type="module"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="title">
|
||||
<h1>Einkaufsliste</h1>
|
||||
<h1>Einkaufsliste</h1>
|
||||
</div>
|
||||
|
||||
<div class="list">
|
||||
<form class="addCategoryForm">
|
||||
<span>Neue Kategorie hinzufügen:</span>
|
||||
<input type="text" class="addCategoryForm__nameInput" name="categoryName" placeholder="Neue Kategorie hinzufügen...">
|
||||
<button class="addCategoryForm__submitButton" type="submit">Hinzufügen</button>
|
||||
</form>
|
||||
<div class="list">
|
||||
<form class="addCategoryForm">
|
||||
<span>Neue Kategorie hinzufügen:</span>
|
||||
<input type="text" class="addCategoryForm__nameInput" name="categoryName" placeholder="Neue Kategorie hinzufügen...">
|
||||
<button class="addCategoryForm__submitButton" type="submit">Hinzufügen</button>
|
||||
</form>
|
||||
|
||||
<br>
|
||||
<br>
|
||||
|
||||
<form class="addItemForm">
|
||||
<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>
|
||||
<button class="addItemForm__submitButton" type="submit">Hinzufügen</button>
|
||||
</form>
|
||||
<form class="addItemForm">
|
||||
<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>
|
||||
<button class="addItemForm__submitButton" type="submit">Hinzufügen</button>
|
||||
</form>
|
||||
|
||||
<button type="" class="deleteAllDoneItemsButton">Alle fertigen Items löschen</button>
|
||||
<button class="deleteAllDoneItemsButton">Alle fertigen Items löschen</button>
|
||||
<ul class="displayedList">
|
||||
</ul>
|
||||
|
||||
|
||||
<ul class="displayedList">
|
||||
<
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user