Skip to content

Commit 6aeef12

Browse files
committed
Store service and api decomposed.
1 parent 0da05c1 commit 6aeef12

File tree

6 files changed

+368
-223
lines changed

6 files changed

+368
-223
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
package com.siriusxi.ms.store.api.composite;
2+
3+
import com.siriusxi.ms.store.api.composite.dto.ProductAggregate;
4+
import io.swagger.annotations.Api;
5+
import io.swagger.annotations.ApiOperation;
6+
import io.swagger.annotations.ApiResponse;
7+
import io.swagger.annotations.ApiResponses;
8+
import org.springframework.web.bind.annotation.*;
9+
10+
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
11+
12+
/**
13+
* Interface <code>StoreEndpoint</code> is a higher level Interface
14+
* to define <strong>Store Service</strong> endpoint APIs that follow <code>StoreService</code>
15+
* interface. And to be implemented by service controllers.
16+
*
17+
*
18+
* @author mohamed.taman
19+
* @version v1.0
20+
* @since v3.0 codename Storm
21+
*/
22+
@Api("REST API for Springy Store products information.")
23+
@RequestMapping("store/api/v1")
24+
public interface StoreEndpoint extends StoreService {
25+
26+
/**
27+
* Sample usage:
28+
*
29+
* <p><code>curl $HOST:$PORT/store/api/v1/products/1</code></p>
30+
*
31+
* @param id is the product that you are looking for.
32+
* @return the composite product info, if found, else null.
33+
* @since v3.0 codename Storm.
34+
*/
35+
@ApiOperation(
36+
value = "${api.product-composite.get-composite-product.description}",
37+
notes = "${api.product-composite.get-composite-product.notes}")
38+
@ApiResponses(
39+
value = {
40+
@ApiResponse(
41+
code = 400,
42+
message = """
43+
Bad Request, invalid format of the request.
44+
See response message for more information.
45+
"""),
46+
@ApiResponse(code = 404, message = "Not found, the specified id does not exist."),
47+
@ApiResponse(
48+
code = 422,
49+
message = """
50+
Unprocessable entity, input parameters caused the processing to fails.
51+
See response message for more information.
52+
""")
53+
})
54+
@GetMapping(value = "products/{id}",
55+
produces = APPLICATION_JSON_VALUE)
56+
ProductAggregate getProduct(@PathVariable int id);
57+
58+
/**
59+
* Sample usage:
60+
*
61+
* <p><code>curl -X POST $HOST:$PORT/store/api/v1/products \
62+
* -H "Content-Type: application/json" --data \
63+
* '{"productId":123,"name":"product 123", "weight":123}'</code></p>
64+
*
65+
* @param body of composite product elements definition.
66+
* @since v3.0 codename Storm.
67+
*/
68+
@ApiOperation(
69+
value = "${api.product-composite.create-composite-product.description}",
70+
notes = "${api.product-composite.create-composite-product.notes}")
71+
@ApiResponses(
72+
value = {
73+
@ApiResponse(
74+
code = 400,
75+
message = """
76+
Bad Request, invalid format of the request.
77+
See response message for more information.
78+
"""),
79+
@ApiResponse(
80+
code = 422,
81+
message = """
82+
Unprocessable entity, input parameters caused the processing to fail.
83+
See response message for more information.
84+
""")
85+
})
86+
@PostMapping(
87+
value = "products",
88+
consumes = APPLICATION_JSON_VALUE)
89+
void createProduct(@RequestBody ProductAggregate body);
90+
91+
/**
92+
* Sample usage:
93+
*
94+
* <p><code>curl -X DELETE $HOST:$PORT/store/api/v1/products/1</code></p>
95+
*
96+
* @param id is the product id to delete it.
97+
* @since v3.0 codename Storm.
98+
*/
99+
@ApiOperation(
100+
value = "${api.product-composite.delete-composite-product.description}",
101+
notes = "${api.product-composite.delete-composite-product.notes}")
102+
@ApiResponses(
103+
value = {
104+
@ApiResponse(
105+
code = 400,
106+
message ="""
107+
Bad Request, invalid format of the request.
108+
See response message for more information.
109+
"""),
110+
@ApiResponse(
111+
code = 422,
112+
message ="""
113+
Unprocessable entity, input parameters caused the processing to fail.
114+
See response message for more information.
115+
""")
116+
})
117+
@DeleteMapping("products/{id}")
118+
void deleteProduct(@PathVariable int id);
119+
}
Lines changed: 38 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,104 +1,47 @@
11
package com.siriusxi.ms.store.api.composite;
22

33
import com.siriusxi.ms.store.api.composite.dto.ProductAggregate;
4-
import io.swagger.annotations.Api;
5-
import io.swagger.annotations.ApiOperation;
6-
import io.swagger.annotations.ApiResponse;
7-
import io.swagger.annotations.ApiResponses;
8-
import org.springframework.web.bind.annotation.*;
94

