1717import com .fasterxml .jackson .databind .ObjectMapper ;
1818import com .team_nebula .nebula .domain .chatbot .dto .request .ChatRequestDTO ;
1919import com .team_nebula .nebula .domain .chatbot .dto .request .SessionRequestDTO ;
20- import com .team_nebula .nebula .domain .chatbot .dto .response .CharResponseDTO ;
20+ import com .team_nebula .nebula .domain .chatbot .dto .response .ChatResponseDTO ;
2121import com .team_nebula .nebula .domain .chatbot .dto .response .MessageResponseDTO ;
22+ import com .team_nebula .nebula .domain .chatbot .dto .response .PaginationResponseDTO ;
2223import com .team_nebula .nebula .domain .chatbot .dto .response .SessionListResponseDTO ;
2324import com .team_nebula .nebula .domain .chatbot .dto .response .SessionResponseDTO ;
25+ import com .team_nebula .nebula .domain .chatbot .dto .response .SessionsResponseDTO ;
2426import com .team_nebula .nebula .global .apipayload .code .status .ErrorStatus ;
2527import com .team_nebula .nebula .global .apipayload .exception .GeneralException ;
2628
@@ -79,7 +81,7 @@ private String extractSessionId(String responseBody) {
7981 }
8082
8183 @ Override
82- public List < SessionListResponseDTO > getSessions (Long userId , int limit , int offset ) {
84+ public SessionsResponseDTO getSessions (Long userId , int limit , int offset ) {
8385 try {
8486 String url = String .format ("%s/chat/sessions?user_id=%d&limit=%d&offset=%d" , aiChatUrl , userId , limit ,
8587 offset );
@@ -101,16 +103,23 @@ public List<SessionListResponseDTO> getSessions(Long userId, int limit, int offs
101103 }
102104 }
103105
104- private List < SessionListResponseDTO > parseSessionsFromResponse (String responseBody ) {
106+ private SessionsResponseDTO parseSessionsFromResponse (String responseBody ) {
105107 List <SessionListResponseDTO > sessions = new ArrayList <>();
108+ int total = 0 ;
106109
107110 try {
108111 JsonNode root = objectMapper .readTree (responseBody );
109- JsonNode sessionsNode = root .path ("data" ).path ("sessions" );
112+ JsonNode dataNode = root .path ("data" );
113+ JsonNode sessionsNode = dataNode .path ("sessions" );
114+
115+ total = dataNode .path ("total" ).asInt (0 );
110116
111117 if (!sessionsNode .isArray ()) {
112118 log .warn ("세션 목록이 배열이 아닙니다." );
113- return sessions ;
119+ return SessionsResponseDTO .builder ()
120+ .sessions (sessions )
121+ .total (total )
122+ .build ();
114123 }
115124
116125 for (JsonNode sessionNode : sessionsNode ) {
@@ -129,7 +138,10 @@ private List<SessionListResponseDTO> parseSessionsFromResponse(String responseBo
129138 log .error ("AI 세션 목록 JSON 파싱 실패" , e );
130139 }
131140
132- return sessions ;
141+ return SessionsResponseDTO .builder ()
142+ .sessions (sessions )
143+ .total (total )
144+ .build ();
133145 }
134146
135147 private String getText (JsonNode node , String fieldName ) {
@@ -224,9 +236,10 @@ private Map<String, Object> buildChatRequestBody(Long userId, ChatRequestDTO req
224236 }
225237
226238 @ Override
227- public List < CharResponseDTO > getSessionMessages (Long userId , String sessionId ) {
239+ public ChatResponseDTO getSessionMessages (Long userId , String sessionId , int page , int size ) {
228240 try {
229- String url = String .format ("%s/chat/sessions/%s/messages?user_id=%d" , aiChatUrl , sessionId , userId );
241+ String url = String .format ("%s/chat/sessions/%s/messages?user_id=%d&page=%d&size=%d" ,
242+ aiChatUrl , sessionId , userId , page , size );
230243
231244 HttpHeaders headers = new HttpHeaders ();
232245 headers .setContentType (MediaType .APPLICATION_JSON );
@@ -245,6 +258,7 @@ public List<CharResponseDTO> getSessionMessages(Long userId, String sessionId) {
245258
246259 String receivedSessionId = getText (data , "session_id" );
247260 JsonNode messagesNode = data .path ("messages" );
261+ JsonNode paginationNode = data .path ("pagination" );
248262
249263 List <MessageResponseDTO > messageList = new ArrayList <>();
250264
@@ -261,13 +275,23 @@ public List<CharResponseDTO> getSessionMessages(Long userId, String sessionId) {
261275 }
262276 }
263277
264- CharResponseDTO responseDto = CharResponseDTO .builder ()
278+ PaginationResponseDTO pagination = PaginationResponseDTO .builder ()
279+ .currentPage (paginationNode .path ("current_page" ).asInt (1 ))
280+ .pageSize (paginationNode .path ("page_size" ).asInt (20 ))
281+ .totalCount (paginationNode .path ("total_count" ).asInt (0 ))
282+ .totalPages (paginationNode .path ("total_pages" ).asInt (0 ))
283+ .hasNext (paginationNode .path ("has_next" ).asBoolean (false ))
284+ .hasPrev (paginationNode .path ("has_prev" ).asBoolean (false ))
285+ .nextPage (paginationNode .path ("next_page" ).isNull () ? null : paginationNode .path ("next_page" ).asInt ())
286+ .prevPage (paginationNode .path ("prev_page" ).isNull () ? null : paginationNode .path ("prev_page" ).asInt ())
287+ .build ();
288+
289+ return ChatResponseDTO .builder ()
265290 .sessionId (receivedSessionId )
266291 .messages (messageList )
292+ .pagination (pagination )
267293 .build ();
268294
269- return List .of (responseDto );
270-
271295 } catch (Exception e ) {
272296 log .error ("세션 메시지 조회 중 오류 발생" , e );
273297 throw new GeneralException (ErrorStatus ._AI_CHATBOT_ERROR );
0 commit comments