From c097e58bf36b0dc5ddce228353612abd9e915bbf Mon Sep 17 00:00:00 2001 From: Hannes Date: Fri, 8 May 2020 09:58:29 +0200 Subject: [PATCH] change Databasename and add Advertisementflag --- prototype/.gitignore | 2 +- .../ecommerce/controller/shop/ShopArticleController.java | 4 +--- .../ecommerce/controller/shop/ShopIndexController.java | 3 +-- .../org/hso/ecommerce/entities/supplier/ArticleOffer.java | 2 ++ .../org/hso/ecommerce/repos/shop/ArticleRepository.java | 8 +++----- prototype/src/main/resources/application.properties | 2 +- prototype/src/main/resources/templates/shop/checkout.html | 3 ++- 7 files changed, 11 insertions(+), 13 deletions(-) diff --git a/prototype/.gitignore b/prototype/.gitignore index 4fac9a9..52b353d 100644 --- a/prototype/.gitignore +++ b/prototype/.gitignore @@ -1,4 +1,4 @@ -./e-commerce.db +e-commerce.db ./build ./gradle ./out diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopArticleController.java b/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopArticleController.java index a6159d9..6d8cea9 100644 --- a/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopArticleController.java +++ b/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopArticleController.java @@ -13,12 +13,10 @@ import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; -import java.io.ByteArrayInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.List; -import java.util.Optional; @Controller @RequestMapping("/shop/articles") @@ -53,7 +51,7 @@ public class ShopArticleController { model.addAttribute("inStock", false); } - List
commercialArticles = articleRepository.getCommercialisedArticles("2"); + List
commercialArticles = articleRepository.getAdvertisedArticles(); model.addAttribute("commercialArticles", commercialArticles); diff --git a/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopIndexController.java b/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopIndexController.java index 69dce5d..73c3241 100644 --- a/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopIndexController.java +++ b/prototype/src/main/java/org/hso/ecommerce/controller/shop/ShopIndexController.java @@ -9,7 +9,6 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import javax.servlet.http.HttpSession; -import javax.swing.*; import java.util.List; @Controller @@ -27,7 +26,7 @@ public class ShopIndexController { @GetMapping("/shop/") public String shop(Model model, HttpSession session) { - List
commercialArticles = articleRepository.getCommercialisedArticles("4"); + List
commercialArticles = articleRepository.getAdvertisedArticles(); model.addAttribute("commercialArticles", commercialArticles); //check if logged in diff --git a/prototype/src/main/java/org/hso/ecommerce/entities/supplier/ArticleOffer.java b/prototype/src/main/java/org/hso/ecommerce/entities/supplier/ArticleOffer.java index 005b0b9..ce02d13 100644 --- a/prototype/src/main/java/org/hso/ecommerce/entities/supplier/ArticleOffer.java +++ b/prototype/src/main/java/org/hso/ecommerce/entities/supplier/ArticleOffer.java @@ -19,4 +19,6 @@ public class ArticleOffer { public String articleNumber; public int vatPercent; + + public boolean should_be_advertised; } diff --git a/prototype/src/main/java/org/hso/ecommerce/repos/shop/ArticleRepository.java b/prototype/src/main/java/org/hso/ecommerce/repos/shop/ArticleRepository.java index 42ef5ee..a22f191 100644 --- a/prototype/src/main/java/org/hso/ecommerce/repos/shop/ArticleRepository.java +++ b/prototype/src/main/java/org/hso/ecommerce/repos/shop/ArticleRepository.java @@ -13,16 +13,14 @@ import java.util.Optional; @Repository public interface ArticleRepository extends JpaRepository { - @Query(nativeQuery = true, value = "Select * FROM articles where articles.id = :articleId") + @Query("Select a FROM Article a where a.id = :articleId") Article findArticleById(@Param("articleId") long articleId); - //TODO: getCommercialisedArticles(int quantity) - @Query("SELECT c FROM User c WHERE c.email = :quantity") - List
getCommercialisedArticles(@Param("quantity") String quantity); + @Query("SELECT a from Article a join a.related ao where ao.should_be_advertised = true") + List
getAdvertisedArticles(); - //TODO: getLastOrderedArticles(int quantity) @Query("SELECT c FROM User c WHERE c.email = :quantity") List
getLastOrderedArticles(@Param("quantity") String quantity); diff --git a/prototype/src/main/resources/application.properties b/prototype/src/main/resources/application.properties index b62e80f..18ec88c 100644 --- a/prototype/src/main/resources/application.properties +++ b/prototype/src/main/resources/application.properties @@ -3,7 +3,7 @@ spring.resources.cache.cachecontrol.maxAge=P0D # LOGGING logging.level.org.springframework.web=WARN # DATABASE -spring.datasource.url=jdbc:sqlite:./test.db +spring.datasource.url=jdbc:sqlite:./e-commerce.db spring.datasource.driverClassName=org.sqlite.JDBC spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.SQLiteDialect spring.jpa.hibernate.ddl-auto=update diff --git a/prototype/src/main/resources/templates/shop/checkout.html b/prototype/src/main/resources/templates/shop/checkout.html index cf02b5c..9962649 100644 --- a/prototype/src/main/resources/templates/shop/checkout.html +++ b/prototype/src/main/resources/templates/shop/checkout.html @@ -44,7 +44,8 @@ + th:src="@{/shop/articles/{id}/image.jpg(id=${item.article.id})}" class="s"/> +