From 3f423bfbfe42bb37fe670b3759453b35b6e9f968 Mon Sep 17 00:00:00 2001 From: suhwan2004 Date: Sun, 3 Nov 2024 23:51:59 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=ED=94=BC=EB=93=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95,=20=EC=9E=91=EC=84=B1=20handler=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/mocks/handlers/feed.ts | 69 +++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 2 deletions(-) diff --git a/src/app/mocks/handlers/feed.ts b/src/app/mocks/handlers/feed.ts index c3e964b..a61f352 100644 --- a/src/app/mocks/handlers/feed.ts +++ b/src/app/mocks/handlers/feed.ts @@ -1,17 +1,28 @@ import { http } from 'msw'; +import { feedMockData } from '../data'; import { createHttpErrorResponse, createHttpSuccessResponse } from '../lib'; -interface IReportFeedReqDto { +interface IReportFeedReqDTO { category: string; content: string; isBlind: boolean; } + +interface IWriteFeedReqDTO { + content: string; + images: string[]; + scope: TFeedScope; +} + +type TFeedScope = 'public' | 'friends' | 'private'; + export const feedHandlers = [ + // 1️⃣ 피드 신고 http.post('http://api.example.com/v2/feeds/:feedId/reports', async ({ request, params }) => { const { feedId } = params; - const { category, content } = (await request.json()) as IReportFeedReqDto; + const { category, content } = (await request.json()) as IReportFeedReqDTO; if (!feedId || !category || !content) { return createHttpErrorResponse('피드 ID, 신고 카테고리, 컨텐츠가 다 입력되어야 합니다.'); @@ -21,4 +32,58 @@ export const feedHandlers = [ isReported: true, }); }), + + // 2️⃣ 피드 작성 + http.post('http://api.example.com/v2/feeds', async ({ request }) => { + const { content, images, scope } = (await request.json()) as IWriteFeedReqDTO; + + if (!content) { + return createHttpErrorResponse('피드 등록을 위해 컨텐츠를 작성해야 합니다.'); + } else if (!scope) { + return createHttpErrorResponse('피드 등록을 위해 공개 범위를 설정해야 합니다.'); + } + + feedMockData.push({ + id: feedMockData.length + 1, + user: { ...feedMockData[feedMockData.length - 1].user }, + content, + images: images.map((url, index) => ({ id: index + 1, imageUrl: url })), + likeCount: 0, + commentCount: 0, + isLiked: false, + isBookmarked: false, + isBlinded: false, + createdAt: new Date().toISOString(), + updatedAt: new Date().toISOString(), + }); + + return createHttpSuccessResponse({}); + }), + + // 3️⃣ 피드 수정 + http.put('http://api.example.com/v2/feeds/:feedId', async ({ request, params }) => { + const { feedId } = params; + + const { content, images, scope } = (await request.json()) as IWriteFeedReqDTO; + + if (!content) { + return createHttpErrorResponse('피드 수정을 위해 컨텐츠를 작성해야 합니다.'); + } else if (!scope) { + return createHttpErrorResponse('피드 수정을 위해 공개 범위를 설정해야 합니다.'); + } + + feedMockData.forEach((feed) => { + const numFeedId = +feedId; + if (feed.id === numFeedId) { + feedMockData[numFeedId] = { + ...feedMockData[numFeedId], + content, + images: images.map((url, index) => ({ id: index + 1, imageUrl: url })), + updatedAt: new Date().toISOString(), + }; + } + }); + + return createHttpSuccessResponse({}); + }), ]; From bc165ca55c7c9a9098ef96b2867b38aeed356fb1 Mon Sep 17 00:00:00 2001 From: suhwan2004 Date: Mon, 4 Nov 2024 00:16:16 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=ED=94=BC=EB=93=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95,=20=EC=9E=91=EC=84=B1=20Request=20DTO=EB=A5=BC=20enti?= =?UTF-8?q?ties/feed/model/types.ts=20=EC=97=90=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/mocks/handlers/feed.ts | 16 ++-------------- src/entities/feed/index.ts | 1 + src/entities/feed/model/index.ts | 1 + src/entities/feed/model/types.ts | 13 +++++++++++++ 4 files changed, 17 insertions(+), 14 deletions(-) create mode 100644 src/entities/feed/index.ts create mode 100644 src/entities/feed/model/index.ts create mode 100644 src/entities/feed/model/types.ts diff --git a/src/app/mocks/handlers/feed.ts b/src/app/mocks/handlers/feed.ts index a61f352..e50dd5c 100644 --- a/src/app/mocks/handlers/feed.ts +++ b/src/app/mocks/handlers/feed.ts @@ -1,22 +1,10 @@ import { http } from 'msw'; +import { IReportFeedReqDTO, IWriteFeedReqDTO } from '@/entities/feed'; + import { feedMockData } from '../data'; import { createHttpErrorResponse, createHttpSuccessResponse } from '../lib'; -interface IReportFeedReqDTO { - category: string; - content: string; - isBlind: boolean; -} - -interface IWriteFeedReqDTO { - content: string; - images: string[]; - scope: TFeedScope; -} - -type TFeedScope = 'public' | 'friends' | 'private'; - export const feedHandlers = [ // 1️⃣ 피드 신고 http.post('http://api.example.com/v2/feeds/:feedId/reports', async ({ request, params }) => { diff --git a/src/entities/feed/index.ts b/src/entities/feed/index.ts new file mode 100644 index 0000000..9f8ccad --- /dev/null +++ b/src/entities/feed/index.ts @@ -0,0 +1 @@ +export * from './model'; diff --git a/src/entities/feed/model/index.ts b/src/entities/feed/model/index.ts new file mode 100644 index 0000000..fcb073f --- /dev/null +++ b/src/entities/feed/model/index.ts @@ -0,0 +1 @@ +export * from './types'; diff --git a/src/entities/feed/model/types.ts b/src/entities/feed/model/types.ts new file mode 100644 index 0000000..800c871 --- /dev/null +++ b/src/entities/feed/model/types.ts @@ -0,0 +1,13 @@ +export interface IReportFeedReqDTO { + category: string; + content: string; + isBlind: boolean; +} + +export interface IWriteFeedReqDTO { + content: string; + images: string[]; + scope: TFeedScope; +} + +export type TFeedScope = 'public' | 'friends' | 'private';