10-
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
11-
12-
@Api("REST API for Springy Store products information.")
13-
@RequestMapping("store/api/v1")
5+
/**
6+
* Interface that define the general service contract (methods) for the Store
7+
* <ol>
8+
* <li>Service and,</li>
9+
* <li>Controller interfaces.</li>
10+
* </ol>
11+
*
12+
* @author mohamed.taman
13+
* @version v0.2
14+
* @since v0.1
15+
*/
1416
public interface StoreService {
1517

16-
/**
17-
* Sample usage: curl $HOST:$PORT/store/api/v1/products/1
18-
*
19-
* @param productId is the product that you are looking for.
20-
* @return the product info, if found, else null.
21-
*/
22-
@ApiOperation(
23-
value = "${api.product-composite.get-composite-product.description}",
24-
notes = "${api.product-composite.get-composite-product.notes}")
25-
@ApiResponses(
26-
value = {
27-
@ApiResponse(
28-
code = 400,
29-
message = """
30-
Bad Request, invalid format of the request.
31-
See response message for more information.
32-
"""),
33-
@ApiResponse(code = 404, message = "Not found, the specified id does not exist."),
34-
@ApiResponse(
35-
code = 422,
36-
message = """
37-
Unprocessable entity, input parameters caused the processing to fails.
38-
See response message for more information.
39-
""")
40-
})
41-
@GetMapping(value = "products/{productId}",
42-
produces = APPLICATION_JSON_VALUE)
43-
ProductAggregate getProduct(@PathVariable int productId);
18+
/**
19+
* Add composite product to the product, review, and recommendation repositories.
20+
*
21+
* @see ProductAggregate
22+
* @param body product to save.
23+
* @since v0.1
24+
*/
25+
void createProduct(ProductAggregate body);
4426

45-
/**
46-
* Sample usage:
47-
*
48-
* <p>curl -X POST $HOST:$PORT/store/api/v1/products \
49-
* -H "Content-Type: application/json" --data \
50-
* '{"productId":123,"name":"product 123", "weight":123}'
51-
*
52-
* @param body of product elements definition.
53-
*/
54-
@ApiOperation(
55-
value = "${api.product-composite.create-composite-product.description}",
56-
notes = "${api.product-composite.create-composite-product.notes}")
57-
@ApiResponses(
58-
value = {
59-
@ApiResponse(
60-
code = 400,
61-
message = """
62-
Bad Request, invalid format of the request.
63-
See response message for more information.
64-
"""),
65-
@ApiResponse(
66-
code = 422,
67-
message = """
68-
Unprocessable entity, input parameters caused the processing to fail.
69-
See response message for more information.
70-
""")
71-
})
72-
@PostMapping(
73-
value = "products",
74-
consumes = APPLICATION_JSON_VALUE)
75-
void createProduct(@RequestBody ProductAggregate body);
27+
/**
28+
* Get the aggregate product with its reviews and recommendations and services involved in
29+
* the call.
30+
*
31+
* @see ProductAggregate
32+
* @param id is the product id that you are looking for.
33+
* @return the product, if found, else null.
34+
* @since v0.1
35+
*/
36+
ProductAggregate getProduct(int id);
7637

77-
/**
78-
* Sample usage:
79-
*
80-
* <p>curl -X DELETE $HOST:$PORT/store/api/v1/products/1
81-
*
82-
* @param productId to delete.
83-
*/
84-
@ApiOperation(
85-
value = "${api.product-composite.delete-composite-product.description}",
86-
notes = "${api.product-composite.delete-composite-product.notes}")
87-
@ApiResponses(
88-
value = {
89-
@ApiResponse(
90-
code = 400,
91-
message ="""
92-
Bad Request, invalid format of the request.
93-
See response message for more information.
94-
"""),
95-
@ApiResponse(
96-
code = 422,
97-
message ="""
98-
Unprocessable entity, input parameters caused the processing to fail.
99-
See response message for more information.
100-
""")
101-
})
102-
@DeleteMapping("products/{productId}")
103-
void deleteProduct(@PathVariable int productId);
38+
/**
39+
* Delete the product and all its relate reviews and recommendations from their repositories.
40+
*
41+
* @see ProductAggregate
42+
* @implNote This method should be idempotent and always return 200 OK status.
43+
* @param id to be deleted.
44+
* @since v0.1
45+
*/
46+
void deleteProduct(int id);
10447
}

store-api/src/main/java/com/siriusxi/ms/store/api/core/product/ProductEndpoint.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* to define <strong>Product Service</strong> endpoint APIs that follow <code>ProductService</code>
1212
* interface. And to be implemented by service controllers.
1313
*
14-
* @see com.siriusxi.ms.store.api.core.product.ProductService
14+
* @see ProductService
1515
*
1616
* @author mohamed.taman
1717
* @version v1.0
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.siriusxi.ms.store.pcs.api;
2+
3+
import com.siriusxi.ms.store.api.composite.StoreEndpoint;
4+
import com.siriusxi.ms.store.api.composite.StoreService;
5+
import com.siriusxi.ms.store.api.composite.dto.ProductAggregate;
6+
import lombok.extern.log4j.Log4j2;
7+
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.beans.factory.annotation.Qualifier;
9+
import org.springframework.web.bind.annotation.RestController;
10+
11+
@RestController
12+
@Log4j2
13+
public class StoreController implements StoreEndpoint {
14+
/** Store service business logic interface. */
15+
private final StoreService storeService;
16+
17+
@Autowired
18+
public StoreController(@Qualifier("StoreServiceImpl") StoreService storeService) {
19+
this.storeService = storeService;
20+
}
21+
22+
/**
23+
* {@inheritDoc}
24+
*/
25+
@Override
26+
public ProductAggregate getProduct(int id) {
27+
return storeService.getProduct(id);
28+
}
29+
30+
/**
31+
* {@inheritDoc}
32+
*/
33+
@Override
34+
public void createProduct(ProductAggregate body) {
35+
storeService.createProduct(body);
36+
}
37+
38+
/**
39+
* {@inheritDoc}
40+
*/
41+
@Override
42+
public void deleteProduct(int id) {
43+
storeService.deleteProduct(id);
44+
}
45+
}

0 commit comments

Comments
 (0)