Răsfoiți Sursa

added bids in history

Daniel Garcia Costa 3 săptămâni în urmă
părinte
comite
fac4224d11

+ 7 - 1
src/main/java/bidflow/bid/client/controller/AuctionController.java

@@ -10,9 +10,11 @@ import bidflow.bid.client.dto.User;
 import bidflow.bid.client.dto.UserResponse;
 import bidflow.bid.client.dto.Auction;
 import bidflow.bid.client.dto.AuctionView;
+import bidflow.bid.client.dto.Bid;
 import bidflow.bid.client.dto.BidRequest;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -65,11 +67,15 @@ public class AuctionController {
                     String sellerUsername = seller != null ? seller.getEmail() : "";
                     String winnerUsername = winner != null ? winner.getUsername() : "";
 
+                    List<Bid> bids = auction.getBids() != null ? auction.getBids() : Collections.emptyList();
+                    System.err.println(bids.getFirst().getUserId());
+
                     return new AuctionView(
                             itemName,
                             sellerUsername,
                             winnerUsername,
-                            auction.getFinalPrice()
+                            auction.getFinalPrice(),
+                            bids
                     );
                 })
                 .collect(Collectors.toList());

+ 15 - 2
src/main/java/bidflow/bid/client/dto/AuctionView.java

@@ -1,19 +1,24 @@
 package bidflow.bid.client.dto;
 
+import java.util.List;
+
 public class AuctionView {
 
     private String sellerUsername;
     private String winnerUsername;    
     private String itemName;
     private Double finalPrice;
+    private List<Bid> bids;
+    
 
-    public AuctionView(){}
+    public AuctionView(){} 
 
-    public AuctionView(String itemName, String sellerUsername, String winnerUsername, Double finalPrice) {
+    public AuctionView(String itemName, String sellerUsername, String winnerUsername, Double finalPrice, List<Bid> bids) {
         this.sellerUsername = sellerUsername;
         this.winnerUsername = winnerUsername;
         this.itemName = itemName;
         this.finalPrice = finalPrice;
+        this.bids = bids;
     }
 
     public String getSellerUsername() {
@@ -48,6 +53,14 @@ public class AuctionView {
         this.finalPrice = finalPrice;
     }
 
+    public List<Bid> getBids() {
+        return bids;
+    }
+
+    public void setBids(List<Bid> bids) {
+        this.bids = bids;
+    }
+
     
     
 }

+ 54 - 8
src/main/resources/templates/index.html

@@ -126,14 +126,59 @@
                 </thead>
 
                 <tbody>
-                <tr th:each="auction : ${history}">
-                    <td th:text="${auction.itemName}"></td>
-                    <td th:text="${auction.sellerUsername}"></td>
-                    <td th:text="${auction.winnerUsername}"></td>
-                    <td th:text="${auction.finalPrice}"></td>
-                </tr>
-                </tbody>
-
+                    <th:block th:each="auction, iterStat : ${history}">
+
+                        <!-- fila principal -->
+                        <tr data-bs-toggle="collapse"
+                            th:attr="data-bs-target='#bids-' + ${iterStat.index}"
+                            style="cursor: pointer;">
+
+                            <td th:text="${auction.itemName}"></td>
+                            <td th:text="${auction.sellerUsername}"></td>
+                            <td th:text="${auction.winnerUsername}"></td>
+                            <td th:text="${auction.finalPrice}"></td>
+                        </tr>
+
+                        <!-- fila expandida -->
+                        <tr>
+                            <td colspan="4">
+
+                                <div class="collapse" th:id="'bids-' + ${iterStat.index}">
+
+                                    <div th:if="${auction.bids != null and !#lists.isEmpty(auction.bids)}">
+
+                                        <table class="table table-sm mt-2">
+                                            <thead>
+                                            <tr>
+                                                <th>User</th>
+                                                <th>Amount</th>
+                                                <th>Time</th>
+                                            </tr>
+                                            </thead>
+
+                                            <tbody>
+                                            <tr th:each="bid : ${auction.bids}">
+                                                <td th:text="${bid.userId}"></td>
+                                                <td th:text="${bid.amount}"></td>
+                                                <td th:text="${bid.timestamp}"></td>
+                                            </tr>
+                                            </tbody>
+                                        </table>
+
+                                    </div>
+
+                                    <div th:if="${auction.bids == null or #lists.isEmpty(auction.bids)}">
+                                        <em>No hay pujas</em>
+                                    </div>
+
+                                </div>
+
+                            </td>
+                        </tr>
+
+                    </th:block>
+                </tbody>              
+        
             </table>
 
         </div>
@@ -141,5 +186,6 @@
 
 </div>
 
+<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
 </body>
 </html>