@@ -3,16 +3,16 @@ import {
33 bodyToCreateMoment ,
44 bodyToUpdateMoment ,
55 responseFromMyMomentDetail ,
6- responseFromFriendsMoments ,
7- responseFromFriendMomentDetail } from "../dtos/moment.dto.js" ;
6+ responseFromOtherUserMoments ,
7+ responseFromOtherUserMomentDetail } from "../dtos/moment.dto.js" ;
88import {
99 momentCreate ,
1010 momentUpdate ,
1111 momentDelete ,
1212 getMyMoments ,
1313 getMyMomentDetail ,
14- getFriendsMoments ,
15- getFriendMomentDetail } from "../services/moment.service.js" ;
14+ getOtherUserMoments ,
15+ getOtherUserMomentDetail } from "../services/moment.service.js" ;
1616
1717
1818export const handleCreateMoment = async ( req , res , next ) => {
@@ -228,66 +228,83 @@ export const handleGetMyMomentDetail = async (req, res, next) => {
228228 }
229229} ;
230230
231+ export const handleGetOtherUserMoments = async ( req , res , next ) => {
232+ try {
231233
234+ // userId 확인: 잘못된 값이 전달되는지 확인
235+ const userId = Number ( req . params . userId ) ;
236+ console . log ( "Received userId from params:" , req . params . userId ) ; // 확인용 로그 추가
237+ if ( isNaN ( userId ) ) {
238+ throw new Error ( "유효하지 않은 사용자 ID입니다." ) ;
239+ }
232240
233- export const handleGetFriendsMoments = async ( req , res , next ) => {
234- /*
235- #swagger.tags = ['Moments']
236- #swagger.summary = '친구의 Moment 목록 조회 API'
237- #swagger.description = '친구의 페이지에서 해당 친구의 Moment 게시물 목록을 조회합니다.'
238- #swagger.security = [{
239- "bearerAuth": []
240- }]
241-
242- */
241+ // getOtherUserMoments 함수에서 userId 확인
242+ const responseData = await getOtherUserMoments ( userId ) ;
243243
244- try {
245- console . log ( "친구의 Moment 목록 조회 요청" ) ;
246- const friendId = parseInt ( req . params . friendId , 10 ) ;
247- const moments = await getFriendsMoments ( friendId ) ;
248244 res . status ( StatusCodes . OK ) . json ( {
249245 resultType : "SUCCESS" ,
250246 error : null ,
251- success : {
252- data : responseFromFriendsMoments ( moments )
253- }
247+ success : { data : responseData }
254248 } ) ;
249+
255250 } catch ( error ) {
251+ console . error ( "❌ 특정 사용자의 Moment 목록 조회 오류:" , error ) ;
256252 next ( error ) ;
257253 }
258254} ;
259255
260256
261- export const handleGetFriendMomentDetail = async ( req , res , next ) => {
257+
258+
259+
260+
261+
262+
263+
264+ export const handleGetOtherUserMomentDetail = async ( req , res , next ) => {
262265 /*
263266 #swagger.tags = ['Moments']
264- #swagger.summary = '친구의 특정 Moment 상세 조회 API'
265- #swagger.description = '친구의 페이지에서 특정 Moment 게시물의 상세 정보를 조회합니다.'
266- #swagger.security = [{
267- "bearerAuth": []
268- }]
267+ #swagger.summary = '특정 사용자의 특정 Moment 상세 조회 API'
268+ #swagger.description = '특정 사용자의 페이지에서 특정 Moment 게시물의 상세 정보를 조회합니다.'
269+ #swagger.security = [{ "bearerAuth": [] }]
270+ #swagger.parameters['userId'] = {
271+ in: "path",
272+ required: true,
273+ description: "조회할 사용자의 ID",
274+ schema: { type: "integer", example: 1234 }
275+ }
269276 #swagger.parameters['momentId'] = {
270277 in: "path",
271278 required: true,
272279 description: "조회할 Moment의 ID",
273280 schema: { type: "integer", example: 456 }
274281 }
275-
276282 */
277283
278284 try {
279- console . log ( "친구의 특정 Moment 상세 조회 요청" ) ;
280- const friendId = parseInt ( req . params . friendId , 10 ) ;
281- const momentId = parseInt ( req . params . momentId , 10 ) ;
282- const moment = await getFriendMomentDetail ( friendId , momentId ) ;
285+ console . log ( "특정 사용자의 Moment 목록 조회 요청" ) ;
286+
287+ const userId = parseInt ( req . params . userId , 10 ) ;
288+ if ( isNaN ( userId ) ) {
289+ throw new Error ( "유효하지 않은 사용자 ID입니다." ) ;
290+ }
291+
292+ const moments = await getOtherUserMoments ( userId ) ;
293+
294+ // 🔍 responseFromOtherUserMoments() 변환 결과 확인
295+ const responseData = responseFromOtherUserMoments ( moments ) ;
296+ console . log ( "Swagger 응답 데이터:" , JSON . stringify ( responseData , null , 2 ) ) ;
297+
283298 res . status ( StatusCodes . OK ) . json ( {
284299 resultType : "SUCCESS" ,
285300 error : null ,
286301 success : {
287- data : responseFromFriendMomentDetail ( moment )
302+ data : responseData
288303 }
289304 } ) ;
290305 } catch ( error ) {
306+ console . error ( "특정 사용자의 Moment 목록 조회 오류:" , error ) ;
291307 next ( error ) ;
292308 }
293- } ;
309+ } ;
310+
0 commit comments