Skip to content

David Bylund - #102

Open
ReRaulReb wants to merge 3 commits into
boolean-uk:mainfrom
ReRaulReb:main
Open

David Bylund#102
ReRaulReb wants to merge 3 commits into
boolean-uk:mainfrom
ReRaulReb:main

Conversation

@ReRaulReb

Copy link
Copy Markdown

No description provided.

Copilot AI lite review requested due to automatic review settings August 31, 2026 11:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ProductController REST endpoints for CRUD operations under /products.
  • Implements ProductService and ProductRepository to manage products in-memory.
  • Introduces Product and ProductCreateDto to 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

  • deleteOne iterates using Product.getCurrentId() - 1 instead of the current list size, which can skip existing products and can throw IndexOutOfBoundsException when 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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants