Commit 01d153dc by Patryk Czarnik

Edycja danych - wersja bez walidacji

parent 4277823e
......@@ -83,6 +83,29 @@ public class ProductController {
return "redirect:/products";
}
@GetMapping("/new")
public String nowyProdukt() {
return "product_form";
}
@GetMapping("/{id}/edit")
public String edytujProdukt(@PathVariable int id, Model model) {
Optional<Product> product = productRepository.findById(id);
if(product.isPresent()) {
model.addAttribute("product", product.get());
return "product_form";
} else {
model.addAttribute("product_id", id);
return "missing_product";
}
}
@PostMapping({"/new", "/{id}/edit"})
public String zapiszProdukt(Product product) {
productRepository.save(product);
return "product_form";
}
@GetMapping(path="/{id}/photo", produces="image/jpeg")
@ResponseBody
public byte[] getPhoto(@PathVariable int id) {
......
......@@ -11,7 +11,8 @@ public class SecurityConfig {
@Bean
SecurityFilterChain configHttpSecurity(HttpSecurity httpSecurity, HandlerMappingIntrospector hmi) throws Exception {
httpSecurity.authorizeHttpRequests(auth -> auth.anyRequest().permitAll());
httpSecurity.authorizeHttpRequests(auth -> auth.anyRequest().permitAll())
.csrf().disable();
return httpSecurity.build();
}
......
......@@ -16,6 +16,7 @@
<p>Cena: <span class="product-price">${product.price}</span></p>
<p>Stawka VAT: <span class="product-price">${product.vat * 100}%</span></p>
<p class="product-description">${product.description}</p>
<div class="action"><a href="/products/${product.id}/edit">Edytuj</a></div>
<div class="action"><a href="/products/${product.id}/add-to-basket">Dodaj do koszyka</a></div>
</div>
......
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="jakarta.tags.core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Edycja danych produktu</title>
<link rel="stylesheet" type="text/css" href="/styl.css">
</head>
<body>
<h1>Edycja produktu</h1>
<form id="product-form" method="post">
<table class="form">
<tr>
<td><label for="productId">Numer:</label></td>
<td><input id="productId" name="id" placeholder="brak" type="number" readonly="readonly" value="${product.id}"/></td>
</tr>
<tr>
<td><label for="productName">Nazwa towaru:</label></td>
<td><input id="productName" name="productName" placeholder="nazwa..." type="text" value="${product.productName}"/>
</td>
</tr>
<tr>
<td><label for="price">Cena:</label></td>
<td><input id="price" name="price" placeholder="12.90" title="tu wpisz cenę" type="number" step="0.01" value="${product.price}"/>
</td>
</tr>
<tr>
<td><label for="vat">Stawka VAT:</label></td>
<td><input id="vat" name="vat" placeholder="0.23" title="tu wpisz vat" type="number" step="0.01" value="${product.vat}"/>
</td>
</tr>
<tr>
<td><label for="description">Opis:</label></td>
<td><textarea id="description" name="description" rows="10" cols="120">${product.description}</textarea></td>
</tr>
<tr>
<td><button>Zapisz</button></td>
</tr>
</table>
</form>
<div class="action"><a href="/products">powrót do listy produktów</a></div>
<div class="action"><a href="/">powrót do spisu treści</a></div>
</body>
</html>
......@@ -28,6 +28,7 @@
<p>Towar <a href="/products/${product.id}" class="product-name">${product.productName}</a></p>
<p>Cena: <span class="product-price">${product.price}</span></p>
<p class="product-description">${product.description}</p>
<div class="action"><a href="/products/${product.id}/edit">Edytuj</a></div>
<div class="action"><a href="/products/${product.id}/add-to-basket">Dodaj do koszyka</a></div>
</div>
</c:forEach>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment