From 9802f52860c0a7add7e87cacbc08ee988b22c06f Mon Sep 17 00:00:00 2001 From: grulla79 Date: Tue, 9 Jul 2024 23:23:29 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=94=A5=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EC=BD=94=EB=93=9C=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/routes/user/user.service.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/routes/user/user.service.js b/src/routes/user/user.service.js index 53fb77e..f1a1ae1 100644 --- a/src/routes/user/user.service.js +++ b/src/routes/user/user.service.js @@ -83,7 +83,6 @@ exports.updateRequest = async (requestId, formData) => { exports.updateRequestState = async (userId, requestId, status, formData, requestType) => { if (userId) { - console.log("업데이트 서비스 진입!!!!!!!!!!!!", userId, requestId, status, formData, requestType) await userRepository.updateRequestState(userId, requestId, status, formData); if (requestType === 'add') { await wordRepository.addWord(requestId, formData); From 4dff4d55516977803aed5978392d541cf10e045a Mon Sep 17 00:00:00 2001 From: grulla79 Date: Thu, 11 Jul 2024 15:45:04 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9C=A8=EB=8B=A8=EC=96=B4=EB=93=B1?= =?UTF-8?q?=EB=A1=9D=20=EC=A4=91=EB=B3=B5=EA=B2=80=EC=82=AC=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/constants/error-message.js | 2 ++ src/common/constants/success-message.js | 3 +++ src/routes/word/word.controller.js | 28 +++++++++++++++++++++++++ src/routes/word/word.repository.js | 12 +++++++++++ src/routes/word/word.route.js | 5 ++++- src/routes/word/word.service.js | 7 +++++++ 6 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/common/constants/error-message.js b/src/common/constants/error-message.js index 0261a19..839b136 100644 --- a/src/common/constants/error-message.js +++ b/src/common/constants/error-message.js @@ -34,6 +34,8 @@ const ErrorMessage = Object.freeze({ RANK_WORDS_ERROR: '인기 검색어 조회 중 오류가 발생하였습니다.', RELATED_WORDS_ERROR: '연관 검색어 조회 중 오류가 발생하였습니다.', REGISTER_WORDS_ERROR: '등록 요청 중 오류가 발생하였습니다.', + EXIST_WORD: '이미 존재하는 단어입니다.', + CHECK_DUPLICATE_WORD_ERROR: '단어 중복검사중 오류가 발생하였습니다.', // REQUEST GET_REQUESTS_ERROR: '요청 조회중 오류가 발생하였습니다.', diff --git a/src/common/constants/success-message.js b/src/common/constants/success-message.js index e9575e3..be55de1 100644 --- a/src/common/constants/success-message.js +++ b/src/common/constants/success-message.js @@ -34,6 +34,9 @@ const SuccessMessage = Object.freeze({ // Word - 등록요청 REGISTER_WORDS_SUCCESS: '등록 요청 성공', + + // Word - 중복검사 + CHECK_DUPLICATE_REQUEST_SUCCESS: '중복 검사 성공', }); module.exports = SuccessMessage; diff --git a/src/routes/word/word.controller.js b/src/routes/word/word.controller.js index fc0c60e..74e0dd0 100644 --- a/src/routes/word/word.controller.js +++ b/src/routes/word/word.controller.js @@ -87,3 +87,31 @@ exports.getAllWords = async (req, res) => { sendResponse.fail(req, res, ErrorMessage.GET_WORDS_ERROR); } }; + +// 등록요청 중복 단어 검사 +exports.checkDuplicateWord = async (req, res) => { + try { + const { word } = req.body; // req.body 에서 word 추출 + console.log("전달된 중복 검수 단어", ); + const isDataExist = await wordService.checkDuplicateWord(word); + data = { isDataExist }; + console.log("중복검수 결과", data); + + // 중복 단어가 있는 경우 + if (isDataExist) { + return sendResponse.ok(res, { + message: ErrorMessage.EXIST_WORD, + data, + }); + } + // 중복 단어가 없는 경우 + return sendResponse.ok(res, { + message: SuccessMessage.CHECK_DUPLICATE_REQUEST_SUCCESS, + data, + }); + + } catch (error) { + sendResponse.fail(req, res, ErrorMessage.CHECK_DUPLICATE_REQUEST_ERROR); + } +} + diff --git a/src/routes/word/word.repository.js b/src/routes/word/word.repository.js index ec7ad47..c5cb8dd 100644 --- a/src/routes/word/word.repository.js +++ b/src/routes/word/word.repository.js @@ -140,3 +140,15 @@ exports.updateWord = async (requestId, formData) => { return null; } }; + +exports.checkDuplicateWord = async (word) => { + try { + const wordExists = await Word.findOne({ word: { $regex: new RegExp(`^${word}$`, 'i') } }); + console.log('wordExists:', wordExists); + return wordExists; + } + catch (error) { + console.log('Error while checking duplicate word:', error); + return null; + } +} \ No newline at end of file diff --git a/src/routes/word/word.route.js b/src/routes/word/word.route.js index 979c4f7..0bbf5f1 100644 --- a/src/routes/word/word.route.js +++ b/src/routes/word/word.route.js @@ -1,7 +1,7 @@ const express = require('express'); const wordRouter = express.Router(); const { isUser } = require('../../common/utils/auth'); -const { getRankWords, getSearchWords, getRelatedWords, getAllWords } = require('./word.controller'); +const { getRankWords, getSearchWords, getRelatedWords, getAllWords, checkDuplicateWord } = require('./word.controller'); // 전체 단어 목록 (쿼리 스트링에 정렬 & 페이지 정보) wordRouter.get('/', getAllWords); @@ -13,5 +13,8 @@ wordRouter.get('/search/related', getRelatedWords); // 검색어 조회 wordRouter.post('/search/:searchTerm', isUser, getSearchWords); +//등록요청 단어 중복검사 +wordRouter.post('/checkDuplicateWord', checkDuplicateWord); + module.exports = wordRouter; diff --git a/src/routes/word/word.service.js b/src/routes/word/word.service.js index 362097a..c4d10e3 100644 --- a/src/routes/word/word.service.js +++ b/src/routes/word/word.service.js @@ -23,3 +23,10 @@ exports.getAllWords = async (sort, page, limit) => { const words = await wordRepository.getAllWords(sort, page, limit); return words; }; + +// 등록 단어 중복 검사 +exports.checkDuplicateWord = async (word) => { + const isDuplicate = await wordRepository.checkDuplicateWord(word); + console.log("isDuplicate: ", isDuplicate) + return isDuplicate; +};