jichoi / lms_front star
박민혁 박민혁 2024-08-22
240822 박민혁 로드맵 수정
@302768bae1f43914acba804c465420ccb88ffa39
client/views/pages/teacher/RoadMap.vue
--- client/views/pages/teacher/RoadMap.vue
+++ client/views/pages/teacher/RoadMap.vue
@@ -1205,6 +1205,16 @@
 
                             if (item.prblm_id && item.prblm_id.length > 0) {
                                 item.prblm_id.forEach(prblm => {
+                                    if (seqIndex === 2) {
+                                    this.learningId1 = item.learning_id;
+                                }
+                                if (seqIndex === 3) {
+                                    this.learningId2 = item.learning_id;
+                                }
+                                if (seqIndex === 6) {
+                                    this.learningId3 = item.learning_id;
+                                }
+
                                     this.RoadMap[seqIndex].push({
                                         learningId: item.learning_id,
                                         prblmId: prblm.prblm_id,
@@ -1245,14 +1255,6 @@
                 const originalSeq = this.OrginRoadMap[position] || [];
                 const insertList = [];
                 const insertExistList = [];
-                const updateList = [];
-                const deleteList = [];
-
-                // 원본 데이터의 wdCntId와 wdBookId를 매핑하여 쉽게 조회할 수 있도록 객체화
-                const originalMap = {};
-                originalSeq.forEach(item => {
-                    originalMap[item.wdCntId] = item.wdBookId;
-                });
 
                 // currentSeq와 originalSeq 비교
                 const isEqual = currentSeq.length === originalSeq.length && currentSeq.every((currentItem, index) => {
@@ -1265,19 +1267,6 @@
                     console.log(`Position ${position}: currentSeq and originalSeq are identical. No action taken.`);
                     continue; // 다음 위치로 넘어감
                 }
-                // 삭제할 데이터 찾기
-                originalSeq.forEach(originalItem => {
-                    const { wdCntId, wdBookId } = originalItem;
-                    const currentItemExists = currentSeq.some(item => item.wdCntId === wdCntId);
-
-                    // 현재 시퀀스에 존재하지 않는 경우 삭제 리스트에 추가
-                    if (!currentItemExists) {
-                        deleteList.push({
-                            wordContentId: wdCntId,
-                            wordBookId: wdBookId,
-                        });
-                    }
-                });
 
                 currentSeq.forEach(currentItem => {
                     const { wdBookId, wdCntId } = currentItem;
@@ -1285,31 +1274,15 @@
                     if (!this.isFirst) {
                         insertList.push({ wordBookId: wdBookId });
                     } else {
-                        // 현재 아이템의 wdCntId가 원본에 존재하는지 확인
-                        if (originalMap[wdCntId] !== undefined) {
-                            // 원본에 존재하는 경우
-                            const originalWdBookId = originalMap[wdCntId];
-
-                            if (originalWdBookId !== wdBookId) {
-                                // wdBookId가 변경된 경우 업데이트 리스트에 추가
-                                updateList.push({
-                                    wordContentId: wdCntId,
-                                    wordBookId: originalWdBookId, // 기존 wdBookId
-                                    NewWordBookId: wdBookId, // 새로운 wdBookId
-                                });
-                            }
-                        } else {
-                            // 원본에 존재하지 않는 경우
-                            let cntId = null;
-                            if (position === 1) {
-                                cntId = this.wordContentId1;
-                            } else if (position === 5) {
-                                cntId = this.wordContentId2;
-                            } else if (position === 9) {
-                                cntId = this.wordContentId3;
-                            }
-                            insertExistList.push({ wordBookId: wdBookId, wordContentId: cntId });
+                        let cntId = null;
+                        if (position === 1) {
+                            cntId = this.wordContentId1;
+                        } else if (position === 5) {
+                            cntId = this.wordContentId2;
+                        } else if (position === 9) {
+                            cntId = this.wordContentId3;
                         }
+                        insertExistList.push({ wordBookId: wdBookId, wordContentId: cntId });
                     }
                 });
 
@@ -1329,23 +1302,9 @@
                     });
                 }
 
-                // 필요 시에만 추가 요청 보내기
-                const promises = [];
                 if (insertExistList.length > 0) {
-                    promises.push(this.sendInsertExistRequest(insertExistList));
+                    await this.sendInsertExistRequest(insertExistList);
                 }
-                if (updateList.length > 0) {
-                    promises.push(this.sendUpdateRequest(updateList));
-                }
-                if (deleteList.length > 0) {
-                    promises.push(this.sendDeleteRequest(deleteList));
-                }
-
-                // 모든 요청을 병렬로 실행
-                if (promises.length > 0) {
-                    await Promise.all(promises);
-                }
-
             }
         },
 
@@ -1371,25 +1330,6 @@
             }
         },
 
