fix update article

This commit is contained in:
Tim
2025-06-22 13:39:20 +02:00
parent 03a7ca4a92
commit d468f90772

View File

@@ -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")