From 220b3ef2d469030487f35a52b2a500e0a6adf03f Mon Sep 17 00:00:00 2001 From: hylee Date: Tue, 3 Sep 2024 18:09:42 +0900 Subject: [PATCH] =?UTF-8?q?=EC=8A=A4=ED=8C=B8=EB=8B=A8=EC=96=B4=20?= =?UTF-8?q?=EC=B2=B4=ED=81=AC=20=EB=93=9C=EB=A0=88=EA=B7=B8=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../itn/mjon/spam/web/RestSpamController.java | 51 ++++++++++++------- .../resources/templates/mjon/spam/select.html | 13 ++++- 2 files changed, 45 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/itn/admin/itn/mjon/spam/web/RestSpamController.java b/src/main/java/com/itn/admin/itn/mjon/spam/web/RestSpamController.java index f954a58..1fb1fcb 100644 --- a/src/main/java/com/itn/admin/itn/mjon/spam/web/RestSpamController.java +++ b/src/main/java/com/itn/admin/itn/mjon/spam/web/RestSpamController.java @@ -8,14 +8,12 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.nio.charset.StandardCharsets; +import java.util.Base64; @Slf4j @RestController @@ -35,22 +33,41 @@ public class RestSpamController { } // 키워드 -> 핵심키워드 :: keywords -> chc_keywords - @PutMapping("/mjon/spam/chcKeyword/{spamId}/{word}") - public ResponseEntity updateChcKeyword(@PathVariable String spamId, @PathVariable String word) { - /* try { - String decodedWord = URLDecoder.decode(word, StandardCharsets.UTF_8.toString()); - return ResponseEntity.ok().body(spamService.updateChcKeyword(spamId, decodedWord)); - } catch (UnsupportedEncodingException e) { - // 디코딩에 실패할 경우, 적절한 오류 응답을 보냅니다. - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new RestResponse("Invalid encoding")); - }*/ - return ResponseEntity.ok().body(spamService.updateChcKeyword(spamId, word)); + @PutMapping("/mjon/spam/chcKeyword/{spamId}/{encodedWord}") + public ResponseEntity updateChcKeyword(@PathVariable String spamId, @PathVariable String encodedWord) { + try { + System.out.println("Encoded Word from URL: " + encodedWord); // 인코딩된 단어 출력 + byte[] decodedBytes = Base64.getDecoder().decode(encodedWord); + String word = new String(decodedBytes, StandardCharsets.UTF_8); + System.out.println("Decoded Word: " + word); // 디코딩된 단어 출력 + + return ResponseEntity.ok().body(spamService.updateChcKeyword(spamId, word)); + } catch (IllegalArgumentException e) { + System.err.println("Base64 decoding error: " + e.getMessage()); + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new RestResponse("Invalid Base64 encoding")); + } catch (Exception e) { + System.err.println("General error: " + e.getMessage()); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new RestResponse("Server error")); + } +// return ResponseEntity.ok().body(spamService.updateChcKeyword(spamId, word)); } // 핵심키워드 -> 키워드 :: chc_keywords -> keywords - @PutMapping("/mjon/spam/keyword/{spamId}/{word}") - public ResponseEntity updateKeyword(@PathVariable String spamId, @PathVariable String word) { - return ResponseEntity.ok().body(spamService.updateKeyword(spamId, word)); + @PutMapping("/mjon/spam/keyword/{spamId}/{encodedWord}") + public ResponseEntity updateKeyword(@PathVariable String spamId, @PathVariable String encodedWord) { + try { + System.out.println("Encoded Word from URL: " + encodedWord); // 인코딩된 단어 출력 + byte[] decodedBytes = Base64.getDecoder().decode(encodedWord); + String word = new String(decodedBytes, StandardCharsets.UTF_8); + System.out.println("Decoded Word: " + word); // 디코딩된 단어 출력 + return ResponseEntity.ok().body(spamService.updateKeyword(spamId, word)); + } catch (IllegalArgumentException e) { + System.err.println("Base64 decoding error: " + e.getMessage()); + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new RestResponse("Invalid Base64 encoding")); + } catch (Exception e) { + System.err.println("General error: " + e.getMessage()); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new RestResponse("Server error")); + } } diff --git a/src/main/resources/templates/mjon/spam/select.html b/src/main/resources/templates/mjon/spam/select.html index d57f251..8acb0a0 100644 --- a/src/main/resources/templates/mjon/spam/select.html +++ b/src/main/resources/templates/mjon/spam/select.html @@ -253,6 +253,10 @@ // 선택된 텍스트가 있는 경우에만 실행 if (selectedText) { + + if(!confirm("\'" +selectedText+ "\' 단어를 등록 하시겠습니까?")){ + return false; + } console.log(selectedText); // 선택된 텍스트를 콘솔에 출력 // 핵심 단어 칼럼에 새로운 단어 버튼 추가 var spamId = $(this).closest('tr').find('button').first().data('spamid'); @@ -380,7 +384,9 @@ function fn_keywordUpdate(spamId, word){ // 한글이 포함된 word를 URL 인코딩합니다. - var encodedWord = encodeURIComponent(word); + var base64Word = btoa(unescape(encodeURIComponent(word))); // Base64 인코딩 + var encodedWord = encodeURIComponent(base64Word); // URL 인코딩 + $.ajax({ url: '/mjon/spam/keyword/' + spamId + '/' + encodedWord, type: 'PUT', @@ -397,7 +403,10 @@ function fn_chcKeywordUpdate(spamId, word){ // 한글이 포함된 word를 URL 인코딩합니다. - var encodedWord = encodeURIComponent(word); + // var encodedWord = encodeURIComponent(word); + var base64Word = btoa(unescape(encodeURIComponent(word))); // Base64 인코딩 + var encodedWord = encodeURIComponent(base64Word); // URL 인코딩 + console.log("Encoded Word:", encodedWord); // 인코딩된 단어 출력 $.ajax({ url: '/mjon/spam/chcKeyword/' + spamId + '/' + encodedWord, type: 'PUT',