add Article update via /intern/listedArticles/ID
This commit is contained in:
parent
39b29c0f87
commit
e99dfea609
@ -155,23 +155,37 @@ public class RequestController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/intern/listedArticles/{id}")
|
@GetMapping("/intern/listedArticles/{id}")
|
||||||
public String internListedArticlesId() {
|
public String internListedArticlesId(Model model) {
|
||||||
Article article = new Article();
|
|
||||||
article.setTitle("Test-Artikel");
|
|
||||||
article.setCategory("Ding");
|
|
||||||
article.setDescription("Ein einfacher Artikel.");
|
|
||||||
article.setRefArticle(123);
|
|
||||||
article.setSellingPrice(1000);
|
|
||||||
article.setMaxPurchasePrice(5000);
|
|
||||||
article.setMaxStock(20);
|
|
||||||
article.setCurrentStock(4);
|
|
||||||
|
|
||||||
articleRepo.save(article);
|
if (articleRepo.findByRefArticle(8405).size() == 0) {
|
||||||
System.out.println("Article saved!");
|
// the article doesn't exist in the db, add it
|
||||||
|
Article article = new Article();
|
||||||
|
article.setTitle("Kamera");
|
||||||
|
article.setCategory("Überwachung\nElektronik");
|
||||||
|
article.setDescription("Eine TOLLE Kamera\n" +
|
||||||
|
"Jaja du denkst jetzt bestimmt: \"Bei dem Preis kann sie gar nich sooo TOLL sein\".\n" +
|
||||||
|
"Aber glaub mir, sie is echt echt TOLL!\n" +
|
||||||
|
"Indianerehrenwort!");
|
||||||
|
article.setRefArticle(8405);
|
||||||
|
article.setSellingPrice(84.45f);
|
||||||
|
article.setMaxPurchasePrice(80.98f);
|
||||||
|
article.setMaxStock(20);
|
||||||
|
article.setCurrentStock(12);
|
||||||
|
|
||||||
|
articleRepo.save(article);
|
||||||
|
}
|
||||||
|
|
||||||
|
model.addAttribute(articleRepo.findByRefArticle(8405).get(0));
|
||||||
|
|
||||||
return "intern/listedArticles/id";
|
return "intern/listedArticles/id";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping(value="/updateArticleAction", method=RequestMethod.POST, params="action=updateArticleAction")
|
||||||
|
public String updateArticleAction(@ModelAttribute Article article, HttpServletResponse response) {
|
||||||
|
articleRepo.updateByRefArticle(article.refArticle, article.title);
|
||||||
|
|
||||||
|
return "redirect:intern/listedArticles/id";
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/intern/articles/")
|
@GetMapping("/intern/articles/")
|
||||||
public String internArticles() {
|
public String internArticles() {
|
||||||
|
@ -2,8 +2,10 @@ package org.hso.ecommerce.db;
|
|||||||
|
|
||||||
import org.hso.ecommerce.entities.Article;
|
import org.hso.ecommerce.entities.Article;
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
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.jpa.repository.Query;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -15,4 +17,13 @@ public interface ArticleRepository extends JpaRepository<Article, Long> {
|
|||||||
|
|
||||||
@Query("SELECT a FROM Article a WHERE a.id = :id")
|
@Query("SELECT a FROM Article a WHERE a.id = :id")
|
||||||
List<Article> findByID(int id);
|
List<Article> findByID(int id);
|
||||||
|
|
||||||
|
@Query("SELECT a FROM Article a WHERE a.refArticle = :refArticle")
|
||||||
|
List<Article> findByRefArticle(int refArticle);
|
||||||
|
|
||||||
|
// https://www.logicbig.com/tutorials/spring-framework/spring-data/modifying-queries.html
|
||||||
|
@Transactional
|
||||||
|
@Modifying
|
||||||
|
@Query("UPDATE Article a SET a.title = :title WHERE a.refArticle = :refArticle")
|
||||||
|
void updateByRefArticle(int refArticle, String title);
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,8 @@ public class Article {
|
|||||||
public String category;
|
public String category;
|
||||||
public String description;
|
public String description;
|
||||||
public int refArticle;
|
public int refArticle;
|
||||||
public int sellingPrice;
|
public float sellingPrice;
|
||||||
public int maxPurchasePrice;
|
public float maxPurchasePrice;
|
||||||
public int maxStock;
|
public int maxStock;
|
||||||
public int currentStock;
|
public int currentStock;
|
||||||
|
|
||||||
@ -59,19 +59,19 @@ public class Article {
|
|||||||
this.refArticle = refArticle;
|
this.refArticle = refArticle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSellingPrice() {
|
public float getSellingPrice() {
|
||||||
return sellingPrice;
|
return sellingPrice;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSellingPrice(int sellingPrice) {
|
public void setSellingPrice(float sellingPrice) {
|
||||||
this.sellingPrice = sellingPrice;
|
this.sellingPrice = sellingPrice;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMaxPurchasePrice() {
|
public float getMaxPurchasePrice() {
|
||||||
return maxPurchasePrice;
|
return maxPurchasePrice;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMaxPurchasePrice(int maxPurchasePrice) {
|
public void setMaxPurchasePrice(float maxPurchasePrice) {
|
||||||
this.maxPurchasePrice = maxPurchasePrice;
|
this.maxPurchasePrice = maxPurchasePrice;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,8 +12,8 @@ CREATE TABLE "article" (
|
|||||||
"category" TEXT,
|
"category" TEXT,
|
||||||
"description" TEXT,
|
"description" TEXT,
|
||||||
"refArticle" INTEGER,
|
"refArticle" INTEGER,
|
||||||
"sellingPrice" INTEGER,
|
"sellingPrice" FLOAT,
|
||||||
"maxPurchasePrice" INTEGER,
|
"maxPurchasePrice" FLOAT,
|
||||||
"maxStock" INTEGER,
|
"maxStock" INTEGER,
|
||||||
"currentStock" INTEGER
|
"currentStock" INTEGER
|
||||||
);
|
);
|
||||||
|
@ -22,14 +22,14 @@
|
|||||||
<nav th:replace="fragments/intern :: sidebar"></nav>
|
<nav th:replace="fragments/intern :: sidebar"></nav>
|
||||||
<div class="content-width">
|
<div class="content-width">
|
||||||
<h2>Gelisteter Artikel 8450</h2>
|
<h2>Gelisteter Artikel 8450</h2>
|
||||||
<form class="detailgrid">
|
<form class="detailgrid" th:action="@{/updateArticleAction}" th:object="${article}" method="post">
|
||||||
<p class="m">
|
<p class="m">
|
||||||
<label for="title">Titel</label>
|
<label for="title">Titel</label>
|
||||||
<input class=" full-width" type="text" name="title" value="Kamera" />
|
<input class=" full-width" type="text" id="title" th:field="*{title}" value="Kamera" />
|
||||||
</p>
|
</p>
|
||||||
<p class="s">
|
<p class="s">
|
||||||
<label for="ref-article">Refernzierter Artikel</label>
|
<label for="ref-article">Refernzierter Artikel</label>
|
||||||
<input class="" type="text" name="ref-article" value="8405" disabled />
|
<input class="" type="text" id="ref-article" th:field="*{refArticle}" value="8405" readonly/>
|
||||||
<td><a th:href="@{/intern/articles/#q=%2044048}">Details</a></td>
|
<td><a th:href="@{/intern/articles/#q=%2044048}">Details</a></td>
|
||||||
</p>
|
</p>
|
||||||
<div class="spacer"></div>
|
<div class="spacer"></div>
|
||||||
@ -45,14 +45,14 @@
|
|||||||
<div class="s">
|
<div class="s">
|
||||||
<p>
|
<p>
|
||||||
<label for="price">Preis (Netto)</label>
|
<label for="price">Preis (Netto)</label>
|
||||||
<input class="" type="number" step="0.01" name="price" value="84.45" /> EUR <br />
|
<input class="" type="number" step="0.01" id="price" th:field="*{sellingPrice}" value="84.45" /> EUR <br />
|
||||||
(19% Mwst.)
|
(19% Mwst.)
|
||||||
<!-- Info von article ref--> <br />
|
<!-- Info von article ref--> <br />
|
||||||
= 105.98 EUR Brutto
|
= 105.98 EUR Brutto
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<label for="max-price-buy">Maximaler Einkaufspreis (Netto)</label>
|
<label for="max-price-buy">Maximaler Einkaufspreis (Netto)</label>
|
||||||
<input class="" type="number" step="0.01" name="price" value="80.98" /> EUR
|
<input class="" type="number" step="0.01" id="max-price-buy" th:field="*{maxPurchasePrice}" value="80.98" /> EUR
|
||||||
</p>
|
</p>
|
||||||
<div>
|
<div>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
@ -69,7 +69,7 @@
|
|||||||
<p>
|
<p>
|
||||||
Bitte jede Kategorien in eine eigene Zeile
|
Bitte jede Kategorien in eine eigene Zeile
|
||||||
</p>
|
</p>
|
||||||
<textarea name="tags" class="full-width" rows="6">
|
<textarea id="tags" class="full-width" rows="6" th:field="*{category}" >
|
||||||
Überwachung
|
Überwachung
|
||||||
Elektronik
|
Elektronik
|
||||||
</textarea>
|
</textarea>
|
||||||
@ -77,8 +77,8 @@ Elektronik
|
|||||||
|
|
||||||
<div class="s">
|
<div class="s">
|
||||||
<p>
|
<p>
|
||||||
<label for="price">Einheiten pro Lagerplatz</label>
|
<label for="units-per-slot">Einheiten pro Lagerplatz</label>
|
||||||
<input class="" type="number" name="units-per-slot" value="20" />
|
<input class="" type="number" id="units-per-slot" th:field="*{maxStock}" value="20" />
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
<b>Lagerbestand: 12</b>
|
<b>Lagerbestand: 12</b>
|
||||||
@ -96,7 +96,7 @@ Elektronik
|
|||||||
|
|
||||||
<p class="l">
|
<p class="l">
|
||||||
<label for="description">Beschreibung</label>
|
<label for="description">Beschreibung</label>
|
||||||
<textarea name="description" class="full-width" rows="15">
|
<textarea id="description" class="full-width" rows="15" th:field="*{description}">
|
||||||
Eine TOLLE Kamera
|
Eine TOLLE Kamera
|
||||||
Jaja du denkst jetzt bestimmt: "Bei dem Preis kann sie gar nich sooo TOLL sein".
|
Jaja du denkst jetzt bestimmt: "Bei dem Preis kann sie gar nich sooo TOLL sein".
|
||||||
Aber glaub mir, sie is echt echt TOLL!
|
Aber glaub mir, sie is echt echt TOLL!
|
||||||
@ -104,7 +104,7 @@ Indianerehrenwort!
|
|||||||
</textarea>
|
</textarea>
|
||||||
</p>
|
</p>
|
||||||
<div class="l">
|
<div class="l">
|
||||||
<button type="submit">Änderungen speichern</button>
|
<button type="submit" name="action" value="updateArticleAction">Änderungen speichern</button>
|
||||||
<button type="reset">Zurücksetzen</button>
|
<button type="reset">Zurücksetzen</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
Reference in New Issue
Block a user