add Article as Entity
* update spring-boot to version 2.2.4
This commit is contained in:
parent
230d71944f
commit
39b29c0f87
|
@ -88,4 +88,4 @@ local.properties
|
|||
*.launch
|
||||
|
||||
# SQLite
|
||||
prototype/src/main/resources/*.db
|
||||
prototype/*.db
|
||||
|
|
|
@ -3,7 +3,7 @@ buildscript {
|
|||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.2.2.RELEASE")
|
||||
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.2.4.RELEASE")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package org.hso.ecommerce.app;
|
||||
|
||||
import org.hso.ecommerce.contoller.Login;
|
||||
import org.hso.ecommerce.db.ArticleRepository;
|
||||
import org.hso.ecommerce.db.CustomerRepository;
|
||||
import org.hso.ecommerce.entities.Article;
|
||||
import org.hso.ecommerce.entities.Customer;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
@ -18,7 +20,16 @@ import java.util.UUID;
|
|||
@Controller
|
||||
public class RequestController {
|
||||
|
||||
static int notSoRandom = 0;
|
||||
static int notSoRandom = 0;
|
||||
|
||||
// TODO move this to a separate controller
|
||||
private final ArticleRepository articleRepo;
|
||||
|
||||
@Autowired
|
||||
public RequestController(ArticleRepository articleRepo) {
|
||||
this.articleRepo = articleRepo;
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/")
|
||||
public String home() {
|
||||
|
@ -32,13 +43,13 @@ public class RequestController {
|
|||
|
||||
@PostMapping("/login")
|
||||
public String loginPost(HttpServletResponse response, @RequestParam(value = "goto", required = false) String gto) {
|
||||
response.addCookie(new Cookie("login", "true"));
|
||||
response.addCookie(new Cookie("login", "true"));
|
||||
|
||||
if (gto != null && gto.startsWith("/")) {
|
||||
return "redirect:" + gto;
|
||||
} else {
|
||||
return "redirect:/";
|
||||
}
|
||||
if (gto != null && gto.startsWith("/")) {
|
||||
return "redirect:" + gto;
|
||||
} else {
|
||||
return "redirect:/";
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/logout")
|
||||
|
@ -71,10 +82,11 @@ public class RequestController {
|
|||
public String shopCheckoutFinish() {
|
||||
return "shop/checkoutFinish";
|
||||
}
|
||||
|
||||
@GetMapping("/shop/checkoutFinish")
|
||||
public String shopCheckoutFinishGET() {
|
||||
return "shop/checkoutFinish";
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/shop/articles/{id}")
|
||||
public String shopArticlesById() {
|
||||
|
@ -82,13 +94,13 @@ public class RequestController {
|
|||
}
|
||||
|
||||
@PostMapping("/shop/articles/{id}")
|
||||
public String shopArticlesByIdBuy(@RequestAttribute("customer") Boolean isCustomer, @PathVariable("id") Integer id) {
|
||||
public String shopArticlesByIdBuy(@RequestAttribute("customer") Boolean isCustomer, @PathVariable("id") Integer id) {
|
||||
if (isCustomer) {
|
||||
return "redirect:/shop/checkout";
|
||||
return "redirect:/shop/checkout";
|
||||
} else {
|
||||
return "redirect:/login?goto=%2Fshop%2Farticles%2F"+id;
|
||||
return "redirect:/login?goto=%2Fshop%2Farticles%2F" + id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/user/")
|
||||
public String user() {
|
||||
|
@ -144,6 +156,19 @@ public class RequestController {
|
|||
|
||||
@GetMapping("/intern/listedArticles/{id}")
|
||||
public String internListedArticlesId() {
|
||||
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);
|
||||
System.out.println("Article saved!");
|
||||
|
||||
return "intern/listedArticles/id";
|
||||
}
|
||||
|
||||
|
@ -235,18 +260,23 @@ public class RequestController {
|
|||
|
||||
@PostMapping("/intern/warehouse/progress/{id}")
|
||||
public String accountingWarehouseProgressIdPost(HttpServletResponse response) {
|
||||
if((notSoRandom++) % 2 == 1) {
|
||||
return "redirect:/intern/warehouse/progress/450";
|
||||
} else {
|
||||
response.setStatus(409);
|
||||
return "intern/warehouse/error_progress_failed";
|
||||
}
|
||||
if ((notSoRandom++) % 2 == 1) {
|
||||
return "redirect:/intern/warehouse/progress/450";
|
||||
} else {
|
||||
response.setStatus(409);
|
||||
return "intern/warehouse/error_progress_failed";
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/intern/warehouse/progress/{id}")
|
||||
public String accountingWarehouseProgressId() {
|
||||
return "intern/warehouse/id_progress";
|
||||
}
|
||||
return "intern/warehouse/id_progress";
|
||||
}
|
||||
|
||||
@GetMapping("/intern/warehouse/error_progress_failed")
|
||||
public String err() {
|
||||
return "intern/warehouse/error_progress_failed";
|
||||
}
|
||||
|
||||
@GetMapping("/intern/warehouse/slots/")
|
||||
public String accountingWarehouseSlots() {
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package org.hso.ecommerce.db;
|
||||
|
||||
import org.hso.ecommerce.entities.Article;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface ArticleRepository extends JpaRepository<Article, Long> {
|
||||
|
||||
@Query("SELECT a FROM Article a WHERE a.title = :title")
|
||||
List<Article> findByTitle(String title);
|
||||
|
||||
@Query("SELECT a FROM Article a WHERE a.id = :id")
|
||||
List<Article> findByID(int id);
|
||||
}
|
|
@ -5,7 +5,6 @@ import org.springframework.context.annotation.Bean;
|
|||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
package org.hso.ecommerce.entities;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@Entity
|
||||
@Table(name = "article")
|
||||
public class Article {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "id_Sequence")
|
||||
@SequenceGenerator(name = "id_Sequence", sequenceName = "ID_SEQ")
|
||||
public Long id;
|
||||
public String title;
|
||||
public String category;
|
||||
public String description;
|
||||
public int refArticle;
|
||||
public int sellingPrice;
|
||||
public int maxPurchasePrice;
|
||||
public int maxStock;
|
||||
public int currentStock;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getCategory() {
|
||||
return category;
|
||||
}
|
||||
|
||||
public void setCategory(String category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public int getRefArticle() {
|
||||
return refArticle;
|
||||
}
|
||||
|
||||
public void setRefArticle(int refArticle) {
|
||||
this.refArticle = refArticle;
|
||||
}
|
||||
|
||||
public int getSellingPrice() {
|
||||
return sellingPrice;
|
||||
}
|
||||
|
||||
public void setSellingPrice(int sellingPrice) {
|
||||
this.sellingPrice = sellingPrice;
|
||||
}
|
||||
|
||||
public int getMaxPurchasePrice() {
|
||||
return maxPurchasePrice;
|
||||
}
|
||||
|
||||
public void setMaxPurchasePrice(int maxPurchasePrice) {
|
||||
this.maxPurchasePrice = maxPurchasePrice;
|
||||
}
|
||||
|
||||
public int getMaxStock() {
|
||||
return maxStock;
|
||||
}
|
||||
|
||||
public void setMaxStock(int maxStock) {
|
||||
this.maxStock = maxStock;
|
||||
}
|
||||
|
||||
public int getCurrentStock() {
|
||||
return currentStock;
|
||||
}
|
||||
|
||||
public void setCurrentStock(int currentStock) {
|
||||
this.currentStock = currentStock;
|
||||
}
|
||||
}
|
|
@ -7,7 +7,7 @@ import javax.persistence.*;
|
|||
public class Customer {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator = "id_Sequence")
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "id_Sequence")
|
||||
@SequenceGenerator(name = "id_Sequence", sequenceName = "ID_SEQ")
|
||||
public Long id;
|
||||
public String lastname;
|
||||
|
|
|
@ -5,3 +5,15 @@ CREATE TABLE "customers" (
|
|||
"username" TEXT,
|
||||
"password" TEXT
|
||||
);
|
||||
|
||||
CREATE TABLE "article" (
|
||||
"id" INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
"title" TEXT,
|
||||
"category" TEXT,
|
||||
"description" TEXT,
|
||||
"refArticle" INTEGER,
|
||||
"sellingPrice" INTEGER,
|
||||
"maxPurchasePrice" INTEGER,
|
||||
"maxStock" INTEGER,
|
||||
"currentStock" INTEGER
|
||||
);
|
||||
|
|
Reference in New Issue