Search in sources :

Example 1 with ProductEntity

use of com.zavada.entity.ProductEntity in project Logos_Materials_October_2017 by VolodymyrZavada.

the class SpringBootConsultationProjectApplication method addProducts.

static void addProducts(ConfigurableApplicationContext context) {
    ProductRepository productRepository = context.getBean(ProductRepository.class);
    ProductEntity product = productRepository.findOne(1);
    if (product == null) {
        productRepository.save(getProducts());
    }
}
Also used : ProductRepository(com.zavada.repository.ProductRepository) ProductEntity(com.zavada.entity.ProductEntity)

Example 2 with ProductEntity

use of com.zavada.entity.ProductEntity in project Logos_Materials_October_2017 by VolodymyrZavada.

the class RestController method buy.

@GetMapping("/buy")
public ResponseEntity<?> buy(@RequestParam("productid") String prodIdStr) {
    int productId = Integer.valueOf(prodIdStr);
    ProductEntity entity = productService.findProductById(productId);
    entity.setInStock(entity.getInStock() - 1);
    productService.saveOrUpdate(entity);
    return new ResponseEntity<>(HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ProductEntity(com.zavada.entity.ProductEntity) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 3 with ProductEntity

use of com.zavada.entity.ProductEntity in project Logos_Materials_October_2017 by VolodymyrZavada.

the class SpringBootConsultationProjectApplication method getProducts.

private static List<ProductEntity> getProducts() {
    List<ProductEntity> productEntities = new ArrayList<>();
    productEntities.add(new ProductEntity("MacBook Pro (15 inch)", 2999, 50, "Apple"));
    productEntities.add(new ProductEntity("Samsung Galaxy Note 7", 899, 199, "Samsung"));
    productEntities.add(new ProductEntity("HP Officejet 5740", 899, 12, "HP"));
    productEntities.add(new ProductEntity("iPhone X", 999, 3, "Apple"));
    productEntities.add(new ProductEntity("iPad Pro (9.7 inch)", 699, 30, "Apple"));
    productEntities.add(new ProductEntity("OnePlus 3 cover", 449, 0, "OnePlus"));
    return productEntities;
}
Also used : ArrayList(java.util.ArrayList) ProductEntity(com.zavada.entity.ProductEntity)

Aggregations

ProductEntity (com.zavada.entity.ProductEntity)3 ProductRepository (com.zavada.repository.ProductRepository)1 ArrayList (java.util.ArrayList)1 ResponseEntity (org.springframework.http.ResponseEntity)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1