diff --git a/src/main/java/com/app/bookstore/controller/OrderController.java b/src/main/java/com/app/bookstore/controller/OrderController.java index 456727f..d3e3f18 100644 --- a/src/main/java/com/app/bookstore/controller/OrderController.java +++ b/src/main/java/com/app/bookstore/controller/OrderController.java @@ -41,7 +41,7 @@ public OrderResponseDto placeOrder(@RequestBody OrderRequestDto requestDto) { @PreAuthorize("hasRole('ROLE_USER')") @GetMapping @Operation(summary = "Get all orders", description = "Return all orders") - public List getAll(Authentication authentication) { + public List getAll(Authentication authentication) { User user = (User) authentication.getPrincipal(); return orderService.getAll(user.getId()); } diff --git a/src/main/java/com/app/bookstore/dto/order/OrderResponseDto.java b/src/main/java/com/app/bookstore/dto/order/OrderResponseDto.java index 4569865..e3a9e12 100644 --- a/src/main/java/com/app/bookstore/dto/order/OrderResponseDto.java +++ b/src/main/java/com/app/bookstore/dto/order/OrderResponseDto.java @@ -1,4 +1,17 @@ package com.app.bookstore.dto.order; +import com.app.bookstore.model.OrderItem; +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.util.List; +import lombok.Data; + +@Data public class OrderResponseDto { + private Long id; + private Long userId; + private List orderItems; + private LocalDateTime orderDate; + private BigDecimal total; + private String status; } diff --git a/src/main/java/com/app/bookstore/dto/order/UpdateOrderRequestDto.java b/src/main/java/com/app/bookstore/dto/order/UpdateOrderRequestDto.java index 2a630af..ded0e2d 100644 --- a/src/main/java/com/app/bookstore/dto/order/UpdateOrderRequestDto.java +++ b/src/main/java/com/app/bookstore/dto/order/UpdateOrderRequestDto.java @@ -1,9 +1,11 @@ package com.app.bookstore.dto.order; import com.app.bookstore.model.Order; +import jakarta.validation.constraints.NotNull; import lombok.Data; @Data public class UpdateOrderRequestDto { + @NotNull private Order.Status status; } diff --git a/src/main/java/com/app/bookstore/service/order/OrderService.java b/src/main/java/com/app/bookstore/service/order/OrderService.java index 6335beb..2aaee97 100644 --- a/src/main/java/com/app/bookstore/service/order/OrderService.java +++ b/src/main/java/com/app/bookstore/service/order/OrderService.java @@ -9,7 +9,7 @@ public interface OrderService { OrderResponseDto placeOrder(OrderRequestDto requestDto); - List getAll(Long id); + List getAll(Long id); OrderResponseDto updateStatus(Long id, UpdateOrderRequestDto requestDto); } diff --git a/src/main/java/com/app/bookstore/service/order/OrderServiceImpl.java b/src/main/java/com/app/bookstore/service/order/OrderServiceImpl.java index e963856..f24e944 100644 --- a/src/main/java/com/app/bookstore/service/order/OrderServiceImpl.java +++ b/src/main/java/com/app/bookstore/service/order/OrderServiceImpl.java @@ -24,8 +24,11 @@ public OrderResponseDto placeOrder(OrderRequestDto requestDto) { } @Override - public List getAll(Long id) { - return orderRepository.findAllById(id); + public List getAll(Long id) { + List orderList = orderRepository.findAllById(id); + return orderList.stream() + .map(orderMapper::toDto) + .toList(); } @Override