-        // 데이터 업데이트 요청 보내기
-        async sendUpdateRequest(updateList) {
-            try {
-                const response = await axios.post("/wordContent/updateContent.json", updateList);
-                console.log("Update response:", response.data);
-            } catch (error) {
-                console.error("Error updating data:", error);
-            }
-        },
-
-        // 데이터 삭제 요청 보내기 
-        async sendDeleteRequest(deleteList) {
-            try {
-                const response = await axios.post("/wordContent/deleteContent.json", deleteList);
-                console.log("Delete response:", response.data);
-            } catch (error) {
-                console.error("Error deleting data:", error);
-            }
-        },
 
         // 로드맵 데이터 사용
         async postRoadMaps() {
@@ -1418,8 +1358,6 @@
             } else {
                 this.insertRoadData();
             }
-
-
         },
 
         // 로드맵 등록하기
@@ -1510,6 +1448,7 @@
                 .then(response => {
                     console.log(`Update successful:`, response.data);
                     if (response.data > 0) {
+                        this.postPrblmBookExist();
                     }
                 })
                 .catch(error => {
@@ -1564,6 +1503,76 @@
                     console.error("Error during registering problems:", error);
                 });
         },
+
+        // 로드맵 문제 수정
+        postPrblmBookExist() {
+            const changedProblemList = [];
+            const validPositions = [2, 3, 6]; // prblm_id가 있는 인덱스들
+
+            validPositions.forEach(position => {
+                const currentSeq = this.RoadMap[position] || [];
+                const originalSeq = this.OrginRoadMap[position] || [];
+
+                console.log('currentSeq:', currentSeq);
+                console.log('originalSeq:', originalSeq);
+                // 크기가 다를 경우, 모든 currentSeq 항목을 변경된 것으로 처리
+                if (currentSeq.length !== originalSeq.length) {
+                    currentSeq.forEach(currentItem => {
+                        let learningId = null;
+                        if (position === 2) {
+                            learningId = this.learningId1;
+                        } else if (position === 3) {
+                            learningId = this.learningId2;
+                        } else if (position === 6) {
+                            learningId = this.learningId3;
+                        }
+
+                        changedProblemList.push({
+                            learningId: learningId,
+                            prblmId: currentItem.prblmId,
+                        });
+                    });
+
+                } else {
+                    // 크기가 같은 경우, 기존 비교 로직을 그대로 적용
+                    currentSeq.forEach(currentItem => {
+                        const originalItem = originalSeq.find(item => item.prblmId === currentItem.prblmId);
+
+                        if (!originalItem || JSON.stringify(originalItem) !== JSON.stringify(currentItem)) {
+                            let learningId = null;
+                            if (position === 2) {
+                                learningId = this.learningId1;
+                            } else if (position === 3) {
+                                learningId = this.learningId2;
+                            } else if (position === 6) {
+                                learningId = this.learningId3;
+                            }
+
+                            changedProblemList.push({
+                                learningId: learningId,
+                                prblmId: currentItem.prblmId,
+                            });
+                        }
+                    });
+                }
+            });
+
+
+            // 변경된 문제가 있다면, 서버에 업데이트 요청
+            if (changedProblemList.length > 0) {
+                axios.post("/problemBook/registerExist.json", changedProblemList)
+                    .then(response => {
+                        console.log("Problems updated successfully:", response.data);
+                        this.fetchRoadmapData();
+                        alert("학습 로드맵 문제 수정이 완료되었습니다!");
+                    })
+                    .catch(error => {
+                        console.error("Error during updating problems:", error);
+                    });
+            } else {
+                console.log("No changes detected in prblm_id.");
+            }
+        },
     },
     watch: {
 
Add a comment
List