genofire/hs_monolith
genofire
/
hs_monolith
Archived
1
0
Fork 0

[TASK] fix for presentation

This commit is contained in:
Martin Geno 2017-06-23 12:45:24 +02:00
parent 0754b05118
commit 0aa115e34c
No known key found for this signature in database
GPG Key ID: F0D39A37E925E941
4 changed files with 27 additions and 10 deletions

View File

@ -11,6 +11,10 @@ public interface ProductRepository extends Repository<Product, Integer> {
+ "where key(i) = ?1 and lower(i.name) = ?2") + "where key(i) = ?1 and lower(i.name) = ?2")
Product findByI18nName(String language, String name); Product findByI18nName(String language, String name);
@Query("select p from Product p join fetch p.i18n i left join fetch i.reviews r "
+ "where key(i) = ?1 and p.id = ?2")
Product findByID(String language, Integer id);
@Query("select p from Product p") @Query("select p from Product p")
List<Product> findAll(); List<Product> findAll();

View File

@ -30,7 +30,7 @@ public class ShopService {
/** /**
* Gets all categories of the current language. * Gets all categories of the current language.
* *
* @return A simplified Data Transfer Object. * @return A simplified Data Transfer Object.
*/ */
public List<CategoryDTO> getCategories(Locale locale) { public List<CategoryDTO> getCategories(Locale locale) {
@ -44,7 +44,7 @@ public class ShopService {
/** /**
* Gets all products for a category in the current language. * Gets all products for a category in the current language.
* *
* @return A simplified Data Transfer Object. * @return A simplified Data Transfer Object.
*/ */
public List<ProductDTO> getProductsForCategory(Locale locale, String prettyUrlFragment) { public List<ProductDTO> getProductsForCategory(Locale locale, String prettyUrlFragment) {
@ -73,7 +73,20 @@ public class ShopService {
/** /**
* Gets a product in the current language. * Gets a product in the current language.
* *
* @return A simplified Data Transfer Object.
*/
public ProductDTO getProduct(Locale locale, Integer id) {
Product product = productRepository.findByID(locale.getLanguage(), id);
if (product == null) {
throw new NotFoundException();
}
return dtoFactory.createProductDTO(product, locale);
}
/**
* Gets a product in the current language.
*
* @return A simplified Data Transfer Object. * @return A simplified Data Transfer Object.
*/ */
public ProductDTO getProduct(Locale locale, String prettyUrlFragment) { public ProductDTO getProduct(Locale locale, String prettyUrlFragment) {

View File

@ -31,7 +31,7 @@ public class ProductController {
/** /**
* Product page * Product page
* *
* @param prettyUrlFragment Pretty URL fragment * @param prettyUrlFragment Pretty URL fragment
* @param model Template model * @param model Template model
* @param locale Current locale * @param locale Current locale
@ -46,7 +46,7 @@ public class ProductController {
/** /**
* Post a review * Post a review
* *
* @param reviewForm Form data * @param reviewForm Form data
* @param bindingResult Form binding result after validation * @param bindingResult Form binding result after validation
* @param prettyUrlFragment Product context * @param prettyUrlFragment Product context
@ -69,10 +69,10 @@ public class ProductController {
return TEMPLATE; return TEMPLATE;
} }
@RequestMapping(value = "/products/{prettyUrlFragment:[\\w-]+}.json", method = RequestMethod.GET) @RequestMapping(value = "/products/{id}.json", method = RequestMethod.GET)
@ResponseBody @ResponseBody
public ProductDTO productJson(@PathVariable String prettyUrlFragment, Locale locale) { public ProductDTO productJson(@PathVariable Integer id, Locale locale) {
return shopService.getProduct(locale, prettyUrlFragment); return shopService.getProduct(locale, id);
} }
@RequestMapping(value = "/products.json", method = RequestMethod.GET) @RequestMapping(value = "/products.json", method = RequestMethod.GET)

View File

@ -33,7 +33,7 @@
<h2 th:text="${product.name}">Product Name</h2> <h2 th:text="${product.name}">Product Name</h2>
<!-- Addition: traffic light food labeling system of the stock microservice --> <!-- Addition: traffic light food labeling system of the stock microservice -->
<img width="10%" class="icon" th:src="${'https://stock.pub.warehost.de/api/good/availablity/'+product.id}"/> <img width="10%" class="icon" th:src="${'http://localhost:8081/api/good/availablity/'+product.id}"/>
<p class="text-info text-uppercase" th:text="${product.price}">0,00 Euro</p> <p class="text-info text-uppercase" th:text="${product.price}">0,00 Euro</p>
<p class="lead" th:text="${product.description}">Description.</p> <p class="lead" th:text="${product.description}">Description.</p>
@ -53,4 +53,4 @@
<script src="../static/js/bootstrap.min.js" <script src="../static/js/bootstrap.min.js"
th:src="@{/js/bootstrap.min.js}"></script> th:src="@{/js/bootstrap.min.js}"></script>
</body> </body>
</html> </html>