@@ -727,9 +727,7 @@ async def create_diary_with_emotion_based_recommendation(
727727 return response_data
728728
729729
730- @router .get ("/{diary_id}" , response_model = DiaryResponse ,
731- summary = "일기 조회" ,
732- description = "특정 일기의 상세 정보를 조회합니다." )
730+ @router .get ("/{diary_id}" , response_model = DiaryResponse )
733731def get_diary (
734732 diary_id : int ,
735733 current_user : User = Depends (get_current_user ),
@@ -743,9 +741,26 @@ def get_diary(
743741 if not diary :
744742 raise HTTPException (status_code = 404 , detail = "일기를 찾을 수 없습니다." )
745743
746- return diary
744+ recommended_songs = db .query (RecommendedSong ).filter (
745+ RecommendedSong .diary_id == diary .id
746+ ).order_by (RecommendedSong .similarity_score .desc ()).all ()
747747
748- @router .get ("/diary/{diary_id}/recommended-songs" , response_model = List [RecommendSongResponse ],
748+ main_song = db .query (RecommendedSong ).get (diary .main_recommended_song_id )
749+
750+ return DiaryResponse (
751+ id = diary .id ,
752+ user_id = diary .user_id ,
753+ content = diary .content ,
754+ emotiontype_id = diary .emotiontype_id ,
755+ confidence = diary .confidence ,
756+ created_at = diary .created_at ,
757+ updated_at = diary .updated_at ,
758+ recommended_songs = recommended_songs ,
759+ main_recommend_song = main_song ,
760+ top_emotions = []
761+ )
762+
763+ @router .get ("/{diary_id}/recommended-songs" , response_model = List [RecommendSongResponse ],
749764 summary = "추천 노래 조회" ,
750765 description = "특정 일기에 대한 추천 노래 리스트를 조회합니다." )
751766def get_recommended_songs_by_diary (
@@ -770,9 +785,7 @@ def get_recommended_songs_by_diary(
770785
771786 return songs
772787
773- @router .get ("" , response_model = List [DiaryResponse ],
774- summary = "내 일기 목록 조회" ,
775- description = "로그인한 사용자가 작성한 모든 일기를 조회합니다." )
788+ @router .get ("" , response_model = List [DiaryResponse ], summary = "내 일기 목록 조회" , description = "로그인한 사용자가 작성한 모든 일기를 조회합니다." )
776789def get_all_diaries (
777790 current_user : User = Depends (get_current_user ),
778791 db : Session = Depends (get_db )
@@ -781,7 +794,28 @@ def get_all_diaries(
781794 Diary .user_id == current_user .id
782795 ).all ()
783796
784- return diaries
797+ results = []
798+ for diary in diaries :
799+ recommended_songs = db .query (RecommendedSong ).filter (
800+ RecommendedSong .diary_id == diary .id
801+ ).order_by (RecommendedSong .similarity_score .desc ()).all ()
802+
803+ main_song = db .query (RecommendedSong ).get (diary .main_recommended_song_id )
804+
805+ results .append (DiaryResponse (
806+ id = diary .id ,
807+ user_id = diary .user_id ,
808+ content = diary .content ,
809+ emotiontype_id = diary .emotiontype_id ,
810+ confidence = diary .confidence ,
811+ created_at = diary .created_at ,
812+ updated_at = diary .updated_at ,
813+ recommended_songs = recommended_songs ,
814+ main_recommend_song = main_song ,
815+ top_emotions = []
816+ ))
817+
818+ return results
785819
786820@router .put ("/{diary_id}" , response_model = DiaryResponse ,
787821 summary = "일기 수정" ,
0 commit comments