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; ...@@ -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.CategoryService;
import ntnu.idatt2016.v233.SmartMat.service.product.ProductService; import ntnu.idatt2016.v233.SmartMat.service.product.ProductService;
import ntnu.idatt2016.v233.SmartMat.util.CategoryUtil; import ntnu.idatt2016.v233.SmartMat.util.CategoryUtil;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -110,13 +111,13 @@ public class ProductController { ...@@ -110,13 +111,13 @@ public class ProductController {
* @return The product that was deleted. * @return The product that was deleted.
*/ */
@DeleteMapping("ean/{ean}") @DeleteMapping("ean/{ean}")
public ResponseEntity<Product> deleteProduct(@PathVariable long ean) { public ResponseEntity<String> deleteProduct(@PathVariable long ean) {
Optional<Product> product = productService.getProductById(ean); Optional<Product> product = productService.getProductById(ean);
if(product.isPresent()) { if(product.isPresent()) {
productService.deleteProductById(product.get().getEan()); 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{ ...@@ -53,7 +53,7 @@ public class Product{
@ManyToOne(cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH}, @ManyToOne(cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH},
fetch = FetchType.LAZY) fetch = FetchType.LAZY)
@JoinColumn(name = "category_name") @JoinColumn(name = "category_name")
@JsonIgnore @JsonIncludeProperties("categoryName")
Category category; Category category;
@Column(name = "image_url") @Column(name = "image_url")
...@@ -73,8 +73,7 @@ public class Product{ ...@@ -73,8 +73,7 @@ public class Product{
@ManyToMany(cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH}, @ManyToMany(cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH},
fetch = FetchType.LAZY, mappedBy = "products") fetch = FetchType.LAZY, mappedBy = "products")
@JsonIgnoreProperties({"products", "users"}) @JsonIncludeProperties("name")
@JsonIgnore
List<Allergy> allergies; List<Allergy> allergies;
@OneToMany(cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH}, @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