Skip to content

Commit

Permalink
FE-51 ๐Ÿ”จ ์˜ค๋Š˜์˜ ๊ฐ์ • ๊ด€๋ จ ์ˆ˜์ • (#115)
Browse files Browse the repository at this point in the history
* FE-51 ๐Ÿ”จ ๊ฐ์ • ์˜์–ด์ด๋ฆ„ ์ˆ˜์ •

* FE-51 ๐Ÿ”จ postEmotion ํ† ํฐ ์ œ๊ฑฐ
  • Loading branch information
newjinlee authored Jul 30, 2024
1 parent 1c80963 commit c7f2191
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 25 deletions.
11 changes: 1 addition & 10 deletions src/apis/postEmotion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,12 @@ import { EmotionType } from '@/types/emotion';
import type { PostEmotionRequestType, PostEmotionResponseType } from '@/schema/emotion';
import { translateEmotionToEnglish } from '@/utils/emotionMap';
import httpClient from '.';
import { getMe } from './user';

const postEmotion = async (emotion: EmotionType): Promise<PostEmotionResponseType> => {
const user = await getMe();
if (!user) {
throw new Error('๋กœ๊ทธ์ธ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.');
}

const englishEmotion = translateEmotionToEnglish(emotion);
const request: PostEmotionRequestType = { emotion: englishEmotion };

const response = await httpClient.post<PostEmotionResponseType>('/emotionLogs/today', {
...request,
userId: user.id,
});
const response = await httpClient.post<PostEmotionResponseType>('/emotionLogs/today', request);

return response.data;
};
Expand Down
6 changes: 3 additions & 3 deletions src/schema/emotion.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import * as z from 'zod';

export const PostEmotionRequest = z.object({
emotion: z.enum(['MOVED', 'JOY', 'WORRY', 'SADNESS', 'ANGER']),
emotion: z.enum(['MOVED', 'HAPPY', 'WORRIED', 'SAD', 'ANGRY']),
});

export const PostEmotionResponse = z.object({
createdAt: z.coerce.date(),
emotion: z.enum(['MOVED', 'JOY', 'WORRY', 'SADNESS', 'ANGER']),
emotion: z.enum(['MOVED', 'HAPPY', 'WORRIED', 'SAD', 'ANGRY']),
userId: z.number(),
id: z.number(),
});

export const GetEmotionResponse = z.object({
createdAt: z.coerce.date(),
emotion: z.enum(['MOVED', 'JOY', 'WORRY', 'SADNESS', 'ANGER']),
emotion: z.enum(['MOVED', 'HAPPY', 'WORRIED', 'SAD', 'ANGRY']),
userId: z.number(),
id: z.number(),
});
Expand Down
24 changes: 12 additions & 12 deletions src/utils/emotionMap.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { EmotionType } from '@/types/emotion';

const emotionMap: Record<EmotionType, 'MOVED' | 'JOY' | 'WORRY' | 'SADNESS' | 'ANGER'> = {
const emotionMap: Record<EmotionType, 'MOVED' | 'HAPPY' | 'WORRIED' | 'SAD' | 'ANGRY'> = {
๊ฐ๋™: 'MOVED',
๊ธฐ์จ: 'JOY',
๊ณ ๋ฏผ: 'WORRY',
์Šฌํ””: 'SADNESS',
๋ถ„๋…ธ: 'ANGER',
๊ธฐ์จ: 'HAPPY',
๊ณ ๋ฏผ: 'WORRIED',
์Šฌํ””: 'SAD',
๋ถ„๋…ธ: 'ANGRY',
};

const reverseEmotionMap: Record<'MOVED' | 'JOY' | 'WORRY' | 'SADNESS' | 'ANGER', EmotionType> = {
const reverseEmotionMap: Record<'MOVED' | 'HAPPY' | 'WORRIED' | 'SAD' | 'ANGRY', EmotionType> = {
MOVED: '๊ฐ๋™',
JOY: '๊ธฐ์จ',
WORRY: '๊ณ ๋ฏผ',
SADNESS: '์Šฌํ””',
ANGER: '๋ถ„๋…ธ',
HAPPY: '๊ธฐ์จ',
WORRIED: '๊ณ ๋ฏผ',
SAD: '์Šฌํ””',
ANGRY: '๋ถ„๋…ธ',
};

const translateEmotionToEnglish = (emotion: EmotionType): 'MOVED' | 'JOY' | 'WORRY' | 'SADNESS' | 'ANGER' => emotionMap[emotion];
const translateEmotionToEnglish = (emotion: EmotionType): 'MOVED' | 'HAPPY' | 'WORRIED' | 'SAD' | 'ANGRY' => emotionMap[emotion];

const translateEmotionToKorean = (emotion: 'MOVED' | 'JOY' | 'WORRY' | 'SADNESS' | 'ANGER'): EmotionType => reverseEmotionMap[emotion];
const translateEmotionToKorean = (emotion: 'MOVED' | 'HAPPY' | 'WORRIED' | 'SAD' | 'ANGRY'): EmotionType => reverseEmotionMap[emotion];

export { translateEmotionToEnglish, translateEmotionToKorean };

0 comments on commit c7f2191

Please sign in to comment.