-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from Romantic-Yeojido/develop
Develop
- Loading branch information
Showing
4 changed files
with
282 additions
and
254 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,78 +1,232 @@ | ||
// controllers/user.controller.js | ||
import { UserService } from "../services/user.service.js"; | ||
import { withdrawUser, getMyProfile } from "../services/user.service.js"; | ||
|
||
export class UserController { | ||
constructor() { | ||
this.userService = new UserService(); | ||
} | ||
|
||
async withdrawUser(req, res) { | ||
try { | ||
const userId = parseInt(req.params.userId); | ||
|
||
const result = await this.userService.withdrawUser(userId); | ||
|
||
return res.status(200).json({ | ||
success: true, | ||
message: "회원 탈퇴가 완료되었습니다.", | ||
}); | ||
} catch (error) { | ||
if (error.message === "존재하지 않는 사용자입니다.") { | ||
return res.status(404).json({ | ||
success: false, | ||
message: error.message, | ||
}); | ||
export const handleWithdrawUser = async (req, res, next) => { | ||
/* | ||
#swagger.path = '/api/v1/users/withdraw/{userId}' | ||
#swagger.method = 'patch' | ||
#swagger.summary = '회원 탈퇴 API' | ||
#swagger.description = '사용자 계정을 탈퇴. is_deleted 필드를 true로 변경합니다.' | ||
#swagger.parameters['userId'] = { | ||
in: 'path', | ||
description: '탈퇴할 사용자의 ID', | ||
required: true, | ||
type: 'integer', | ||
minimum: 1, | ||
example: 1 | ||
} | ||
#swagger.responses[200] = { | ||
description: '회원 탈퇴 성공', | ||
content: { | ||
"application/json": { | ||
schema: { | ||
type: "object", | ||
properties: { | ||
success: { | ||
type: "boolean", | ||
description: "탈퇴 처리 성공 여부", | ||
example: true | ||
}, | ||
message: { | ||
type: "string", | ||
description: "결과 메시지", | ||
example: "회원 탈퇴가 완료되었습니다." | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
#swagger.responses[404] = { | ||
description: '사용자를 찾을 수 없음', | ||
content: { | ||
"application/json": { | ||
schema: { | ||
type: "object", | ||
properties: { | ||
success: { | ||
type: "boolean", | ||
example: false | ||
}, | ||
message: { | ||
type: "string", | ||
example: "존재하지 않는 사용자입니다." | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
#swagger.responses[500] = { | ||
description: '서버 오류', | ||
content: { | ||
"application/json": { | ||
schema: { | ||
type: "object", | ||
properties: { | ||
success: { | ||
type: "boolean", | ||
example: false | ||
}, | ||
message: { | ||
type: "string", | ||
example: "회원 탈퇴 처리 중 오류가 발생했습니다." | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
*/ | ||
try { | ||
const userId = parseInt(req.params.userId); | ||
const result = await withdrawUser(userId); | ||
|
||
console.error("회원 탈퇴 중 오류 발생:", error); | ||
return res.status(500).json({ | ||
return res.status(200).json({ | ||
success: true, | ||
message: "회원 탈퇴가 완료되었습니다.", | ||
}); | ||
} catch (error) { | ||
if (error.message === "존재하지 않는 사용자입니다.") { | ||
return res.status(404).json({ | ||
success: false, | ||
message: "회원 탈퇴 처리 중 오류가 발생했습니다.", | ||
message: error.message, | ||
}); | ||
} | ||
|
||
console.error("회원 탈퇴 중 오류 발생:", error); | ||
return res.status(500).json({ | ||
success: false, | ||
message: "회원 탈퇴 처리 중 오류가 발생했습니다.", | ||
}); | ||
} | ||
async getMyProfile(req, res) { | ||
try { | ||
const userId = parseInt(req.params.userId); | ||
}; | ||
|
||
// 사용자 정보 조회 | ||
const userInfo = await this.userService.getMyProfile(userId); | ||
export const handleGetMyProfile = async (req, res, next) => { | ||
/* | ||
#swagger.path = '/api/v1/users/{userId}' | ||
#swagger.method = 'get' | ||
#swagger.summary = '마이페이지 조회 API' | ||
#swagger.description = '사용자의 기본 정보(이메일, 닉네임)를 조회합니다.' | ||
#swagger.parameters['userId'] = { | ||
in: 'path', | ||
description: '조회할 사용자의 ID', | ||
required: true, | ||
type: 'integer', | ||
minimum: 1, | ||
example: 1 | ||
} | ||
#swagger.responses[200] = { | ||
description: '정보 조회 성공', | ||
content: { | ||
"application/json": { | ||
schema: { | ||
type: "object", | ||
properties: { | ||
success: { | ||
type: "boolean", | ||
example: true | ||
}, | ||
data: { | ||
type: "object", | ||
properties: { | ||
email: { | ||
type: "string", | ||
example: "user123@kakao.com" | ||
}, | ||
nickname: { | ||
type: "string", | ||
example: "철수킴" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
#swagger.responses[404] = { | ||
description: '사용자를 찾을 수 없음', | ||
content: { | ||
"application/json": { | ||
schema: { | ||
type: "object", | ||
properties: { | ||
success: { | ||
type: "boolean", | ||
example: false | ||
}, | ||
message: { | ||
type: "string", | ||
example: "존재하지 않는 사용자입니다" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
*/ | ||
try { | ||
const userId = parseInt(req.params.userId); | ||
const userInfo = await getMyProfile(userId); | ||
|
||
return res.status(200).json({ | ||
success: true, | ||
data: userInfo, | ||
}); | ||
} catch (error) { | ||
console.error("사용자 정보 조회 중 오류 발생:", error); | ||
|
||
if (error.message === "존재하지 않는 사용자입니다") { | ||
return res.status(404).json({ | ||
success: false, | ||
message: error.message, | ||
}); | ||
} | ||
return res.status(200).json({ | ||
success: true, | ||
data: userInfo, | ||
}); | ||
} catch (error) { | ||
console.error("사용자 정보 조회 중 오류 발생:", error); | ||
|
||
return res.status(500).json({ | ||
if (error.message === "존재하지 않는 사용자입니다") { | ||
return res.status(404).json({ | ||
success: false, | ||
message: "사용자 정보 조회 중 오류가 발생했습니다", | ||
message: error.message, | ||
}); | ||
} | ||
|
||
return res.status(500).json({ | ||
success: false, | ||
message: "사용자 정보 조회 중 오류가 발생했습니다", | ||
}); | ||
} | ||
}; | ||
|
||
async logout(req, res) { | ||
try { | ||
// 실제 구현에서는 세션 삭제나 토큰 무효화 등의 작업이 필요 | ||
// 테스트를 위해 간단히 성공 응답만 반환 | ||
return res.status(200).json({ | ||
success: true, | ||
message: "로그아웃이 완료되었습니다", | ||
}); | ||
} catch (error) { | ||
console.error("로그아웃 중 오류 발생:", error); | ||
return res.status(500).json({ | ||
success: false, | ||
message: "로그아웃 처리 중 오류가 발생했습니다", | ||
}); | ||
} | ||
export const handleLogout = async (req, res, next) => { | ||
/* | ||
#swagger.path = '/api/v1/users/auth/logout' | ||
#swagger.method = 'post' | ||
#swagger.summary = '로그아웃 API' | ||
#swagger.description = '사용자 로그아웃 처리를 수행합니다.' | ||
#swagger.responses[200] = { | ||
description: '로그아웃 성공', | ||
content: { | ||
"application/json": { | ||
schema: { | ||
type: "object", | ||
properties: { | ||
success: { | ||
type: "boolean", | ||
example: true | ||
}, | ||
message: { | ||
type: "string", | ||
example: "로그아웃이 완료되었습니다" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
*/ | ||
try { | ||
return res.status(200).json({ | ||
success: true, | ||
message: "로그아웃이 완료되었습니다", | ||
}); | ||
} catch (error) { | ||
console.error("로그아웃 중 오류 발생:", error); | ||
return res.status(500).json({ | ||
success: false, | ||
message: "로그아웃 처리 중 오류가 발생했습니다", | ||
}); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,26 @@ | ||
// repositories/user.repository.js | ||
import { pool } from '../db.config.js'; | ||
import { pool } from "../db.config.js"; | ||
|
||
export class UserRepository { | ||
async findById(userId) { | ||
try { | ||
const [rows] = await pool.query( | ||
'SELECT * FROM users WHERE id = ?', | ||
[userId] | ||
); | ||
return rows[0]; | ||
} catch (error) { | ||
console.error('사용자 조회 중 오류:', error); | ||
throw error; | ||
} | ||
} | ||
export const findById = async (userId) => { | ||
try { | ||
const [rows] = await pool.query("SELECT * FROM users WHERE id = ?", [ | ||
userId, | ||
]); | ||
return rows[0]; | ||
} catch (error) { | ||
console.error("사용자 조회 중 오류:", error); | ||
throw error; | ||
} | ||
}; | ||
|
||
async softDeleteUser(userId) { | ||
try { | ||
const [result] = await pool.query( | ||
'UPDATE users SET is_deleted = true WHERE id = ?', | ||
[userId] | ||
); | ||
return result.affectedRows > 0; | ||
} catch (error) { | ||
console.error('회원 탈퇴 처리 중 오류:', error); | ||
throw error; | ||
} | ||
} | ||
} | ||
export const softDeleteUser = async (userId) => { | ||
try { | ||
const [result] = await pool.query( | ||
"UPDATE users SET is_deleted = true WHERE id = ?", | ||
[userId] | ||
); | ||
return result.affectedRows > 0; | ||
} catch (error) { | ||
console.error("회원 탈퇴 처리 중 오류:", error); | ||
throw error; | ||
} | ||
}; |
Oops, something went wrong.