Skip to content
Snippets Groups Projects
Commit 156d79a7 authored by Birk Øvstetun Narvhus's avatar Birk Øvstetun Narvhus
Browse files

Merge branch 'bugfix/251-fix-retrival-of-allergies-when-getting-products' into 'main'

Resolve "fix retrival of allergies  when getting products"

Closes #251

See merge request idatt2106-v23-03/backend!193
parents 89503d4f 0c65187a
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,7 @@ import ntnu.idatt2016.v233.SmartMat.service.AllergyService;
import ntnu.idatt2016.v233.SmartMat.service.product.CategoryService;
import ntnu.idatt2016.v233.SmartMat.service.product.ProductService;
import ntnu.idatt2016.v233.SmartMat.util.CategoryUtil;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
......@@ -110,13 +111,13 @@ public class ProductController {
* @return The product that was deleted.
*/
@DeleteMapping("ean/{ean}")
public ResponseEntity<Product> deleteProduct(@PathVariable long ean) {
public ResponseEntity<String> deleteProduct(@PathVariable long ean) {
Optional<Product> product = productService.getProductById(ean);
if(product.isPresent()) {
productService.deleteProductById(product.get().getEan());
return ResponseEntity.ok(product.get());
return ResponseEntity.ok("Product deleted");
}
return ResponseEntity.notFound().build();
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Product not found");
}
......
......@@ -53,7 +53,7 @@ public class Product{
@ManyToOne(cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH},
fetch = FetchType.LAZY)
@JoinColumn(name = "category_name")
@JsonIgnore
@JsonIncludeProperties("categoryName")
Category category;
@Column(name = "image_url")
......@@ -73,8 +73,7 @@ public class Product{
@ManyToMany(cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH},
fetch = FetchType.LAZY, mappedBy = "products")
@JsonIgnoreProperties({"products", "users"})
@JsonIgnore
@JsonIncludeProperties("name")
List<Allergy> allergies;
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH},
......
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