Compare commits
12
Commits
05874500b8
...
bb6d4abe9e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bb6d4abe9e | ||
|
|
844decd963 | ||
|
|
de72438a0b | ||
|
|
e8fcb5ed9c | ||
|
|
9f436720e9 | ||
|
|
18daded2c2 | ||
|
|
e579044ed5 | ||
|
|
f7d11a77d1 | ||
|
|
080f61a0c8 | ||
|
|
18ac0273bd | ||
|
|
c104754ff3 | ||
|
|
4a0c70fb98 |
No files matched your search
@@ -41,7 +41,7 @@ public class PageController {
|
||||
public String list(Model model, @PathVariable UUID id){
|
||||
ShoppingList list = shoppingListRepository.findById(id).orElseThrow();
|
||||
model.addAttribute("list", list);
|
||||
model.addAttribute("categories", shoppingCategoryRepository.findByShoppingList(list));
|
||||
model.addAttribute("categories", shoppingCategoryRepository.findByList(list));
|
||||
model.addAttribute("items", shoppingItemRepository.findByList_IdAndCategoryIsNull(id));
|
||||
return "list";
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@RestController
|
||||
@@ -63,4 +64,15 @@ public class ShoppingItemController {
|
||||
shoppingItemRepository.deleteById(itemID);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
|
||||
@DeleteMapping("/api/item")
|
||||
public ResponseEntity<Void> deleteAllDoneItems(@RequestParam UUID listID, @RequestParam boolean done){
|
||||
if(!done) return ResponseEntity.badRequest().build();
|
||||
|
||||
List<ShoppingItem> items = shoppingItemRepository.findByList_IdAndIsDoneIsTrue(listID);
|
||||
shoppingItemRepository.deleteAll(items);
|
||||
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import de.timaldinger.einkaufsliste.Models.ShoppingList;
|
||||
import de.timaldinger.einkaufsliste.Repository.ShoppingCategoryRepository;
|
||||
import de.timaldinger.einkaufsliste.Repository.ShoppingItemRepository;
|
||||
import de.timaldinger.einkaufsliste.Repository.ShoppingListRepository;
|
||||
import de.timaldinger.einkaufsliste.Service.ShoppingListService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -23,6 +24,8 @@ public class ShoppingListController {
|
||||
private ShoppingListRepository shoppingListRepository;
|
||||
@Autowired
|
||||
private ShoppingItemRepository shoppingItemRepository;
|
||||
@Autowired
|
||||
private ShoppingListService shoppingListService;
|
||||
|
||||
@PostMapping("/api/list")
|
||||
public ShoppingListResponseDTO addList(@RequestBody ShoppingListPostDTO newList){
|
||||
@@ -32,14 +35,9 @@ public class ShoppingListController {
|
||||
|
||||
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){
|
||||
List<ShoppingItem> items = shoppingItemRepository.findByList_IdAndIsDoneIsTrue(listID);
|
||||
shoppingItemRepository.deleteAll(items);
|
||||
}
|
||||
public ResponseEntity<Void> deleteList(@PathVariable UUID listID){
|
||||
shoppingListService.deleteList(listID);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,6 +22,6 @@ public class ShoppingCategory extends ShoppingElement{
|
||||
private List<ShoppingItem> itemsInCategory;
|
||||
@ManyToOne //mehrere Kategorien (Many) gehören (to) einer Liste an (one)
|
||||
@JoinColumn(name="list_id", nullable = false)
|
||||
private ShoppingList shoppingList;
|
||||
private ShoppingList list;
|
||||
|
||||
}
|
||||
+7
-2
@@ -3,11 +3,16 @@ package de.timaldinger.einkaufsliste.Repository;
|
||||
import de.timaldinger.einkaufsliste.Models.ShoppingList;
|
||||
import de.timaldinger.einkaufsliste.Models.ShoppingCategory;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface ShoppingCategoryRepository extends JpaRepository<ShoppingCategory, UUID>{
|
||||
List<ShoppingCategory> findByShoppingList(ShoppingList list);
|
||||
|
||||
List<ShoppingCategory> findByList(ShoppingList list);
|
||||
@Modifying
|
||||
@Query("DELETE FROM ShoppingCategory c WHERE c.list.id = :listID")
|
||||
void deleteByListId(@Param("listID") UUID listID);
|
||||
}
|
||||
@@ -3,6 +3,9 @@ package de.timaldinger.einkaufsliste.Repository;
|
||||
import de.timaldinger.einkaufsliste.Models.ShoppingItem;
|
||||
import de.timaldinger.einkaufsliste.Models.ShoppingList;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@@ -12,4 +15,7 @@ public interface ShoppingItemRepository extends JpaRepository<ShoppingItem, UUID
|
||||
List<ShoppingItem> findByList_IdAndCategoryIsNull(UUID list);
|
||||
List<ShoppingItem> findAllByCategory_Id(UUID categoryID);
|
||||
List<ShoppingItem> findByList_IdAndIsDoneIsTrue(UUID listID);
|
||||
@Modifying
|
||||
@Query("DELETE FROM ShoppingItem i WHERE i.list.id = :listID")
|
||||
void deleteByListId(@Param("listID") UUID listID);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package de.timaldinger.einkaufsliste.Service;
|
||||
|
||||
import de.timaldinger.einkaufsliste.Repository.ShoppingCategoryRepository;
|
||||
import de.timaldinger.einkaufsliste.Repository.ShoppingItemRepository;
|
||||
import de.timaldinger.einkaufsliste.Repository.ShoppingListRepository;
|
||||
import jakarta.transaction.Transactional;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Service
|
||||
public class ShoppingListService {
|
||||
@Autowired
|
||||
private ShoppingItemRepository shoppingItemRepository;
|
||||
@Autowired
|
||||
private ShoppingListRepository shoppingListRepository;
|
||||
@Autowired
|
||||
private ShoppingCategoryRepository shoppingCategoryRepository;
|
||||
|
||||
@Transactional
|
||||
public void deleteList(UUID listID){
|
||||
shoppingItemRepository.deleteByListId(listID);
|
||||
shoppingCategoryRepository.deleteByListId(listID);
|
||||
shoppingListRepository.deleteById(listID);
|
||||
}
|
||||
}
|
||||
@@ -14,8 +14,8 @@ export async function addList(listName) {
|
||||
}
|
||||
|
||||
export async function deleteList(id) {
|
||||
const response = await fetch(`/api/list/${id}`, { method: "DELETE" })
|
||||
.then(r => console.log("Liste entfernt"))
|
||||
const response = await fetch(`/api/list/${id}`, { method: "DELETE" });
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -6,3 +6,7 @@ export function addList(listAsJSON) {
|
||||
const listElement = ShoppingList.fromJSON(listAsJSON);
|
||||
list.append(listElement.render());
|
||||
}
|
||||
|
||||
export function deleteList(listElement) {
|
||||
listElement.remove();
|
||||
}
|
||||
@@ -14,8 +14,11 @@ function editList() {
|
||||
|
||||
}
|
||||
|
||||
function deleteList() {
|
||||
function deleteList(listElement) {
|
||||
|
||||
const response = api.deleteList(listElement.id);
|
||||
|
||||
if (response.status == 204) ui.deleteList(listElement);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +29,15 @@ function init() {
|
||||
addList(formData.listName);
|
||||
});
|
||||
|
||||
document.querySelector(".index").addEventListener("click", (event) => {
|
||||
if (event.target.matches(".list__editButton")) {
|
||||
|
||||
} else if (event.target.matches(".list__deleteButton")) {
|
||||
deleteList(event.target.closest("li"));
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', init);
|
||||
@@ -41,4 +41,14 @@ export async function editItem(itemID, toChange) {
|
||||
return response;
|
||||
}
|
||||
|
||||
export async function deleteAllDoneItems(listID) {
|
||||
|
||||
const response = await fetch(`/api/item?listID=${listID}&done=true`, { method: "DELETE" });
|
||||
|
||||
if (response.status == 204) {
|
||||
console.log(`items have been deleted`);
|
||||
}
|
||||
return response;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +1,3 @@
|
||||
export * from "./itemAPI.js";
|
||||
export * from "./categoryAPI.js"
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user