-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
155 additions
and
114 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,12 +1,12 @@ | ||
import { | ||
DailyEmotionType, | ||
WeeklyEmotionSummaryType | ||
} from '@/shared/model/moodTypes'; | ||
DailyConditionType, | ||
WeeklyConditionSummaryType | ||
} from '@/shared/model/conditionTypes'; | ||
|
||
const isDailyEmotion = ( | ||
data: DailyEmotionType[] | WeeklyEmotionSummaryType[] | ||
): data is DailyEmotionType[] => { | ||
return (data as DailyEmotionType[])[0]?.day !== undefined; | ||
data: DailyConditionType[] | WeeklyConditionSummaryType[] | ||
): data is DailyConditionType[] => { | ||
return (data as DailyConditionType[])[0]?.day !== undefined; | ||
}; | ||
|
||
export default isDailyEmotion; |
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
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
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { createGptRequestQuery } from '../lib/createGptRequestQuery'; | ||
import { gptAnswerType, MoodDataType } from '../model/type'; | ||
import { fetchGptRecommend } from './fetchGptRecommend'; | ||
|
||
/** | ||
* 음악 아이텝을 반환합니다. | ||
* @param emotionData d | ||
* @param param1 | ||
* @returns | ||
*/ | ||
export const fetchMusicRecommendation = async ( | ||
emotionData: MoodDataType | null, | ||
{ | ||
onSuccess, | ||
onError, | ||
onValidationError | ||
}: { | ||
onSuccess: (data: gptAnswerType) => void; | ||
onError: () => void; | ||
onValidationError: () => void; | ||
} | ||
) => { | ||
if (!emotionData) { | ||
onValidationError(); | ||
return; | ||
} | ||
try { | ||
const requestQuery = createGptRequestQuery(emotionData); | ||
const recommendedMusic = await fetchGptRecommend(requestQuery); | ||
onSuccess(recommendedMusic); | ||
} catch (error) { | ||
onError(); | ||
throw error; | ||
} | ||
}; |
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,3 +1,8 @@ | ||
export { fetchGptRecommend } from './api/fetchGptRecommend'; | ||
export { youtubeSearch } from './api/fetchMusicList'; | ||
export { spotifySearch } from './api/fetchMusicList'; | ||
export { fetchMusicRecommendation } from './api/fetchMusicRecommendation'; | ||
export { useMusicSearch } from './hooks/useMusicSearch'; | ||
export { createGptRequestQuery } from './lib/createGptRequestQuery'; | ||
export { MusicCard } from './ui/MusicCard'; | ||
export { EmptyMusicCard } from './ui/EmptyMusicCard'; | ||
export { useMusicSearch } from './hooks/useMusicSearch'; |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { gptQueryParamsType, MoodDataType } from '../model/type'; | ||
|
||
// 테스트 다이러리 | ||
const INITIAL_DIARY = { | ||
title: '우울해', | ||
content: '너무 우울해서 빵샀어' | ||
}; | ||
|
||
/** | ||
* 감정데이터, 일기데이터를 조합해 쿼리 데이터를 생성 | ||
* @param emotionData | ||
* @returns | ||
*/ | ||
export const createGptRequestQuery = ( | ||
emotionData: MoodDataType | ||
): gptQueryParamsType => { | ||
return { | ||
title: INITIAL_DIARY.title, | ||
content: INITIAL_DIARY.content, | ||
...(emotionData?.mood && { mood: emotionData.mood }), | ||
...(emotionData?.emotion && { emotion: emotionData.emotion }), | ||
...(emotionData?.subEmotion && { | ||
subemotion: emotionData.subEmotion.filter( | ||
(emotion): emotion is string => emotion !== null | ||
) | ||
}) | ||
}; | ||
}; |
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
This file was deleted.
Oops, something went wrong.
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
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
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,7 +1,7 @@ | ||
import { EmotionType } from '@/shared/model/moodTypes'; | ||
import { ConditionType } from '@/shared/model/conditionTypes'; | ||
|
||
export interface MoodDataType { | ||
mood: EmotionType; | ||
mood: ConditionType; | ||
emotion: string | null; | ||
subEmotion: (string | null)[]; | ||
} |
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
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
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
18 changes: 9 additions & 9 deletions
18
src/shared/model/moodTypes.ts → src/shared/model/conditionTypes.ts
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,31 +1,31 @@ | ||
export type EmotionType = | ||
export type ConditionType = | ||
| '좋음' | ||
| '나쁨' | ||
| '보통' | ||
| '매우 좋음' | ||
| '매우 나쁨' | ||
| null; | ||
|
||
export interface DailyEmotionType { | ||
export interface DailyConditionType { | ||
day: 'Mon' | 'Tue' | 'Wed' | 'Thu' | 'Fri' | 'Sat' | 'Sun'; | ||
mood: EmotionType; | ||
mood: ConditionType; | ||
} | ||
|
||
export interface WeeklyDataType { | ||
period: string; | ||
mostFrequentEmotion: EmotionType; | ||
mostFrequentEmotion: ConditionType; | ||
frequency: number | null; | ||
allEmotions: DailyEmotionType[]; | ||
allEmotions: DailyConditionType[]; | ||
} | ||
|
||
export interface WeeklyEmotionSummaryType { | ||
export interface WeeklyConditionSummaryType { | ||
week: number; | ||
mostFrequentEmotion: EmotionType; | ||
mostFrequentEmotion: ConditionType; | ||
} | ||
|
||
export interface MonthlyDataType { | ||
period: string; | ||
weeklyResults: WeeklyEmotionSummaryType[]; | ||
weeklyResults: WeeklyConditionSummaryType[]; | ||
frequency: number | null; | ||
mostFrequentEmotion: EmotionType; | ||
mostFrequentEmotion: ConditionType; | ||
} |
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
Oops, something went wrong.