33import com .synergyx .trading .apiPayload .code .status .ErrorStatus ;
44import com .synergyx .trading .apiPayload .exception .GeneralException ;
55import com .synergyx .trading .dto .InterestStock .InterestStockResponseDTO ;
6+ import com .synergyx .trading .model .Stock ;
7+ import com .synergyx .trading .model .StockDetail ;
68import com .synergyx .trading .model .User ;
79import com .synergyx .trading .repository .InterestStockRepository ;
810import com .synergyx .trading .repository .RecentViewStockRepository ;
1315
1416import java .util .List ;
1517
18+ import static com .synergyx .trading .util .ParsingUtil .toFormattedNumber ;
19+
1620@ Service
1721@ RequiredArgsConstructor
1822public class InterestStockQueryServiceImpl implements InterestStockQueryService {
@@ -34,13 +38,20 @@ public List<InterestStockResponseDTO> getInterestList(Long userId) {
3438 User user = getValidUser (userId );
3539
3640 return interestStockRepository .findAllByUserId (userId ).stream ()
37- .map (i -> InterestStockResponseDTO .builder ()
38- .stockId (i .getStock ().getId ())
39- .stockName (i .getStock ().getName ())
40- .stockSymbol (i .getStock ().getSymbol ())
41- .imageUrl (i .getStock ().getImageUrl ())
42- .build ()
43- ).toList ();
41+ .map (i -> {
42+ Stock stock = i .getStock ();
43+ StockDetail detail = stock .getStockDetail (); // entity graph로 fetch
44+
45+ return InterestStockResponseDTO .builder ()
46+ .stockId (i .getStock ().getId ())
47+ .stockName (i .getStock ().getName ())
48+ .stockSymbol (i .getStock ().getSymbol ())
49+ .price (detail != null ? toFormattedNumber (detail .getPrice ()) : null )
50+ .changeRate (detail != null ? (detail .getChangeRate () + "%" ) : null )
51+ .imageUrl (i .getStock ().getImageUrl ())
52+ .build ();
53+ })
54+ .toList ();
4455 }
4556
4657 /**
@@ -54,7 +65,21 @@ public List<InterestStockResponseDTO> getInterestList(Long userId) {
5465 public List <InterestStockResponseDTO > getRecentViewStocks (Long userId ) {
5566 User user = getValidUser (userId );
5667
57- return recentViewStockRepository .findRecentStocksWithInfo (userId );
68+ return recentViewStockRepository .findByUserIdOrderByViewedAtDesc (userId ).stream ()
69+ .map (r -> {
70+ var stock = r .getStock ();
71+ var detail = stock .getStockDetail ();
72+
73+ return InterestStockResponseDTO .builder ()
74+ .stockId (stock .getId ())
75+ .stockName (stock .getName ())
76+ .stockSymbol (stock .getSymbol ())
77+ .price (detail != null ? toFormattedNumber (detail .getPrice ()) : null )
78+ .changeRate (detail != null ? (detail .getChangeRate () + "%" ) : null )
79+ .imageUrl (stock .getImageUrl ())
80+ .build ();
81+ })
82+ .toList ();
5883 }
5984
6085 /**
0 commit comments