pagecontroller, shoppingList und repo hinzugefüt
This commit is contained in:
1 parent
bc558be02d
commit
c2f413329d
5 files changed
+127
No files matched your search
@@ -0,0 +1,36 @@
|
||||
package de.timaldinger.einkaufsliste.Controller;
|
||||
|
||||
import de.timaldinger.einkaufsliste.Models.ShoppingList;
|
||||
import de.timaldinger.einkaufsliste.Repository.ShoppingListRepository;
|
||||
import jakarta.validation.Valid;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/")
|
||||
public class PageController {
|
||||
@Autowired
|
||||
private ShoppingListRepository repository;
|
||||
|
||||
@PostMapping("/list")
|
||||
public String addList(@Valid @ModelAttribute ShoppingList newList){
|
||||
repository.save(newList);
|
||||
return "redirect:/";
|
||||
}
|
||||
|
||||
@GetMapping
|
||||
public String index(Model model){
|
||||
model.addAttribute("lists", repository.findAll());
|
||||
return "index";
|
||||
}
|
||||
|
||||
@GetMapping("/list/{id}")
|
||||
public String list(Model model, @PathVariable UUID id){
|
||||
model.addAttribute("list", repository.findById(id));
|
||||
return "list";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package de.timaldinger.einkaufsliste.Models;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.sql.Date;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
public class ShoppingList extends ShoppingElement {
|
||||
@NotBlank
|
||||
private String listName;
|
||||
private Date dateCreated;
|
||||
private Date lastChanged;
|
||||
private int numberItems;
|
||||
private int numberCategory;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package de.timaldinger.einkaufsliste.Repository;
|
||||
|
||||
import de.timaldinger.einkaufsliste.Models.ShoppingList;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public interface ShoppingListRepository extends JpaRepository<ShoppingList, UUID>{
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<!DOCTYPE html>
|
||||
<html
|
||||
xmlns="http://www.w3.org/1999/xhtml"
|
||||
xmlns:th="http://www.thymeleaf.org">
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
|
||||
<meta name="description" content="" />
|
||||
<meta name="author" content="" />
|
||||
<link href="css/index.css" rel="stylesheet" >
|
||||
|
||||
<body>
|
||||
|
||||
<div class="createShoppingList">
|
||||
<form th:action="@{/list}" method="post">
|
||||
<input type="text" name="listName" required />
|
||||
<button type="submit">Neue Liste erstellen</button>
|
||||
</form>
|
||||
</div>
|
||||
<div class="shoppingListOverwiev">
|
||||
<a th:each="list: ${lists}" th:text="${list.name}"></a>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>niggas</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="title">
|
||||
<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>
|
||||
|
||||
<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>
|
||||
|
||||
<button type="" class="deleteAllDoneItemsButton">Alle fertigen Items löschen</button>
|
||||
|
||||
|
||||
<ul class="displayedList">
|
||||
<
|
||||
</ul>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user