Skip to content
Snippets Groups Projects
Commit a177e649 authored by Pedro Pablo Cardona Arroyave's avatar Pedro Pablo Cardona Arroyave
Browse files

Merge branch '225-add-endpoint-to-fetch-products-by-keyword-name' into 'main'

Resolve "Add endpoint to fetch products by keyword name"

Closes #225

See merge request idatt2106-v23-03/backend!170
parents 707cef7b a69fda1a
No related branches found
No related tags found
No related merge requests found
......@@ -139,5 +139,19 @@ public class ProductController {
return ResponseEntity.notFound().build();
}
/**
*
* Retrieve a product by name using a GET request.
*
* @param name The name of the product to retrieve.
* @return A ResponseEntity containing the product if found, or a 404 Not Found response if not found.
*/
@GetMapping("name/{name}")
public ResponseEntity<Product> getProductByName(@PathVariable String name) {
return productService.getProductByName(name)
.map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
}
}
......@@ -186,14 +186,13 @@ public class FridgeService {
if(fridgeProductAsso.isEmpty()) return Optional.empty();
FridgeProductAsso fridgeProductAsso1 = fridgeProductAsso.get();
fridgeProductAssoRepo.delete(fridgeProductAsso1);
String unit = ProductUtil.getVolumeFromProduct(fridgeProductAsso1.getEan()).get().get(0);
Group group = fridgeProductAsso1.getFridgeId().getGroup();
if(group.getPoints() > 10.0){
group.setPoints(group.getPoints() - 1);
group.setLevel(GroupUtil.getLevel(group.getPoints()));
}
groupRepository.save(group);
return Optional.of(wasteRepository.save(Waste.builder().amount(fridgeProductAsso1.getAmount()).unit(unit).ean(fridgeProductAsso1.getEan()).groupId(fridgeProductAsso1.getFridgeId().getGroup()).timestamp(new Timestamp(System.currentTimeMillis())).build()));
return Optional.of(wasteRepository.save(Waste.builder().amount(fridgeProductAsso1.getAmount()).unit(fridgeProductAsso1.getEan().getUnit()).ean(fridgeProductAsso1.getEan()).groupId(fridgeProductAsso1.getFridgeId().getGroup()).timestamp(new Timestamp(System.currentTimeMillis())).build()));
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment