genofire/hs_monolith
genofire
/
hs_monolith
Archived
1
0
Fork 0

[TASK] patch for microservice stock

This commit is contained in:
Martin Geno 2017-06-22 20:15:07 +02:00
parent ee4696d737
commit 0754b05118
No known key found for this signature in database
GPG Key ID: F0D39A37E925E941
7 changed files with 64 additions and 2 deletions

View File

@ -86,6 +86,8 @@ public class DataTransferObjectFactory {
ProductI18n i18n = product.getI18n().get(locale.getLanguage());
String price = numberFormat.format(i18n.getPrice());
ProductDTO productDTO = new ProductDTO();
// Addition: productDTO.setID()
productDTO.setId(product.getId());
productDTO.setItemNumber(product.getItemNumber());
productDTO.setUnit(product.getUnit());
productDTO.setName(i18n.getName());

View File

@ -1,5 +1,7 @@
package de.mstock.monolith.domain;
import java.util.List;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
@ -9,4 +11,7 @@ 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")
List<Product> findAll();
}

View File

@ -58,6 +58,19 @@ public class ShopService {
return Collections.unmodifiableList(products);
}
/**
* Gets all products in the current language.
*
* @return A simplified Data Transfer Object.
*/
public List<ProductDTO> getAllProducts(Locale locale) {
String language = locale.getLanguage();
List<Product> products = productRepository.findAll();
List<ProductDTO> productsDTO =
dtoFactory.createProductWithoutReviewsDTOs(products, locale);
return Collections.unmodifiableList(productsDTO);
}
/**
* Gets a product in the current language.
*

View File

@ -17,11 +17,24 @@ public class HomepageController {
@Autowired
private ShopService shopService;
// Addition: contant with the address of the stock microservice adminfrontend
private final String STOCKADMINFRONTENDTEMPLATE = "https://stock.pub.warehost.de/index.html";
/**
* Redirect to stock admin frontend
*
* @param model Template model
* @return The constant template name for the stock admin frontend.
*/
@RequestMapping(value = "/stockadmin", method = RequestMethod.GET)
public String redirect(Model model) {
return "redirect:" + this.STOCKADMINFRONTENDTEMPLATE;
}
/**
* Homepage
*
* @param model Template model
* @param model Template model
* @param locale Current locale
* @return The template's name.
*/

View File

@ -1,6 +1,7 @@
package de.mstock.monolith.web;
import java.util.Locale;
import java.util.List;
import javax.validation.Valid;
@ -11,6 +12,7 @@ import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import de.mstock.monolith.service.ReviewService;
import de.mstock.monolith.service.ShopService;
@ -66,4 +68,17 @@ public class ProductController {
model.addAttribute("product", shopService.getProduct(locale, prettyUrlFragment));
return TEMPLATE;
}
@RequestMapping(value = "/products/{prettyUrlFragment:[\\w-]+}.json", method = RequestMethod.GET)
@ResponseBody
public ProductDTO productJson(@PathVariable String prettyUrlFragment, Locale locale) {
return shopService.getProduct(locale, prettyUrlFragment);
}
@RequestMapping(value = "/products.json", method = RequestMethod.GET)
@ResponseBody
public List<ProductDTO> allProductJson(Locale locale) {
return shopService.getAllProducts(locale);
}
}

View File

@ -6,6 +6,7 @@ import de.mstock.monolith.domain.ProductWeightUnit;
public class ProductDTO {
private int id;
private String itemNumber;
private ProductWeightUnit unit;
private String name;
@ -14,6 +15,15 @@ public class ProductDTO {
private String description;
private List<ReviewDTO> reviews;
// Addition: int id, getId() and setID()
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getItemNumber() {
return itemNumber;
}

View File

@ -31,6 +31,10 @@
</div>
<div class="col-md-8">
<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}"/>
<p class="text-info text-uppercase" th:text="${product.price}">0,00 Euro</p>
<p class="lead" th:text="${product.description}">Description.</p>
<div th:replace="fragments/reviews :: reviews"></div>