|
1 | 1 | package com.codebykavindu.bookstore.orders.web.controllers;
|
2 | 2 |
|
| 3 | +import com.codebykavindu.bookstore.orders.domain.OrderNotFoundException; |
3 | 4 | import com.codebykavindu.bookstore.orders.domain.OrderService;
|
4 | 5 | import com.codebykavindu.bookstore.orders.domain.SecurityService;
|
5 | 6 | import com.codebykavindu.bookstore.orders.domain.models.CreateOrderRequest;
|
6 | 7 | import com.codebykavindu.bookstore.orders.domain.models.CreateOrderResponse;
|
| 8 | +import com.codebykavindu.bookstore.orders.domain.models.OrderDTO; |
| 9 | +import com.codebykavindu.bookstore.orders.domain.models.OrderSummary; |
7 | 10 | import jakarta.validation.Valid;
|
| 11 | +import java.util.List; |
8 | 12 | import org.slf4j.Logger;
|
9 | 13 | import org.slf4j.LoggerFactory;
|
10 | 14 | import org.springframework.http.HttpStatus;
|
| 15 | +import org.springframework.web.bind.annotation.GetMapping; |
| 16 | +import org.springframework.web.bind.annotation.PathVariable; |
11 | 17 | import org.springframework.web.bind.annotation.PostMapping;
|
12 | 18 | import org.springframework.web.bind.annotation.RequestBody;
|
13 | 19 | import org.springframework.web.bind.annotation.RequestMapping;
|
@@ -37,4 +43,20 @@ CreateOrderResponse createOrder(@Valid @RequestBody CreateOrderRequest request)
|
37 | 43 | log.info("Creating order for user={}", userName);
|
38 | 44 | return orderService.createOrder(userName, request);
|
39 | 45 | }
|
| 46 | + |
| 47 | + @GetMapping |
| 48 | + List<OrderSummary> getOrders() { |
| 49 | + String username = securityService.getLoginUsername(); |
| 50 | + log.info("Fetching orders for user={}", username); |
| 51 | + return orderService.findOrders(username); |
| 52 | + } |
| 53 | + |
| 54 | + @GetMapping("/{orderNumber}") |
| 55 | + OrderDTO getOrder(@PathVariable("orderNumber") String orderNumber) { |
| 56 | + log.info("Fetching order by id={}", orderNumber); |
| 57 | + String username = securityService.getLoginUsername(); |
| 58 | + return orderService |
| 59 | + .findUserOrder(username, orderNumber) |
| 60 | + .orElseThrow(() -> new OrderNotFoundException(orderNumber)); |
| 61 | + } |
40 | 62 | }
|
0 commit comments