Skip to content

Commit

Permalink
changed return type to dto
Browse files Browse the repository at this point in the history
  • Loading branch information
fedorovychh committed Jan 3, 2024
1 parent 093d059 commit 30d7efa
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Order> getAll(Authentication authentication) {
public List<OrderResponseDto> getAll(Authentication authentication) {
User user = (User) authentication.getPrincipal();
return orderService.getAll(user.getId());
}
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/app/bookstore/dto/order/OrderResponseDto.java
Original file line number Diff line number Diff line change
@@ -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<OrderItem> orderItems;
private LocalDateTime orderDate;
private BigDecimal total;
private String status;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public interface OrderService {
OrderResponseDto placeOrder(OrderRequestDto requestDto);

List<Order> getAll(Long id);
List<OrderResponseDto> getAll(Long id);

OrderResponseDto updateStatus(Long id, UpdateOrderRequestDto requestDto);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ public OrderResponseDto placeOrder(OrderRequestDto requestDto) {
}

@Override
public List<Order> getAll(Long id) {
return orderRepository.findAllById(id);
public List<OrderResponseDto> getAll(Long id) {
List<Order> orderList = orderRepository.findAllById(id);
return orderList.stream()
.map(orderMapper::toDto)
.toList();
}

@Override
Expand Down

0 comments on commit 30d7efa

Please sign in to comment.