Skip to content

Commit f49a076

Browse files
Merge pull request #78 from AnswerConsulting/BENCH-162
BENCH-162 UPDATED STATUS CODES TO ALIGN WITH OPEN API
2 parents a803a43 + a519f0e commit f49a076

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

src/main/java/com/answerdigital/answerking/controller/CategoryController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public CategoryController(final CategoryService categoryService) {
4545
public ResponseEntity<Category> addCategory(@Valid @RequestBody final AddCategoryRequest categoryRequest,
4646
final Errors errors) {
4747
return new ResponseEntity<>(categoryService.addCategory(categoryRequest),
48-
errors.hasErrors() ? HttpStatus.BAD_REQUEST : HttpStatus.OK);
48+
errors.hasErrors() ? HttpStatus.BAD_REQUEST : HttpStatus.CREATED);
4949
}
5050

5151
@Operation(summary = "Get all categories.")

src/main/java/com/answerdigital/answerking/controller/ProductController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public ResponseEntity<Product> getProductById(@Valid @PathVariable @NotNull fina
4848
@PostMapping
4949
public ResponseEntity<Product> addProduct(@Valid @RequestBody final ProductRequest productRequest, final Errors errors) {
5050
return new ResponseEntity<>(productService.addNewProduct(productRequest),
51-
errors.hasErrors() ? HttpStatus.BAD_REQUEST : HttpStatus.OK);
51+
errors.hasErrors() ? HttpStatus.BAD_REQUEST : HttpStatus.CREATED);
5252
}
5353

5454
@PutMapping("/{id}")

src/test/java/com/answerdigital/answerking/controller/CategoryControllerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void addCategoryTest() throws Exception {
6868
final var response = mvc.perform(post("/categories")
6969
.content(categoryRequest)
7070
.contentType(MediaType.APPLICATION_JSON))
71-
.andExpect(status().isOk())
71+
.andExpect(status().isCreated())
7272
.andReturn()
7373
.getResponse();
7474
final var resultJsonNode = mapper.readTree(response.getContentAsString());

src/test/java/com/answerdigital/answerking/controller/ProductControllerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ void addProductWithValidObjectReturnsProductAndOkStatus() throws Exception {
136136
.content(newProduct)
137137
.contentType(MediaType.APPLICATION_JSON));
138138
//then
139-
actualPerformResult.andExpect(status().isOk());
139+
actualPerformResult.andExpect(status().isCreated());
140140
ObjectMapper mapper = new ObjectMapper();
141141
assertEquals(mapper.readTree(newProduct).get("name"), mapper.readTree(actualPerformResult.andReturn()
142142
.getResponse().getContentAsString()).get("name"));

0 commit comments

Comments
 (0)