David Bylund - #102
Open
ReRaulReb wants to merge 3 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a new in-memory “products” API layer (controller/service/repository + model/DTO) alongside the existing Spring Boot application entrypoint.
Changes:
- Adds
ProductControllerREST endpoints for CRUD operations under/products. - Implements
ProductServiceandProductRepositoryto manage products in-memory. - Introduces
ProductandProductCreateDtoto model product data and request payloads.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/main/java/com/booleanuk/api/product/controller/ProductController.java | Adds REST endpoints for product CRUD operations. |
| src/main/java/com/booleanuk/api/product/service/ProductService.java | Adds service-level validation and ResponseEntity-based responses. |
| src/main/java/com/booleanuk/api/product/repo/ProductRepository.java | Implements in-memory persistence and CRUD operations for products. |
| src/main/java/com/booleanuk/api/product/model/Product.java | Defines the Product entity and ID generation strategy. |
| src/main/java/com/booleanuk/api/product/model/ProductCreateDto.java | Defines request DTO for create/update operations. |
| src/main/java/com/booleanuk/api/Main.java | Adds Spring Boot application entry point. |
Suppressed comments (1)
src/main/java/com/booleanuk/api/product/repo/ProductRepository.java:56
deleteOneiterates usingProduct.getCurrentId() - 1instead of the current list size, which can skip existing products and can throwIndexOutOfBoundsExceptionwhen IDs are higher than the list size (e.g., after deletions).
for (int i = 0; i < Product.getCurrentId()-1; i++){
Product p = this.products.get(i);
if(p.getId() == id){
Product removed = this.products.remove(i);
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+28
to
+33
| if(price < 0) | ||
| return ResponseEntity.unprocessableEntity().body(null); | ||
| else if(name.isBlank() || category.isBlank()) | ||
| return ResponseEntity.unprocessableEntity().body(null); | ||
| else if(this.productRepo.isProduct(name)) | ||
| return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null); |
Comment on lines
+40
to
+48
| for (int i = 0; i < Product.getCurrentId()-1; i++){ | ||
| Product p = this.products.get(i); | ||
| if(p.getId() == id){ | ||
| p.setName(name); | ||
| p.setCategory(category); | ||
| p.setPrice(price); | ||
| return Optional.of(this.products.set(i, p)); | ||
| } | ||
| } |
Comment on lines
+11
to
+15
| public ProductCreateDto(String name, String category, int price){ | ||
| setName(name); | ||
| setCategory(category); | ||
| setPrice(price); | ||
| } |
Comment on lines
+49
to
+54
| if(price < 0) | ||
| return ResponseEntity.unprocessableEntity().body(null); | ||
| else if(name.isBlank() || category.isBlank()) | ||
| return ResponseEntity.unprocessableEntity().body(null); | ||
| else if(this.productRepo.isProduct(name)) | ||
| return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null); |
Comment on lines
+47
to
+50
| public ResponseEntity<Product> putProduct(@PathVariable int id, @RequestBody ProductCreateDto productDto){ | ||
| ResponseEntity<Product> res = this.productService.putProduct(id, productDto.getName(), productDto.getCategory(), productDto.getPrice()); | ||
| return res; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.