diff --git a/src/common/swagger/user.json b/src/common/swagger/user.json index 5d32a60..3d45f0d 100644 --- a/src/common/swagger/user.json +++ b/src/common/swagger/user.json @@ -177,7 +177,41 @@ "userId":{"type":"string", "example":"7"}, "nickname":{"type":"string", "example":"탱"}, "profileImage":{"type": ["string", null], "example":null}, - "description":{"type":"string", "example":"."} + "description":{"type":"string", "example":"."}, + "badges":{ + "type":"array", + "items":{ + "properties":{ + "id":{"type":"string", "example":"1"}, + "earnedAt":{"type":"string", "example":"2025-08-10T05:16:02.000Z"}, + "badge":{ + "type":"array", + "items":{ + "properties":{ + "id":{"type":"string", "example":"1"}, + "type":{"type":"string", "example":"follow"}, + "threshold":{"type":"integer", "example":5}, + "name":{"type":"string", "example":"팔로워 5명 달성"}, + "badgeImage":{"type":"string", "example":"null"} + } + } + }, + "reviews":{ + "type":"array", + "items":{ + "properties":{ + "id":{"type":"integer", "example":101}, + "requestId":{"type":"integer", "example":77}, + "rate":{"type":"integer", "example":5}, + "content":{"type":"string", "example":"좋았습니다"}, + "createdAt":{"type":"string", "example":"2025-08-09T12:30:00.000Z"}, + "updatedAt":{"type":"string", "example":"2025-08-09T12:30:00.000Z"} + } + } + } + } + } + } } } } diff --git a/src/user/controller/user.controller.js b/src/user/controller/user.controller.js index 11a1b96..1186433 100644 --- a/src/user/controller/user.controller.js +++ b/src/user/controller/user.controller.js @@ -48,10 +48,12 @@ export const getUserProfile = async(req, res, next) => { const accountId = req.user.accountId; console.log("controller accountId -> ", accountId); + const userId = req.user.userId; + const role = req.user.role; console.log(role); - const result = await UserService.getUserProfile(accountId, role); + const result = await UserService.getUserProfile(accountId, userId, role); res.status(StatusCodes.OK).success(result); } catch(err){ diff --git a/src/user/repository/user.repository.js b/src/user/repository/user.repository.js index e8f7066..1728fcb 100644 --- a/src/user/repository/user.repository.js +++ b/src/user/repository/user.repository.js @@ -310,6 +310,21 @@ export const UserRepository = { } }); }, + // 사용자가 작성한 리뷰 조회 + async UserReviewList(userId) { + return await prisma.review.findMany({ + wehre : {useraId: userId}, + select:{ + id:true, + requestId:true, + rate: true, + content:true, + createddAt: true, + updatedAt: true, + }, + orderBy: {createdAt:"desc"}, + }); + } }; diff --git a/src/user/service/user.service.js b/src/user/service/user.service.js index 9aec154..85f2c3c 100644 --- a/src/user/service/user.service.js +++ b/src/user/service/user.service.js @@ -111,7 +111,7 @@ export const UserService = { } }, // 사용자 프로필 조회 - async getUserProfile(accountId, role) { + async getUserProfile(accountId, userId, role) { let result; @@ -128,6 +128,9 @@ export const UserService = { earnedAt: userBadge.earnedAt, badge: userBadge.badge })); + + const reviews = (await UserRepository.UserReviewList(userId)) ?? []; + return { @@ -137,7 +140,8 @@ export const UserService = { nickname: user.nickname, profileImage:user.profileImage, description: user.description, - badges + badges, + reviews } } } @@ -149,11 +153,10 @@ export const UserService = { console.log("userBadges 확인:", result.userBadges); - - const badges = result.userBadges.map(userBadge => ({ - id: userBadge.id, - earnedAt: userBadge.earnedAt, - badge: userBadge.badge + const badges = result.userBadges.map((userBadge) => ({ + id: userBadge.id, + earnedAt: userBadge.earnedAt, + badge: userBadge.badge? [userBadge.badge] : [] })); return {