From d6659cfc6179cd45052bd6c222416a7fcd9aef38 Mon Sep 17 00:00:00 2001 From: Valerii Fedorovych Date: Wed, 3 Jan 2024 13:19:22 +0200 Subject: [PATCH] changed return type to dto --- .../java/com/app/bookstore/controller/OrderController.java | 2 +- .../app/bookstore/dto/order/item/OrderItemResponseDto.java | 6 ++++++ .../app/bookstore/service/order/item/OrderItemService.java | 2 +- .../bookstore/service/order/item/OrderItemServiceImpl.java | 7 +++++-- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/app/bookstore/controller/OrderController.java b/src/main/java/com/app/bookstore/controller/OrderController.java index d3e3f18..0d20bab 100644 --- a/src/main/java/com/app/bookstore/controller/OrderController.java +++ b/src/main/java/com/app/bookstore/controller/OrderController.java @@ -61,7 +61,7 @@ public OrderResponseDto updateStatus( summary = "Get all items by order id", description = "Retrieve all OrderItems for a specific order" ) - public List getAllById(@PathVariable Long id) { + public List getAllById(@PathVariable Long id) { return orderItemService.getAllById(id); } diff --git a/src/main/java/com/app/bookstore/dto/order/item/OrderItemResponseDto.java b/src/main/java/com/app/bookstore/dto/order/item/OrderItemResponseDto.java index 8798503..f80ad32 100644 --- a/src/main/java/com/app/bookstore/dto/order/item/OrderItemResponseDto.java +++ b/src/main/java/com/app/bookstore/dto/order/item/OrderItemResponseDto.java @@ -1,4 +1,10 @@ package com.app.bookstore.dto.order.item; +import lombok.Data; + +@Data public class OrderItemResponseDto { + private Long id; + private Long bookId; + private int quantity; } diff --git a/src/main/java/com/app/bookstore/service/order/item/OrderItemService.java b/src/main/java/com/app/bookstore/service/order/item/OrderItemService.java index dba6670..d517e50 100644 --- a/src/main/java/com/app/bookstore/service/order/item/OrderItemService.java +++ b/src/main/java/com/app/bookstore/service/order/item/OrderItemService.java @@ -6,7 +6,7 @@ public interface OrderItemService { - List getAllById(Long id); + List getAllById(Long id); OrderItemResponseDto getItemById(Long id, Long itemId); } diff --git a/src/main/java/com/app/bookstore/service/order/item/OrderItemServiceImpl.java b/src/main/java/com/app/bookstore/service/order/item/OrderItemServiceImpl.java index f58e008..455a180 100644 --- a/src/main/java/com/app/bookstore/service/order/item/OrderItemServiceImpl.java +++ b/src/main/java/com/app/bookstore/service/order/item/OrderItemServiceImpl.java @@ -16,8 +16,11 @@ public class OrderItemServiceImpl implements OrderItemService { private final OrderItemMapper orderItemMapper; @Override - public List getAllById(Long id) { - return orderItemRepository.findAllById(id); + public List getAllById(Long id) { + List items = orderItemRepository.findAllById(id); + return items.stream() + .map(orderItemMapper::toDto) + .toList(); } @Override