From 536d8496283046adf0122046d196adc04dc7a84f Mon Sep 17 00:00:00 2001 From: root Date: Fri, 4 Aug 2023 06:38:32 +0000 Subject: [PATCH] =?UTF-8?q?[feat]=20=EC=95=84=EC=9D=B4=EB=94=94=20?= =?UTF-8?q?=EC=B0=BE=EA=B8=B0=20API=20#2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/User/userController.js | 21 +++++++++++++++++++++ src/app/User/userDao.js | 7 ++++--- src/app/User/userProvider.js | 2 ++ src/app/User/userRoute.js | 3 +++ src/app/User/userService.js | 21 ++++++++++++++++++++- 5 files changed, 50 insertions(+), 4 deletions(-) diff --git a/src/app/User/userController.js b/src/app/User/userController.js index eb21bb0..e746fd5 100755 --- a/src/app/User/userController.js +++ b/src/app/User/userController.js @@ -112,6 +112,27 @@ exports.login = async function (req, res) { return res.send(signInResponse); }; +/** + * API No. 4 + * API Name : 아이디 찾기 API + * [GET] /users/auth/id/{userEmail} + */ +exports.findUserId = async function (req, res) { + + /** + * Path Variable: userEmail + */ + const userEmail = req.params.userEmail; + + if (!userEmail) return res.send(errResponse(baseResponse.USER_USEREMAIL_EMPTY)); + + const findUserIdResponse = await userService.findUserId(userEmail); + + console.log(findUserIdResponse); + + return res.send(findUserIdResponse); +}; + /** * API No. 5 diff --git a/src/app/User/userDao.js b/src/app/User/userDao.js index a1fb3ba..a86d1d9 100755 --- a/src/app/User/userDao.js +++ b/src/app/User/userDao.js @@ -11,11 +11,12 @@ async function selectUser(connection) { // 이메일로 회원 조회 async function selectUserEmail(connection, email) { const selectUserEmailQuery = ` - SELECT email, nickname - FROM UserInfo - WHERE email = ?; + SELECT EMAIL, UserId + FROM User_Personal + WHERE EMAIL = ?; `; const [emailRows] = await connection.query(selectUserEmailQuery, email); + return emailRows; } diff --git a/src/app/User/userProvider.js b/src/app/User/userProvider.js index aaf9ccc..cdb28fa 100755 --- a/src/app/User/userProvider.js +++ b/src/app/User/userProvider.js @@ -34,6 +34,8 @@ exports.retrieveUser = async function (userId) { exports.emailCheck = async function (email) { const connection = await pool.getConnection(async (conn) => conn); const emailCheckResult = await userDao.selectUserEmail(connection, email); + + console.log(`추가된 회원 : ${emailCheckResult}`); connection.release(); return emailCheckResult; diff --git a/src/app/User/userRoute.js b/src/app/User/userRoute.js index 97d163d..f5a4d6f 100755 --- a/src/app/User/userRoute.js +++ b/src/app/User/userRoute.js @@ -14,6 +14,9 @@ module.exports = function(app){ // 3. 특정 유저 조회 API app.get('/app/users/:userId', user.getUserById); + // 4. 아이디 찾기 API + app.get('/users/auth/id/:userEmail', user.findUserId); + // TODO: After 로그인 인증 방법 (JWT) // 로그인 하기 API (JWT 생성) diff --git a/src/app/User/userService.js b/src/app/User/userService.js index 3c443fe..934186f 100755 --- a/src/app/User/userService.js +++ b/src/app/User/userService.js @@ -109,4 +109,23 @@ exports.editUser = async function (id, nickname) { logger.error(`App - editUser Service error\n: ${err.message}`); return errResponse(baseResponse.DB_ERROR); } -} \ No newline at end of file +} + +exports.findUserId = async function (email) { + try { + // 해당 이메일에 관한 유저가 있는지 확인 + const emailRows = await userProvider.emailCheck(email); + + if (emailRows.length == 0) + return errResponse(baseResponse.USER_USEREMAIL_NOT_EXIST); + + let userId=emailRows[0].UserId; + + return response(baseResponse.SUCCESS, {'userEmail': email, 'userId': userId}); + + + } catch (err) { + logger.error(`App - createUser Service error\n: ${err.message}`); + return errResponse(baseResponse.DB_ERROR); + } +}; \ No newline at end of file