diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 43d779a..fb65724 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -5,6 +5,7 @@
+
@@ -82,8 +83,8 @@
-
-
+
+
@@ -91,7 +92,7 @@
-
+
@@ -103,8 +104,8 @@
-
-
+
+
@@ -112,20 +113,11 @@
-
-
-
-
-
-
-
-
-
-
-
+
+
@@ -133,36 +125,30 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -198,16 +184,16 @@
-
-
-
-
+
+
+
+
@@ -405,7 +391,7 @@
1547322958782
-
+
1548121370553
@@ -456,11 +442,25 @@
1548128323215
-
+
+ 1548176403757
+
+
+
+ 1548176403757
+
+
+ 1548177602799
+
+
+
+ 1548177602799
+
+
-
+
@@ -489,7 +489,7 @@
-
+
@@ -497,7 +497,7 @@
-
+
@@ -562,7 +562,9 @@
-
+
+
+
@@ -633,35 +635,9 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -682,13 +658,6 @@
-
-
-
-
-
-
-
@@ -710,10 +679,34 @@
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -722,8 +715,8 @@
-
-
+
+
@@ -732,8 +725,18 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
@@ -743,20 +746,13 @@
-
-
+
+
-
-
-
-
-
-
-
diff --git a/README.md b/README.md
index 90c335c..2f79a0b 100644
--- a/README.md
+++ b/README.md
@@ -1,19 +1,54 @@
# DINO\_SCRUM
-DINO\_SCRUM
+## MODEL
-## API Endpoints
+###Product
+```json5
+{
+ "id": Int,
+ "name": String,
+ "price": Float,
+ "quantity": Int,
+ "quantityMax": Int,
+ "imageLink": String
+}
+```
+``id`` - id of product,
-*POST* **/api/product/change-quantity**
+``name`` - name of product with minimal length 2;
+
+``price`` price of product, cannot be under 0.00;
+
+``quantity``: quantity of product in database, cannot be under 0;
+
+``quantityMax``: maximum quantity of product in database, cannot be under 0;
+
+``imageLink``: link to image of product
+
+Any of these couldn't be ``null``
+
+## API
+
+###Edit quantity of the product.
+
+The service will handle `POST` requests for `/api/product/change-quantity`, by changing quantity of product in database.
+
+``id`` - product's to change `id`
+
+``change`` - value of change (positive value for increase quantity, negative valude for decrease).
+
```json
+POST /api/product/change-quantity
+Content-Type: application/json
+
{
"id": Int,
"change": Int
}
```
-Return:
+Response `HttpStatus.OK` with ``JSON``:
```json
{
@@ -26,27 +61,20 @@ Return:
}
```
-Edit quantity and return the product.
* * *
-*GET* **/api/get-all**
+###Retrieve a paginated list of products
+
+The service will handle `GET` requests for `/api/get-all`, by retreving a paginated list of products. Optionally with a `page`, `size` **or** `page`, `size` and`sort` parameters in the query string.
+Page start numbering on `page=0`. Default list is sorted by `id`.
-Return all products sorted by id.
-*GET* **/api/get-all?page=X&size=Y**
-
-Return page *X* with size *Y* of all products sorted by id.
-
-*GET* **/api/get-all?page=X&size=Y&sorted=Z**
-
-Return page *X* with size *Y* of all products sorted by *Z* field.
-
-*GET* **/api/get-all?sorted=Z**
-
-Return all products sorted by *Z*.
-
-Return:
+```json
+GET /api/get-all?page=0&size=1&sort=id
+Content-Type: application/json
+```
+Response with ``HttpStatus.OK`` with ``JSON`` :
```json
{
@@ -57,8 +85,8 @@ Return:
"price": Float,
"quantity": Int,
"quantityMax": Int,
- "imageLink": String
- }
+ "imageLink": string
+ },
{
(...)
}
@@ -92,10 +120,14 @@ Return:
```
* * *
+###Get price of all products.
+The service will handle `GET` request on `/api/get-price-of-all` returing `Float` price of all products in the database.
-*GET* **/api/get-price-of-all**
-
-Return:
+```json
+GET /api/get-price-of-all
+Content-Type: application/json
+```
+Response ``Http.Status.OK`` with ``JSON``:
```json
{
@@ -103,13 +135,28 @@ Return:
}
```
-Return price of all products.
* * *
-
-*POST* **/api/product/add**
+###Create a new product.
+The service will handle `POST` request `/api/product/add`, by adding `Product` to database.
```json
+POST /api/product/add
+Content-Type: application/json
+
+{
+ "id": Int,
+ "name": String,
+ "price": Float,
+ "quantity": Int,
+ "quantityMax": Int,
+ "imageLink": String
+}
+```
+Response `HttpStatus.CREATED` with `JSON`
+
+```json
+
{
"id": Int,
"name": String,
@@ -120,46 +167,62 @@ Return price of all products.
}
```
-Return:
+* * *
+###Delete product with `id`.
+The service will handle `DELETE` request `/api/delete-product`, by
```json
+DELETE /api/delete-product
+Content-Type: application/json
+
{
- "id": Int,
- "name": String,
- "price": Float,
- "quantity": Int,
- "quantityMax": Int,
- "imageLink": String
+ "id": Int
}
+
```
+```json
-Create and return a new product.
+Response: HttpStatus.OK
+```
* * *
-*DELETE* **/api/delete-product**
+###Get product with `id`
+The service wil handle `GET` request `/api/product/get-by-id`, by returning product with `id`.
```json
+GET /api/product/get-by-id
+Content-Type: application/json
+
{
"id": Int
}
```
-Delete product with id.
+Response ``Http.Status.OK`` with `JSON`:
+
+```json
+{
+ "id": Int,
+ "name": String,
+ "price": Float,
+ "quantity": Int,
+ "quantityMax": Int,
+ "imageLink": String
+}
+```
* * *
-*GET* **/api/product/get-by-id**
+###Update product
+The service will handle ``POST`` request `/api/product/update/{id}` with path variable `id`, by updating existing product. In request
+`id` is required, fields which won't be modified should be `null`.
+
```json
-{
- "id": Int
-}
-```
+POST /api/product/update/{id}
+Content-Type: application/json
-Return:
-
-```json
{
"id": Int,
"name": String,
@@ -170,13 +233,7 @@ Return:
}
```
-Return product with id.
-
-* * *
-
-*POST* /api/product/update/{id}
-
-Id is require, other field could be null.
+Response ``Http.Status.OK`` with `JSON`:
```json
{
@@ -187,19 +244,4 @@ Id is require, other field could be null.
"quantityMax": Int,
"imageLink": String
}
-```
-
-Return:
-
-```json
-{
- "id": Int,
- "name": String,
- "price": Float,
- "quantity": Int,
- "quantityMax": Int,
- "imageLink": String
-}
-```
-
-Return updated product.
\ No newline at end of file
+```
\ No newline at end of file
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 378653e..20a592e 100644
--- a/src/main/java/com/dino/scrum/sysmag/controller/ProductController.java
+++ b/src/main/java/com/dino/scrum/sysmag/controller/ProductController.java
@@ -48,9 +48,10 @@ public class ProductController {
}
@PostMapping(value = "/product/add")
- public Product addProduct(@Valid @RequestBody Product product) {
+ public ResponseEntity addProduct(@Valid @RequestBody Product product) {
try {
- return productService.add(product);
+ productService.add(product);
+ return new ResponseEntity(product, HttpStatus.CREATED);
} catch (Exception e) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.toString());
}
@@ -60,7 +61,6 @@ public class ProductController {
public ResponseEntity deleteProduct(@RequestBody IdDto id) {
try {
productService.delete(id.getId());
-// return "Deleted" + id;
return new ResponseEntity("Deleted" + id, HttpStatus.OK);
} catch (Exception e) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.toString());
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 906b643..354a4d8 100644
--- a/src/main/java/com/dino/scrum/sysmag/service/ProductServiceImpl.java
+++ b/src/main/java/com/dino/scrum/sysmag/service/ProductServiceImpl.java
@@ -43,11 +43,12 @@ public class ProductServiceImpl implements ProductService {
@Override
public Product changeQuantity(QuantityChange quantityChange) throws Exception {
productValidator.checkIfExists(quantityChange.getId());
- System.out.println("id: " + quantityChange.getId() + " change: " + quantityChange.getChange());
- Product product = productRepository.findById(quantityChange.getId());
- product.setChangeQuantity(quantityChange.getChange());
- productRepository.save(product);
+ productRepository.save(
+ productRepository.findById(quantityChange.getId())
+ .setChangeQuantity(quantityChange.getChange())
+ );
+
return productRepository.findById(quantityChange.getId());
}