From d468f907726058977124d8043e4cc7d35ba3611a Mon Sep 17 00:00:00 2001 From: Tim <47184194+imgde@users.noreply.github.com> Date: Sun, 22 Jun 2025 13:39:20 +0200 Subject: [PATCH] fix update article --- .../webshop/controller/ArticleController.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/00-backend/src/main/java/de/htwsaar/webshop/controller/ArticleController.java b/00-backend/src/main/java/de/htwsaar/webshop/controller/ArticleController.java index f751c7a..3cc99e1 100644 --- a/00-backend/src/main/java/de/htwsaar/webshop/controller/ArticleController.java +++ b/00-backend/src/main/java/de/htwsaar/webshop/controller/ArticleController.java @@ -13,9 +13,7 @@ import org.springframework.web.bind.annotation.*; import java.util.List; import java.util.UUID; -import static de.htwsaar.webshop.config.ControllerPathConfig.ARTICLE_BASE; -import static de.htwsaar.webshop.config.ControllerPathConfig.ARTICLE_GET_ALL; -import static de.htwsaar.webshop.config.ControllerPathConfig.ARTICLE_GET_ALL_WITH_IMAGE; +import static de.htwsaar.webshop.config.ControllerPathConfig.*; import static de.htwsaar.webshop.config.ParameterConfig.PARAM_UUID; import static de.htwsaar.webshop.util.LoggerUtil.logRequest; @@ -67,12 +65,19 @@ public class ArticleController { @RequestParam(value = PARAM_UUID) UUID uuid, @RequestBody Article article) { logRequest(request); - if (uuid == null || uuid.toString().isEmpty() || articleService.findByUUID(uuid) == null) { + if (uuid == null || uuid.toString().isEmpty()) { + log.warn("[{}] got null UUID", request.getRequestURI()); + return ResponseEntity.badRequest().body(false); + } + if (articleService.findByUUID(uuid) == null) { + log.warn("[{}] got invalid UUID {}", request.getRequestURI(), uuid); return ResponseEntity.badRequest().body(false); } article.setId(articleService.findByUUID(uuid).getId()); - - return ResponseEntity.ok(articleService.save(article) != null); + if (articleService.update(article) != null) { + return ResponseEntity.internalServerError().body(false); + } + return ResponseEntity.ok(true); } @RequestMapping(path = ARTICLE_BASE, method = RequestMethod.DELETE, produces = "application/json")