diff --git a/src/main/java/gift/controller/OptionController.java b/src/main/java/gift/controller/OptionController.java index b0c3d87f1..20d995bc7 100644 --- a/src/main/java/gift/controller/OptionController.java +++ b/src/main/java/gift/controller/OptionController.java @@ -5,8 +5,10 @@ import gift.dto.option.OptionResponse; import gift.dto.option.OptionUpdateResponse; import gift.entity.Option; +import gift.exception.CustomException; import gift.service.OptionService; import jakarta.validation.Valid; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; @@ -47,8 +49,7 @@ public ResponseEntity addOptionToProduct( UriComponentsBuilder uriBuilder) { Option option = optionService.addOptionToProduct(productId, optionRequest); OptionResponse response = new OptionResponse(option.getId(), option.getName(), option.getQuantity()); - URI location = uriBuilder.path("/api/products/{productId}/options/{optionId}") - .buildAndExpand(productId, option.getId()).toUri(); + URI location = uriBuilder.path("/api/products/{productId}/options/{optionId}").buildAndExpand(productId, option.getId()).toUri(); return ResponseEntity.created(location).body(response); } @@ -72,8 +73,15 @@ public ResponseEntity deleteOption( @PathVariable Long optionId, @Parameter(description = "ID of the product", required = true) @RequestBody DeleteOptionRequest deleteOptionRequest) { - optionService.deleteOption(optionId, deleteOptionRequest.getEmail(), deleteOptionRequest.getPassword()); - return ResponseEntity.ok("Option successfully deleted."); + try { + optionService.deleteOption(optionId, DeleteOptionRequest.getEmail(), DeleteOptionRequest.getPassword()); + return ResponseEntity.ok("Option successfully deleted."); + } catch (CustomException.EntityNotFoundException e) { + return ResponseEntity.status(HttpStatus.NOT_FOUND).body(e.getMessage()); + } catch (CustomException.InvalidPasswordException e) { + return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(e.getMessage()); + } catch (Exception e) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("An error occurred: " + e.getMessage()); + } } } - diff --git a/src/main/java/gift/controller/ProductController.java b/src/main/java/gift/controller/ProductController.java index 9da276cd2..4bc60c27b 100644 --- a/src/main/java/gift/controller/ProductController.java +++ b/src/main/java/gift/controller/ProductController.java @@ -116,6 +116,7 @@ public ResponseEntity updateProduct( public ResponseEntity deleteProduct( @Parameter(description = "ID of the product to be deleted", required = true) @PathVariable Long id) { + productService.deleteById(id); try { productService.deleteById(id); return ResponseEntity.ok("성공적으로 삭제되었습니다."); diff --git a/src/main/java/gift/controller/WishController.java b/src/main/java/gift/controller/WishController.java index 534eedfe5..2ed0a12ef 100644 --- a/src/main/java/gift/controller/WishController.java +++ b/src/main/java/gift/controller/WishController.java @@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.*; import jakarta.servlet.http.HttpServletRequest; +import java.util.List; import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.Operation; diff --git a/src/main/java/gift/entity/Order.java b/src/main/java/gift/entity/Order.java index d14a10a8a..c9e64ae36 100644 --- a/src/main/java/gift/entity/Order.java +++ b/src/main/java/gift/entity/Order.java @@ -47,6 +47,10 @@ public String getEmail() { return email; } + public LocalDateTime getOrderTime() { + return orderDateTime; + } + public static class Builder { private Long id; private Long optionId; diff --git a/src/main/java/gift/entity/Product.java b/src/main/java/gift/entity/Product.java index 5af9831bc..3ef614b51 100644 --- a/src/main/java/gift/entity/Product.java +++ b/src/main/java/gift/entity/Product.java @@ -36,9 +36,6 @@ public class Product { @OneToMany(mappedBy = "product", cascade = CascadeType.ALL, orphanRemoval = true) private List