[TASK] fix for presentation
This commit is contained in:
parent
0754b05118
commit
0aa115e34c
|
@ -11,6 +11,10 @@ public interface ProductRepository extends Repository<Product, Integer> {
|
|||
+ "where key(i) = ?1 and lower(i.name) = ?2")
|
||||
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")
|
||||
List<Product> findAll();
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ public class ShopService {
|
|||
|
||||
/**
|
||||
* Gets all categories of the current language.
|
||||
*
|
||||
*
|
||||
* @return A simplified Data Transfer Object.
|
||||
*/
|
||||
public List<CategoryDTO> getCategories(Locale locale) {
|
||||
|
@ -44,7 +44,7 @@ public class ShopService {
|
|||
|
||||
/**
|
||||
* Gets all products for a category in the current language.
|
||||
*
|
||||
*
|
||||
* @return A simplified Data Transfer Object.
|
||||
*/
|
||||
public List<ProductDTO> getProductsForCategory(Locale locale, String prettyUrlFragment) {
|
||||
|
@ -73,7 +73,20 @@ public class ShopService {
|
|||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public ProductDTO getProduct(Locale locale, String prettyUrlFragment) {
|
||||
|
|
|
@ -31,7 +31,7 @@ public class ProductController {
|
|||
|
||||
/**
|
||||
* Product page
|
||||
*
|
||||
*
|
||||
* @param prettyUrlFragment Pretty URL fragment
|
||||
* @param model Template model
|
||||
* @param locale Current locale
|
||||
|
@ -46,7 +46,7 @@ public class ProductController {
|
|||
|
||||
/**
|
||||
* Post a review
|
||||
*
|
||||
*
|
||||
* @param reviewForm Form data
|
||||
* @param bindingResult Form binding result after validation
|
||||
* @param prettyUrlFragment Product context
|
||||
|
@ -69,10 +69,10 @@ public class ProductController {
|
|||
return TEMPLATE;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/products/{prettyUrlFragment:[\\w-]+}.json", method = RequestMethod.GET)
|
||||
@RequestMapping(value = "/products/{id}.json", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public ProductDTO productJson(@PathVariable String prettyUrlFragment, Locale locale) {
|
||||
return shopService.getProduct(locale, prettyUrlFragment);
|
||||
public ProductDTO productJson(@PathVariable Integer id, Locale locale) {
|
||||
return shopService.getProduct(locale, id);
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/products.json", method = RequestMethod.GET)
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
<h2 th:text="${product.name}">Product Name</h2>
|
||||
|
||||
<!-- 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="lead" th:text="${product.description}">Description.</p>
|
||||
|
@ -53,4 +53,4 @@
|
|||
<script src="../static/js/bootstrap.min.js"
|
||||
th:src="@{/js/bootstrap.min.js}"></script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
Reference in New Issue