Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 18 additions & 19 deletions src/controllers/moment.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,6 @@ export const handleGetOtherUserMoments = async (req, res, next) => {









export const handleGetOtherUserMomentDetail = async (req, res, next) => {
/*
#swagger.tags = ['Moments']
Expand All @@ -296,29 +290,34 @@ export const handleGetOtherUserMomentDetail = async (req, res, next) => {
*/

try {
console.log("특정 사용자의 Moment 목록 조회 요청");

const userId = parseInt(req.params.userId, 10);
if (isNaN(userId)) {
throw new Error("유효하지 않은 사용자 ID입니다.");
}
const momentId = parseInt(req.params.momentId, 10);

const moments = await getOtherUserMoments(userId);
// 유효성 검사: NaN 체크
if (isNaN(userId) || isNaN(momentId)) {
throw new Error("유효하지 않은 사용자 ID 또는 Moment ID입니다.");
}

// 🔍 responseFromOtherUserMoments() 변환 결과 확인
const responseData = responseFromOtherUserMoments(moments);
console.log("Swagger 응답 데이터:", JSON.stringify(responseData, null, 2));
// getOtherUserMomentDetail을 호출하여 데이터를 가져옵니다.
const responseData = await getOtherUserMomentDetail(userId, momentId);

// 응답 데이터 반환
res.status(StatusCodes.OK).json({
resultType: "SUCCESS",
error: null,
success: {
data: responseData
}
success: { data: responseData }
});
} catch (error) {
console.error("특정 사용자의 Moment 목록 조회 오류:", error);
console.error("특정 사용자의 Moment 상세 조회 오류:", error);
next(error);
}
};









18 changes: 10 additions & 8 deletions src/dtos/moment.dto.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,28 +222,30 @@ export const responseFromOtherUserMoments = (moments) => {
};





// 친구의 Moment 상세 조회 DTO
export const responseFromOtherUserMomentDetail = (moment) => {
if (!moment || !moment.id) {
console.error("잘못된 moment 데이터:", moment);
return null;
}

return {
userId: moment.userId,
momentId: moment.id,
const transformedMoment = {
userId: Number(moment.userId), // BigInt를 Number로 변환
momentId: Number(moment.id), // BigInt를 Number로 변환
title: moment.title,
date: formatDate(moment.createdAt),
plannerId: moment.plannerId ?? null,
createdAt: formatDateTime(moment.createdAt),
updatedAt: formatDateTime(moment.updatedAt),
momentContents: moment.momentContents.map(content => ({
sortOrder: content.sortOrder,
sortOrder: Number(content.sortOrder), // BigInt를 Number로 변환
content: content.content,
url: content.url ?? null
}))
};

return transformedMoment;
};




2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ app.delete("/moments/:momentId", authenticateJWT, handleDeleteMoment); //모먼
app.get("/mypage/moments", authenticateJWT, handleGetMyMoments); //마이페이지에서 나의 moment게시글 목록 조회
app.get("/mypage/moments/:momentId", authenticateJWT, handleGetMyMomentDetail); //마이페이지에서 나의 특정 moment게시물 조회
app.get("/users/:userId/moments", authenticateJWT, handleGetOtherUserMoments) //친구페이지 moment게시물 목록 조회
app.get("/users/:userId/moments/momentId", authenticateJWT, handleGetOtherUserMomentDetail); //친구페이지 특정 moment게시물 조회
app.get("/users/:userId/moments/:momentId", authenticateJWT, handleGetOtherUserMomentDetail); //친구페이지 특정 moment게시물 조회



Expand Down
4 changes: 1 addition & 3 deletions src/repositories/moment.repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,9 @@ export const findOtherUserMoments = async (userId) => {
// 특정 사용자의 특정 Moment 상세 조회
export const findOtherUserMomentDetail = async (userId, momentId) => {
try {
console.log(`[findOtherUserMomentDetail] API 호출됨! userId: ${userId}, momentId: ${momentId}`);

const moment = await prisma.moment.findUnique({
where: { id: BigInt(momentId) },
where: { id: momentId }, // BigInt 대신 number로 직접 처리
include: {
momentContents: true,
planner: true
Expand All @@ -253,7 +252,6 @@ export const findOtherUserMomentDetail = async (userId, momentId) => {
if (!moment) {
throw new Error("Moment를 찾을 수 없습니다.");
}

return moment;
} catch (error) {
console.error("[findOtherUserMomentDetail] DB 조회 오류:", error.message);
Expand Down