From ea1cb9335cb3894d177f04b2f9af7bfd0bd94fcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EC=84=9D=20=EC=B5=9C?= Date: Fri, 3 Dec 2021 10:08:44 +0900 Subject: [PATCH] =?UTF-8?q?=EC=BD=94=EB=93=9C=EA=B4=80=EB=A6=AC=20?= =?UTF-8?q?=ED=8E=98=EC=9D=B4=EC=A7=80=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/adminController.java | 12 ++---- .../repository/CommonCodeRepository.java | 2 +- .../service/CommonCodeService.java | 2 +- src/main/resources/static/js/admin/codeMgt.js | 40 +++++++++++-------- .../resources/templates/admin/codeValue.html | 2 +- 5 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/dbnt/kcgfilemanager/controller/adminController.java b/src/main/java/com/dbnt/kcgfilemanager/controller/adminController.java index 89d354e..818ee7b 100644 --- a/src/main/java/com/dbnt/kcgfilemanager/controller/adminController.java +++ b/src/main/java/com/dbnt/kcgfilemanager/controller/adminController.java @@ -53,21 +53,15 @@ public class adminController { return mav; } - @PutMapping("/insertCode") + @PostMapping("/insertCode") public CommonCode insertCommonCode(CommonCode commonCode){ commonCodeService.insertCommonCode(commonCode); return commonCode; } - @PostMapping(value = "/deleteCode") + @PutMapping(value = "/deleteCode") @ResponseBody - public int deleteCommonCode( -// @RequestBody HashMap map -// @RequestBody CommonCode code - @RequestBody List codeList - ) { -// return map.size(); -// return code.getCodeSq(); + public int deleteCommonCode(@RequestBody List codeList) { commonCodeService.updateCommonCode(codeList); return codeList.size(); } diff --git a/src/main/java/com/dbnt/kcgfilemanager/repository/CommonCodeRepository.java b/src/main/java/com/dbnt/kcgfilemanager/repository/CommonCodeRepository.java index b2d0885..4c2a91a 100644 --- a/src/main/java/com/dbnt/kcgfilemanager/repository/CommonCodeRepository.java +++ b/src/main/java/com/dbnt/kcgfilemanager/repository/CommonCodeRepository.java @@ -8,5 +8,5 @@ import java.util.List; public interface CommonCodeRepository extends JpaRepository { - List findByCategory(String category); + List findByCategoryAndIsDeleted(String category, String isDeleted); } diff --git a/src/main/java/com/dbnt/kcgfilemanager/service/CommonCodeService.java b/src/main/java/com/dbnt/kcgfilemanager/service/CommonCodeService.java index ce5cccb..aa67aca 100644 --- a/src/main/java/com/dbnt/kcgfilemanager/service/CommonCodeService.java +++ b/src/main/java/com/dbnt/kcgfilemanager/service/CommonCodeService.java @@ -26,7 +26,7 @@ public class CommonCodeService { return commonCodeMapper.selectCommonCodeCategory(commonCode); } public List selectCommonCodeValue(CommonCode commonCode) { - return commonCodeRepository.findByCategory(commonCode.getCategory()); + return commonCodeRepository.findByCategoryAndIsDeleted(commonCode.getCategory(), "N"); } public void insertCommonCode(CommonCode commonCode) { commonCodeRepository.save(commonCode); diff --git a/src/main/resources/static/js/admin/codeMgt.js b/src/main/resources/static/js/admin/codeMgt.js index 5288131..94721fb 100644 --- a/src/main/resources/static/js/admin/codeMgt.js +++ b/src/main/resources/static/js/admin/codeMgt.js @@ -46,7 +46,7 @@ $(document).on('click', '#saveBtn', function (){ if(confirm("저장하시겠습니까?")){ const formData = new FormData($("#commonCodeForm")[0]); $.ajax({ - type : 'PUT', + type : 'POST', data : formData, url : "/admin/insertCode", processData: false, @@ -67,25 +67,33 @@ $(document).on('click', '#deleteCommonCodeBtn', function (){ const codeList = []; $(".valueCheckBox:checked").each(function (idx, el){ codeList.push({}); - codeList[idx].codeSq = Number(el.value); + const target = $(el); + codeList[idx].codeSq = Number(target.attr("data-codesq")); + codeList[idx].category = target.attr("data-category"); + codeList[idx].value = target.attr("data-value"); + codeList[idx].description = target.attr("data-description"); codeList[idx].isDeleted = 'Y'; }) - $.ajaxSettings.traditional = true; - $.ajax({ - type : 'POST', - url : "/admin/deleteCode", - data : JSON.stringify(codeList), - contentType: 'application/json', - beforeSend: function (xhr){ - xhr.setRequestHeader($("[name='_csrf_header']").val(), $("[name='_csrf']").val()); - }, - success : function(data) { - debugger - }, - error : function(xhr, status) { + if(codeList.length !== 0){ + if(confirm(codeList.length+"건을 삭제하시겠습니까?")){ + $.ajax({ + type : 'PUT', + url : "/admin/deleteCode", + data : JSON.stringify(codeList), + contentType: 'application/json', + beforeSend: function (xhr){ + xhr.setRequestHeader($("[name='_csrf_header']").val(), $("[name='_csrf']").val()); + }, + success : function(data) { + alert("삭제되었습니다."); + getValues($(".categoryCheckBox:checked").val()); + }, + error : function(xhr, status) { + } + }) } - }) + } }) function getValues(category){ diff --git a/src/main/resources/templates/admin/codeValue.html b/src/main/resources/templates/admin/codeValue.html index e019adb..3fe164c 100644 --- a/src/main/resources/templates/admin/codeValue.html +++ b/src/main/resources/templates/admin/codeValue.html @@ -14,7 +14,7 @@