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")
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();

View File

@ -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.
*

View File

@ -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)

View File

@ -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>