diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml
new file mode 100644
index 0000000..e05b8fd
--- /dev/null
+++ b/.idea/dataSources.xml
@@ -0,0 +1,11 @@
+
+
+
+
+ postgresql
+ true
+ org.postgresql.Driver
+ jdbc:postgresql://ec2-54-75-230-41.eu-west-1.compute.amazonaws.com:5432/d3e1jrm08qe91q?ssl=true&sslmode=require&=org.postgresql.ssl.NonValidatingFactory
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index b9a1078..5a575d6 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -1,20 +1,13 @@
-
-
-
-
-
+
+
-
-
-
-
-
+
@@ -35,85 +28,113 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -299,13 +321,14 @@
-
+
+
@@ -379,16 +402,23 @@
1547322958782
-
+
+
+ 1548121370553
+
+
+
+ 1548121370553
+
+
-
+
-
@@ -396,9 +426,10 @@
+
-
+
@@ -406,7 +437,7 @@
-
+
@@ -417,7 +448,7 @@
-
+
@@ -470,6 +501,11 @@
+
+
+
+
+
@@ -486,13 +522,6 @@
-
-
-
-
-
-
-
@@ -551,16 +580,6 @@
-
-
-
-
-
-
-
-
-
-
@@ -571,41 +590,12 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
+
@@ -619,6 +609,67 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/java/com/dino/scrum/sysmag/controller/ProductController.java b/src/main/java/com/dino/scrum/sysmag/controller/ProductController.java
index 84c6361..d9ca6a7 100644
--- a/src/main/java/com/dino/scrum/sysmag/controller/ProductController.java
+++ b/src/main/java/com/dino/scrum/sysmag/controller/ProductController.java
@@ -4,10 +4,12 @@ import com.dino.scrum.sysmag.model.Product;
import com.dino.scrum.sysmag.model.dto.IdDto;
import com.dino.scrum.sysmag.model.dto.QuantityChange;
import com.dino.scrum.sysmag.service.ProductServiceImpl;
+import com.dino.scrum.sysmag.validationGroup.UpdateGroup;
import com.dino.scrum.sysmag.validator.QuantityChangeValidator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
+import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException;
@@ -75,6 +77,15 @@ public class ProductController {
}
}
+ @PostMapping(value = "/product/update/{id}")
+ public Product update(@Validated(UpdateGroup.class) @RequestBody Product product, @PathVariable("id") long id) {
+ try {
+ return productService.update(product, id);
+ } catch (Exception e) {
+ throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.toString());
+ }
+ }
+
@PostMapping(value = "/product/change-quantity")
public
Product changeQuantity(@RequestBody QuantityChange quantityChange){
diff --git a/src/main/java/com/dino/scrum/sysmag/service/ProductService.java b/src/main/java/com/dino/scrum/sysmag/service/ProductService.java
index 77434e9..54824e0 100644
--- a/src/main/java/com/dino/scrum/sysmag/service/ProductService.java
+++ b/src/main/java/com/dino/scrum/sysmag/service/ProductService.java
@@ -18,6 +18,8 @@ public interface ProductService {
Product add(Product product) throws Exception;
+ Product update(Product product, long id) throws Exception;
+
float getPriceOfAll();
void delete(long id) throws Exception;
diff --git a/src/main/java/com/dino/scrum/sysmag/service/ProductServiceImpl.java b/src/main/java/com/dino/scrum/sysmag/service/ProductServiceImpl.java
index f1569ad..42df07a 100644
--- a/src/main/java/com/dino/scrum/sysmag/service/ProductServiceImpl.java
+++ b/src/main/java/com/dino/scrum/sysmag/service/ProductServiceImpl.java
@@ -54,7 +54,7 @@ public class ProductServiceImpl implements ProductService {
@Override
public float getPriceOfAll() {
- BigDecimal result = new BigDecimal(0);
+ BigDecimal result = new BigDecimal(0);
Iterable tempProductList = productRepository.findAll();
for (Product product : tempProductList) {
@@ -71,6 +71,32 @@ public class ProductServiceImpl implements ProductService {
return productRepository.save(product);
}
+ @Override
+ public Product update(Product productReceived, long id) throws Exception {
+ productValidator.checkIfExists(productReceived.getId());
+
+ Product productToChange = productRepository.findById(id);
+
+ if (productReceived.getName() != null)
+ productToChange.setName(productReceived.getName());
+
+ if (productReceived.getName() != null)
+ productToChange.setPrice(productReceived.getPrice());
+
+ if (productReceived.getName() != null)
+ productToChange.setQuantity(productReceived.getQuantity());
+
+ if (productReceived.getName() != null)
+ productToChange.setQuantityMax(productReceived.getQuantityMax());
+
+ if (productReceived.getName() != null)
+ productToChange.setImageLink(productReceived.getImageLink());
+
+ productRepository.save(productToChange);
+
+ return productRepository.findById(productToChange.getId().longValue());
+ }
+
@Override
public void delete(long id) throws Exception {
productValidator.checkIfExists(id);
diff --git a/src/main/java/com/dino/scrum/sysmag/validationGroup/UpdateGroup.java b/src/main/java/com/dino/scrum/sysmag/validationGroup/UpdateGroup.java
new file mode 100644
index 0000000..5f8f3a5
--- /dev/null
+++ b/src/main/java/com/dino/scrum/sysmag/validationGroup/UpdateGroup.java
@@ -0,0 +1,8 @@
+package com.dino.scrum.sysmag.validationGroup;
+
+/**
+ * Created by prgres on 2019-01-22.
+ */
+
+public interface UpdateGroup {
+}
diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties
index 008d38f..ea762f5 100644
--- a/src/main/resources/application.properties
+++ b/src/main/resources/application.properties
@@ -7,7 +7,7 @@ spring.datasource.driverClassName=org.postgresql.Driver
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL94Dialect
spring.jpa.generate-ddl=true
spring.jpa.show-sql=false
-spring.jpa.hibernate.ddl-auto=validate
+spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
diff --git a/target/classes/application.properties b/target/classes/application.properties
index 5da0c2b..ea762f5 100644
--- a/target/classes/application.properties
+++ b/target/classes/application.properties
@@ -1,10 +1,16 @@
-# H2
-spring.h2.console.enabled=true
-spring.h2.console.path=/h2
-spring.jpa.hibernate.ddl-auto=create
+# Details for our datasource heroku
+spring.datasource.url=jdbc:postgresql://ec2-54-75-230-41.eu-west-1.compute.amazonaws.com/d3e1jrm08qe91q?ssl=true&sslmode=require&sslfactory=org.postgresql.ssl.NonValidatingFactory
+spring.datasource.username=eecsegponwphcn
+spring.datasource.password=4045a1e5a2de22362149709c3a2a1d5eb6e243cd553fd1a15f76fc54923638ce
+spring.datasource.driverClassName=org.postgresql.Driver
+# Hibernate properties
+spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL94Dialect
spring.jpa.generate-ddl=true
-# Datasource
-spring.datasource.url=jdbc:h2:file:~/sysmag
-spring.datasource.username=sa
-spring.datasource.password=
-spring.datasource.driver-class-name=org.h2.Driver
\ No newline at end of file
+spring.jpa.show-sql=false
+spring.jpa.hibernate.ddl-auto=update
+spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl
+spring.jpa.properties.hibernate.format_sql=true
+spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
+spring.jackson.serialization.FAIL_ON_EMPTY_BEANS=false
+#spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults=false
+