[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();
|
||||
|
||||
|
|
|
@ -71,6 +71,19 @@ public class ShopService {
|
|||
return Collections.unmodifiableList(productsDTO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
|
|
@ -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>
|
||||
|
|
Reference in New Issue