woals 08-07
240807 권민수 책별 단어장 조회 -> 단원별 단어장 조회로 구조 변경
@f2c543b7a2d9f9eddca585ae1a8fcbfa66efd50f
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
@@ -1,6 +1,7 @@
 package com.takensoft.ai_lms.lms.word_book.dao;
 
 import com.takensoft.ai_lms.lms.word_book.vo.WordBookVO;
+import org.apache.ibatis.annotations.Param;
 import org.egovframe.rte.psl.dataaccess.mapper.Mapper;
 
 import java.util.HashMap;
@@ -20,9 +21,9 @@
     List<WordBookVO> getAllWordBooks(HashMap<String, Object> params) throws Exception;
     int getWordBooksCount() throws Exception;
 
-    // 책에 소속된 단어장 목록 조회
-    List<WordBookVO> getWordBooksByBookId(HashMap<String, Object> params) throws Exception;
-    int getWordBooksByBookIdCount(String bookId) throws Exception;
+    // 단원별로 단어장 목록 조회
+    List<WordBookVO> getWordBooksByUnitId(HashMap<String, Object> params) throws Exception;
+    int getWordBooksByUnitIdCount(HashMap<String, Object> params) throws Exception;
 
     // 아이디에 해당하는 단어장 조회
     WordBookVO getWordBookById(String wdBookId);
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
@@ -40,18 +40,20 @@
     }
 
     @Override
