woals 08-06
240806 권민수 단어장 목록 조회 기능에 페이지네이션 추가
@6dca3d5bc7b020d58abd045d2e495bd1e222f67f
src/main/java/com/takensoft/ai_lms/lms/word_book/dao/WordBookDAO.java
--- src/main/java/com/takensoft/ai_lms/lms/word_book/dao/WordBookDAO.java
+++ src/main/java/com/takensoft/ai_lms/lms/word_book/dao/WordBookDAO.java
@@ -3,6 +3,7 @@
 import com.takensoft.ai_lms.lms.word_book.vo.WordBookVO;
 import org.egovframe.rte.psl.dataaccess.mapper.Mapper;
 
+import java.util.HashMap;
 import java.util.List;
 
 /**
@@ -16,10 +17,12 @@
 public interface WordBookDAO {
 
     // 임시: 단어장 전체 목록 조회
-    List<WordBookVO> getAllWordBooks();
+    List<WordBookVO> getAllWordBooks(HashMap<String, Object> params) throws Exception;
+    int getWordBooksCount() throws Exception;
 
     // 책에 소속된 단어장 목록 조회
-    List<WordBookVO> getWordBooksByBookId(String bookId);
+    List<WordBookVO> getWordBooksByBookId(HashMap<String, Object> params) throws Exception;
+    int getWordBooksByBookIdCount(String bookId) throws Exception;
 
     // 아이디에 해당하는 단어장 조회
     WordBookVO getWordBookById(String wdBookId);
@@ -34,9 +37,11 @@
     int deleteWordBook(String wdBookId);
 
     // 단어장 검색(지문 이름으로 검색)
-    List<WordBookVO> getWordBooksByTextTitle(String textTitle);
+    List<WordBookVO> getWordBooksByTextTitle(HashMap<String, Object> params) throws Exception;
+    int getWordBooksByTextTitleCount(String textTitle) throws Exception;
 
     // 단어장 검색(단어로 검색)
-    List<WordBookVO> getWordBooksByWord(String word);
+    List<WordBookVO> getWordBooksByWord(HashMap<String, Object> params) throws Exception;
+    int getWordBooksByWordCount(String word) throws Exception;
 
 }
src/main/java/com/takensoft/ai_lms/lms/word_book/service/Impl/WordBookServiceImpl.java
--- src/main/java/com/takensoft/ai_lms/lms/word_book/service/Impl/WordBookServiceImpl.java
+++ src/main/java/com/takensoft/ai_lms/lms/word_book/service/Impl/WordBookServiceImpl.java
@@ -7,6 +7,7 @@
 import lombok.RequiredArgsConstructor;
 import org.springframework.stereotype.Service;
 
+import java.util.HashMap;
 import java.util.List;
 
 /**
@@ -25,13 +26,32 @@
     private final IdgenService wordBookIdgn;
 
     @Override
-    public List<WordBookVO> getAllWordBooks() {
-        return wordBookDAO.getAllWordBooks();
+    public List<WordBookVO> getAllWordBooks(int page, int pageSize) throws Exception {
+        int startIndex = (page - 1) * pageSize;
+        HashMap<String, Object> params = new HashMap<>();
+        params.put("startIndex", startIndex);
+        params.put("pageSize", pageSize);
+        return wordBookDAO.getAllWordBooks(params);
     }
 
     @Override
-    public List<WordBookVO> getWordBooksByBookId(String bookId) {
-        return wordBookDAO.getWordBooksByBookId(bookId);
+    public int getWordBooksCount() throws Exception {
+        return wordBookDAO.getWordBooksCount();
+    }
+
+    @Override
+    public List<WordBookVO> getWordBooksByBookId(String bookId, int page, int pageSize) throws Exception {
+        int startIndex = (page - 1) * pageSize;
+        HashMap<String, Object> params = new HashMap<>();
+        params.put("bookId", bookId);
+        params.put("startIndex", startIndex);
+        params.put("pageSize", pageSize);
+        return wordBookDAO.getWordBooksByBookId(params);
+    }
+
+    @Override
+    public int getWordBooksByBookIdCount(String bookId) throws Exception {
+        return wordBookDAO.getWordBooksByBookIdCount(bookId);
     }
 
     @Override
@@ -57,13 +77,33 @@
     }
 
     @Override
-    public List<WordBookVO> getWordBooksByTextTitle(String textTitle) {
-        return wordBookDAO.getWordBooksByTextTitle(textTitle);
+    public List<WordBookVO> getWordBooksByTextTitle(String textTitle, int page, int pageSize) throws Exception {
+        int startIndex = (page - 1) * pageSize;
+        HashMap<String, Object> params = new HashMap<>();
+        params.put("textTitle", "%" + textTitle + "%");
+        params.put("startIndex", startIndex);
+        params.put("pageSize", pageSize);
+        return wordBookDAO.getWordBooksByTextTitle(params);
     }
 
     @Override
-    public List<WordBookVO> getWordBooksByWord(String word) {
-        return wordBookDAO.getWordBooksByWord(word);
+    public int getWordBooksByTextTitleCount(String textTitle) throws Exception {
+        return wordBookDAO.getWordBooksByTextTitleCount(textTitle);
+    }
+
+    @Override
+    public List<WordBookVO> getWordBooksByWord(String word, int page, int pageSize) throws Exception {
+        int startIndex = (page - 1) * pageSize;
+        HashMap<String, Object> params = new HashMap<>();
+        params.put("word", "%" + word + "%");
+        params.put("startIndex", startIndex);
+        params.put("pageSize", pageSize);
+        return wordBookDAO.getWordBooksByWord(params);
+    }
+
+    @Override
+    public int getWordBooksByWordCount(String word) throws Exception {
+        return wordBookDAO.getWordBooksByWordCount(word);
     }
 
 }
src/main/java/com/takensoft/ai_lms/lms/word_book/service/WordBookService.java
--- src/main/java/com/takensoft/ai_lms/lms/word_book/service/WordBookService.java
+++ src/main/java/com/takensoft/ai_lms/lms/word_book/service/WordBookService.java
@@ -14,10 +14,12 @@
 public interface WordBookService {
 
     // 임시: 단어장 전체 목록 조회
-    List<WordBookVO> getAllWordBooks();
+    List<WordBookVO> getAllWordBooks(int page, int pageSize) throws Exception;
+    int getWordBooksCount() throws Exception;
 
     // 책에 소속된 단어장 목록 조회
-    List<WordBookVO> getWordBooksByBookId(String bookId);
+    List<WordBookVO> getWordBooksByBookId(String bookId, int page, int pageSize) throws Exception;
+    int getWordBooksByBookIdCount(String bookId) throws Exception;
 
     // 아이디에 해당하는 단어장 조회
     WordBookVO getWordBookById(String wdBookId);
@@ -32,10 +34,12 @@
     void deleteWordBook(String wdBookId);
 
     // 단어장 검색(지문 이름으로 검색)
-    List<WordBookVO> getWordBooksByTextTitle(String textTitle);
+    List<WordBookVO> getWordBooksByTextTitle(String textTitle, int page, int pageSize) throws Exception;
+    int getWordBooksByTextTitleCount(String textTitle) throws Exception;
 
     // 단어장 검색(단어로 검색)
-    List<WordBookVO> getWordBooksByWord(String word);
+    List<WordBookVO> getWordBooksByWord(String word, int page, int pageSize) throws Exception;
+    int getWordBooksByWordCount(String word) throws Exception;
 
 
 }
src/main/java/com/takensoft/ai_lms/lms/word_book/web/WordBookController.java
--- src/main/java/com/takensoft/ai_lms/lms/word_book/web/WordBookController.java
+++ src/main/java/com/takensoft/ai_lms/lms/word_book/web/WordBookController.java
@@ -6,6 +6,7 @@
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -26,15 +27,35 @@
 
     // 단어장 전체 목록 조회
     @PostMapping("/findAll.json")
-    public List<WordBookVO> getAllWordBooks() {
-        return wordBookService.getAllWordBooks();
+    public HashMap<String, Object> getAllWordBooks(@RequestBody HashMap<String, Object> params) throws Exception {
+        int page = (int) params.get("page");
+        int pageSize = (int) params.get("pageSize");
+
+        List<WordBookVO> wordBooks = wordBookService.getAllWordBooks(page, pageSize);
+        int totalWordBooks = wordBookService.getWordBooksCount();
+
+        HashMap<String, Object> result = new HashMap<>();
+        result.put("wordBooks", wordBooks);
+        result.put("totalWordBooks", totalWordBooks);
+
+        return result;
     }
 
     // 책에 소속된 단어장 목록 조회
     @PostMapping("/findByBookId.json")
-    public List<WordBookVO> getWordBooksByBookId(@RequestBody Map<String, String> request) {
-        String bookId = request.get("bookId");
-        return wordBookService.getWordBooksByBookId(bookId);
+    public HashMap<String, Object> getWordBooksByBookId(@RequestBody HashMap<String, Object> params) throws Exception {
+        String bookId = (String) params.get("bookId");
+        int page = (int) params.get("page");
+        int pageSize = (int) params.get("pageSize");
+
+        List<WordBookVO> wordBooks = wordBookService.getWordBooksByBookId(bookId, page, pageSize);
+        int totalWordBooks = wordBookService.getWordBooksByBookIdCount(bookId);
+
+        HashMap<String, Object> result = new HashMap<>();
+        result.put("wordBooks", wordBooks);
+        result.put("totalWordBooks", totalWordBooks);
+
+        return result;
     }
 
     // 아이디에 해당하는 단어장 조회
@@ -68,15 +89,36 @@
 
     // 단어장 검색(지문 이름으로 검색)
     @PostMapping("/findByTextTitle.json")
-    public List<WordBookVO> getWordBooksByTextTitle(@RequestBody Map<String, String> request) {
-        String textTitle = "%" + request.get("textTitle") + "%"; // 부분 검색 허용
-        return wordBookService.getWordBooksByTextTitle(textTitle);
+    public HashMap<String, Object> getWordBooksByTextTitle(@RequestBody HashMap<String, Object> params) throws Exception {
+        String textTitle = (String) params.get("textTitle");
+        int page = (int) params.get("page");
+        int pageSize = (int) params.get("pageSize");
+
+        List<WordBookVO> wordBooks = wordBookService.getWordBooksByTextTitle(textTitle, page, pageSize);
+        int totalWordBooks = wordBookService.getWordBooksByTextTitleCount(textTitle);
+
+        HashMap<String, Object> result = new HashMap<>();
+        result.put("wordBooks", wordBooks);
+        result.put("totalWordBooks", totalWordBooks);
+
+        return result;
     }
 
     // 단어장 검색(단어로 검색)
     @PostMapping("/findByWord.json")
-    public List<WordBookVO> getWordBooksByWord(@RequestBody Map<String, String> request) {
-        return wordBookService.getWordBooksByWord(request.get("word"));
+    public HashMap<String, Object> getWordBooksByWord(@RequestBody HashMap<String, Object> params) throws Exception {
+        String word = (String) params.get("word");
+        int page = (int) params.get("page");
+        int pageSize = (int) params.get("pageSize");
+
+        List<WordBookVO> wordBooks = wordBookService.getWordBooksByWord(word, page, pageSize);
+        int totalWordBooks = wordBookService.getWordBooksByWordCount(word);
+
+        HashMap<String, Object> result = new HashMap<>();
+        result.put("wordBooks", wordBooks);
+        result.put("totalWordBooks", totalWordBooks);
+
+        return result;
     }
 
 }
src/main/resources/mybatis/mapper/lms/word_book-SQL.xml
--- src/main/resources/mybatis/mapper/lms/word_book-SQL.xml
+++ src/main/resources/mybatis/mapper/lms/word_book-SQL.xml
@@ -16,6 +16,31 @@
         <result property="bookId" column="book_id"/>
     </resultMap>
 
+    <select id="getWordBooksCount" resultType="int">
+        SELECT COUNT(*)
+        FROM ai_lms.wordbook
+    </select>
+
+    <select id="getWordBooksByBookIdCount" resultType="int">
+        SELECT COUNT(*)
+        FROM wordbook
+        WHERE book_id = #{bookId}
+    </select>
+
+    <select id="getWordBooksByTextTitleCount" resultType="int">
+        SELECT COUNT(*)
+        FROM wordbook wb
+                 JOIN text t ON wb.text_id = t.text_id
+        WHERE t.text_ttl LIKE #{textTitle}
+    </select>
+
+    <select id="getWordBooksByWordCount" resultType="int">
+        SELECT COUNT(DISTINCT wb.wd_book_id)
+        FROM wordbook wb
+                 JOIN word w ON wb.wd_book_id = w.wd_book_id
+        WHERE w.wd_nm LIKE #{word}
+    </select>
+
     <select id="getAllWordBooks" resultMap="WordBookResultMap">
         SELECT
             wd_book_id,
@@ -24,9 +49,11 @@
             user_id,
             book_id
         FROM ai_lms.wordbook
+        ORDER BY wd_book_id DESC
+        LIMIT #{pageSize} OFFSET #{startIndex}
     </select>
 
-    <select id="getWordBooksByBookId" resultMap="WordBookResultMap">  <!-- 수정됨 -->
+    <select id="getWordBooksByBookId" resultMap="WordBookResultMap">
         SELECT
             wd_book_id,
             wd_book_type_id,
@@ -35,6 +62,8 @@
             book_id
         FROM wordbook
         WHERE book_id = #{bookId}
+        ORDER BY wd_book_id DESC
+        LIMIT #{pageSize} OFFSET #{startIndex}
     </select>
 
     <select id="getWordBookById" parameterType="string" resultMap="WordBookResultMap">
@@ -81,6 +110,8 @@
         FROM wordbook wb
         JOIN text t ON wb.text_id = t.text_id
         WHERE t.text_ttl LIKE #{textTitle}
+        ORDER BY wd_book_id DESC
+        LIMIT #{pageSize} OFFSET #{startIndex}
     </select>
 
     <select id="getWordBooksByWord" resultType="WordBookVO">
@@ -88,6 +119,8 @@
         FROM wordbook wb
         JOIN word w ON wb.wd_book_id = w.wd_book_id
         WHERE w.wd_nm LIKE #{word}
+        ORDER BY wd_book_id DESC
+        LIMIT #{pageSize} OFFSET #{startIndex}
     </select>
 
 </mapper>
(파일 끝에 줄바꿈 문자 없음)
Add a comment
List