-    public List<WordBookVO> getWordBooksByBookId(String bookId, int page, int pageSize) throws Exception {
+    public List<WordBookVO> getWordBooksByUnitId(String unitId, int page, int pageSize) throws Exception {
         int startIndex = (page - 1) * pageSize;
         HashMap<String, Object> params = new HashMap<>();
-        params.put("bookId", bookId);
+        params.put("unitId", unitId);
         params.put("startIndex", startIndex);
         params.put("pageSize", pageSize);
-        return wordBookDAO.getWordBooksByBookId(params);
+        return wordBookDAO.getWordBooksByUnitId(params);
     }
 
     @Override
-    public int getWordBooksByBookIdCount(String bookId) throws Exception {
-        return wordBookDAO.getWordBooksByBookIdCount(bookId);
+    public int getWordBooksByUnitIdCount(String unitId) throws Exception {
+        HashMap<String, Object> params = new HashMap<>();
+        params.put("unitId", unitId);
+        return wordBookDAO.getWordBooksByUnitIdCount(params);
     }
 
     @Override
@@ -77,9 +79,10 @@
     }
 
     @Override
-    public List<WordBookVO> getWordBooksByTextTitle(String textTitle, int page, int pageSize) throws Exception {
+    public List<WordBookVO> getWordBooksByTextTitle(String unitId, String textTitle, int page, int pageSize) throws Exception {
         int startIndex = (page - 1) * pageSize;
         HashMap<String, Object> params = new HashMap<>();
+        params.put("unitId", unitId);
         params.put("textTitle", "%" + textTitle + "%");
         params.put("startIndex", startIndex);
         params.put("pageSize", pageSize);
@@ -87,14 +90,18 @@
     }
 
     @Override
-    public int getWordBooksByTextTitleCount(String textTitle) throws Exception {
+    public int getWordBooksByTextTitleCount(String unitId, String textTitle) throws Exception {
+        HashMap<String, Object> params = new HashMap<>();
+        params.put("unitId", unitId);
+        params.put("textTitle", "%" + textTitle + "%");
         return wordBookDAO.getWordBooksByTextTitleCount(textTitle);
     }
 
     @Override
-    public List<WordBookVO> getWordBooksByWord(String word, int page, int pageSize) throws Exception {
+    public List<WordBookVO> getWordBooksByWord(String unitId, String word, int page, int pageSize) throws Exception {
         int startIndex = (page - 1) * pageSize;
         HashMap<String, Object> params = new HashMap<>();
+        params.put("unitId", unitId);
         params.put("word", word);
         params.put("startIndex", startIndex);
         params.put("pageSize", pageSize);
@@ -102,7 +109,10 @@
     }
 
     @Override
-    public int getWordBooksByWordCount(String word) throws Exception {
+    public int getWordBooksByWordCount(String unitId, String word) throws Exception {
+        HashMap<String, Object> params = new HashMap<>();
+        params.put("unitId", unitId);
+        params.put("word", word);
         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
@@ -18,8 +18,8 @@
     int getWordBooksCount() throws Exception;
 
     // 책에 소속된 단어장 목록 조회
-    List<WordBookVO> getWordBooksByBookId(String bookId, int page, int pageSize) throws Exception;
-    int getWordBooksByBookIdCount(String bookId) throws Exception;
+    List<WordBookVO> getWordBooksByUnitId(String unitId, int page, int pageSize) throws Exception;
+    int getWordBooksByUnitIdCount(String unitId) throws Exception;
 
     // 아이디에 해당하는 단어장 조회
     WordBookVO getWordBookById(String wdBookId);
@@ -34,12 +34,12 @@
     void deleteWordBook(String wdBookId);
 
     // 단어장 검색(지문 이름으로 검색)
-    List<WordBookVO> getWordBooksByTextTitle(String textTitle, int page, int pageSize) throws Exception;
-    int getWordBooksByTextTitleCount(String textTitle) throws Exception;
+    List<WordBookVO> getWordBooksByTextTitle(String unitId, String textTitle, int page, int pageSize) throws Exception;
+    int getWordBooksByTextTitleCount(String unitId, String textTitle) throws Exception;
 
     // 단어장 검색(단어로 검색)
-    List<WordBookVO> getWordBooksByWord(String word, int page, int pageSize) throws Exception;
-    int getWordBooksByWordCount(String word) throws Exception;
+    List<WordBookVO> getWordBooksByWord(String unitId, String word, int page, int pageSize) throws Exception;
+    int getWordBooksByWordCount(String unitId, String word) throws Exception;
 
 
 }
src/main/java/com/takensoft/ai_lms/lms/word_book/vo/WordBookVO.java
--- src/main/java/com/takensoft/ai_lms/lms/word_book/vo/WordBookVO.java
+++ src/main/java/com/takensoft/ai_lms/lms/word_book/vo/WordBookVO.java
@@ -19,5 +19,6 @@
     private String textId;
     private String userId;
     private String bookId;
+    private String unitId;
 
 }
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
@@ -41,15 +41,15 @@
         return result;
     }
 
-    // 책에 소속된 단어장 목록 조회
-    @PostMapping("/findByBookId.json")
-    public HashMap<String, Object> getWordBooksByBookId(@RequestBody HashMap<String, Object> params) throws Exception {
-        String bookId = (String) params.get("bookId");
+    // 단원별 단어장 목록 조회
+    @PostMapping("/findByUnitId.json")
+    public HashMap<String, Object> getWordBooksByUnitId(@RequestBody HashMap<String, Object> params) throws Exception {
+        String unitId = (String) params.get("unitId");
         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);
+        List<WordBookVO> wordBooks = wordBookService.getWordBooksByUnitId(unitId, page, pageSize);
+        int totalWordBooks = wordBookService.getWordBooksByUnitIdCount(unitId);
 
         HashMap<String, Object> result = new HashMap<>();
         result.put("wordBooks", wordBooks);
@@ -90,12 +90,13 @@
     // 단어장 검색(지문 이름으로 검색)
     @PostMapping("/findByTextTitle.json")
     public HashMap<String, Object> getWordBooksByTextTitle(@RequestBody HashMap<String, Object> params) throws Exception {
+        String unitId = (String) params.get("unitId");
         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);
+        List<WordBookVO> wordBooks = wordBookService.getWordBooksByTextTitle(unitId, textTitle, page, pageSize);
+        int totalWordBooks = wordBookService.getWordBooksByTextTitleCount(unitId, textTitle);
 
         HashMap<String, Object> result = new HashMap<>();
         result.put("wordBooks", wordBooks);
@@ -107,12 +108,13 @@
     // 단어장 검색(단어로 검색)
     @PostMapping("/findByWord.json")
     public HashMap<String, Object> getWordBooksByWord(@RequestBody HashMap<String, Object> params) throws Exception {
+        String unitId = (String) params.get("unitId");
         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);
+        List<WordBookVO> wordBooks = wordBookService.getWordBooksByWord(unitId, word, page, pageSize);
+        int totalWordBooks = wordBookService.getWordBooksByWordCount(unitId, word);
 
         HashMap<String, Object> result = new HashMap<>();
         result.put("wordBooks", wordBooks);
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
@@ -13,7 +13,7 @@
         <result property="wdBookTypeId" column="wd_book_type_id"/>
         <result property="textId" column="text_id"/>
         <result property="userId" column="user_id"/>
-        <result property="bookId" column="book_id"/>
+        <result property="unitId" column="unit_id"/>
     </resultMap>
 
     <select id="getWordBooksCount" resultType="int">
@@ -21,10 +21,10 @@
         FROM ai_lms.wordbook
     </select>
 
-    <select id="getWordBooksByBookIdCount" resultType="int">
+    <select id="getWordBooksByUnitIdCount" resultType="int">
         SELECT COUNT(*)
         FROM wordbook
-        WHERE book_id = #{bookId}
+        WHERE unit_id = #{unitId}
     </select>
 
     <select id="getWordBooksByTextTitleCount" resultType="int">
@@ -47,21 +47,23 @@
             wd_book_type_id,
             text_id,
             user_id,
-            book_id
+            book_id,
+            unit_id
         FROM ai_lms.wordbook
         ORDER BY wd_book_id DESC
         LIMIT #{pageSize} OFFSET #{startIndex}
     </select>
 
-    <select id="getWordBooksByBookId" resultMap="WordBookResultMap">
+    <select id="getWordBooksByUnitId" resultMap="WordBookResultMap">
         SELECT
             wd_book_id,
             wd_book_type_id,
             text_id,
             user_id,
-            book_id
+            book_id,
+            unit_id
         FROM wordbook
-        WHERE book_id = #{bookId}
+        WHERE unit_id = #{unitId}
         ORDER BY wd_book_id DESC
         LIMIT #{pageSize} OFFSET #{startIndex}
     </select>
@@ -72,7 +74,8 @@
             wd_book_type_id,
             text_id,
             user_id,
-            book_id
+            book_id,
+            unit_id
         FROM ai_lms.wordbook
         WHERE wd_book_id = #{wdBookId}
     </select>
@@ -83,12 +86,14 @@
                              wd_book_type_id,
                              text_id,
                              user_id,
-                             book_id)
+                             book_id,
+                             unit_id)
         VALUES (#{wdBookId},
                 #{wdBookTypeId},
                 #{textId},
                 #{userId},
-                #{bookId})
+                #{bookId},
+                #{unitId})
     </insert>
 
     <update id="updateWordBook" parameterType="WordBookVO">
@@ -96,7 +101,8 @@
         SET wd_book_type_id = #{wdBookTypeId},
             text_id = #{textId},
             user_id = #{userId},
-            book_id = #{bookId}
+            book_id = #{bookId},
+            unit_id = #{unitId}
         WHERE wd_book_id = #{wdBookId}
     </update>
 
@@ -109,7 +115,8 @@
         SELECT wb.*
         FROM wordbook wb
         JOIN text t ON wb.text_id = t.text_id
-        WHERE t.text_ttl LIKE #{textTitle}
+        WHERE wb.unit_id = #{unitId}
+        AND t.text_ttl LIKE #{textTitle}
         ORDER BY wd_book_id DESC
         LIMIT #{pageSize} OFFSET #{startIndex}
     </select>
@@ -118,7 +125,8 @@
         SELECT DISTINCT wb.*
         FROM wordbook wb
         JOIN word w ON wb.wd_book_id = w.wd_book_id
-        WHERE w.wd_nm LIKE #{word}
+        WHERE wb.unit_id = #{unitId}
+        AND w.wd_nm LIKE #{word}
         ORDER BY wd_book_id DESC
         LIMIT #{pageSize} OFFSET #{startIndex}
     </select>
Add a comment
List