diff --git a/src/app/mocks/handlers/feed.ts b/src/app/mocks/handlers/feed.ts index 60a3b1d..968bf94 100644 --- a/src/app/mocks/handlers/feed.ts +++ b/src/app/mocks/handlers/feed.ts @@ -1,37 +1,47 @@ import { http } from 'msw'; -import { IReportFeedReqDTO, IWriteFeedReqDTO } from '@/entities/feed'; +import { + IModifyFeedParamsDTO, + IReportFeedParamsDTO, + IReportFeedReqDTO, + IReportFeedResDTO, + TModifyFeedReqDTO, + TWriteFeedReqDTO, +} from '@/entities/feed'; import { feedMockData } from '../data'; import { createHttpErrorResponse, createHttpSuccessResponse } from '../lib'; export const feedHandlers = [ // 1️⃣ 피드 신고 - http.post('http://api.example.com/v2/feeds/:feedId/reports', async ({ request, params }) => { - const { feedId } = params; + http.post( + 'http://api.example.com/v2/feeds/:feedId/reports', + async ({ request, params }) => { + const { feedId } = params; - const { category, isBlind } = (await request.json()) as IReportFeedReqDTO; + const { category, isBlind } = (await request.json()) as IReportFeedReqDTO; - if (!feedId || !category) { - return createHttpErrorResponse('피드 ID, 신고 카테고리가 필수로 입력되어야 합니다.'); - } + if (!feedId || !category) { + return createHttpErrorResponse('피드 ID, 신고 카테고리가 필수로 입력되어야 합니다.'); + } - if (isBlind) { - feedMockData.forEach((cur) => { - if (cur.id === +feedId) { - cur.isBlinded = true; - } - }); - } + if (isBlind) { + feedMockData.forEach((cur) => { + if (cur.id === +feedId) { + cur.isBlinded = true; + } + }); + } - return createHttpSuccessResponse({ - isReported: true, - }); - }), + return createHttpSuccessResponse({ + isReported: true, + }); + }, + ), // 2️⃣ 피드 작성 http.post('http://api.example.com/v2/feeds', async ({ request }) => { - const { content, images, scope } = (await request.json()) as IWriteFeedReqDTO; + const { content, images, scope } = (await request.json()) as TWriteFeedReqDTO; if (!content) { return createHttpErrorResponse('피드 등록을 위해 컨텐츠를 작성해야 합니다.'); @@ -57,29 +67,32 @@ export const feedHandlers = [ }), // 3️⃣ 피드 수정 - http.put('http://api.example.com/v2/feeds/:feedId', async ({ request, params }) => { - const { feedId } = params; + http.put( + 'http://api.example.com/v2/feeds/:feedId', + async ({ request, params }) => { + const { feedId } = params; - const { content, images, scope } = (await request.json()) as IWriteFeedReqDTO; + const { content, images, scope } = (await request.json()) as TModifyFeedReqDTO; - 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(), - }; + if (!content) { + return createHttpErrorResponse('피드 수정을 위해 컨텐츠를 작성해야 합니다.'); + } else if (!scope) { + return createHttpErrorResponse('피드 수정을 위해 공개 범위를 설정해야 합니다.'); } - }); - return createHttpSuccessResponse({}); - }), + 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({}); + }, + ), ]; diff --git a/src/app/mocks/handlers/hide.ts b/src/app/mocks/handlers/hide.ts new file mode 100644 index 0000000..20a7cb3 --- /dev/null +++ b/src/app/mocks/handlers/hide.ts @@ -0,0 +1,53 @@ +import { http } from 'msw'; + +import { + ICancelHideFeedParamsDTO, + ICancelHideResDTO, + IHideFeedParamsDTO, + IHideFeedResDTO, +} from '@/features/hideFeed'; + +import { feedMockData } from '../data'; +import { createHttpErrorResponse, createHttpSuccessResponse } from '../lib'; + +export const feedHandlers = [ + // 1️⃣ 피드 숨기기 + http.put( + 'http://api.example.com/v2/feeds/:feedId/hides', + async ({ params }) => { + const { feedId } = params; + + if (!feedId) { + return createHttpErrorResponse('피드 ID가 입력되어야 합니다.'); + } + + feedMockData.forEach((cur) => { + if (cur.id === +feedId) cur.isBlinded = true; + }); + + return createHttpSuccessResponse({ + isHidden: true, + }); + }, + ), + + // 2️⃣ 피드 숨기기 취소 + http.delete( + 'http://api.example.com/v2/feeds/:feedId/hides', + async ({ params }) => { + const { feedId } = params; + + if (!feedId) { + return createHttpErrorResponse('피드 ID가 입력되어야 합니다.'); + } + + feedMockData.forEach((cur) => { + if (cur.id === +feedId) cur.isBlinded = false; + }); + + return createHttpSuccessResponse({ + isHidden: false, + }); + }, + ), +]; diff --git a/src/app/mocks/handlers/search.ts b/src/app/mocks/handlers/search.ts index 04a2b65..0384192 100644 --- a/src/app/mocks/handlers/search.ts +++ b/src/app/mocks/handlers/search.ts @@ -1,6 +1,9 @@ import Fuse from 'fuse.js'; import { http } from 'msw'; +import { ISearchFeedResDTO } from '@/features/searchFeed'; +import { ISearchUserResDTO } from '@/features/searchUser'; + import { feedMockData, userMockData } from '../data'; import { createHttpErrorResponse, createHttpSuccessResponse } from '../lib'; @@ -28,7 +31,7 @@ export const searchHandlers = [ const totalFeeds = contents.length; const hasNextPage = totalFeeds > page * size; - return createHttpSuccessResponse({ + return createHttpSuccessResponse({ feed: { contents, currentPageNumber: page, @@ -62,7 +65,7 @@ export const searchHandlers = [ const totalFeeds = contents.length; const hasNextPage = totalFeeds > page * size; - return createHttpSuccessResponse({ + return createHttpSuccessResponse({ user: { contents, currentPageNumber: page, diff --git a/src/entities/.gitkeep b/src/entities/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/src/entities/feed/model/common.type.ts b/src/entities/feed/model/common.type.ts index bad4eab..1fc3163 100644 --- a/src/entities/feed/model/common.type.ts +++ b/src/entities/feed/model/common.type.ts @@ -1,5 +1,5 @@ -import { IUser } from '@/entities/user/model/type'; -import { IImage } from '@/shared/types/image'; +import { IUser } from '@/entities/user'; +import { IImage } from '@/shared/types'; export interface IFeed { id: number; diff --git a/src/entities/feed/model/report.type.ts b/src/entities/feed/model/report.type.ts index 4b80a80..689ddf5 100644 --- a/src/entities/feed/model/report.type.ts +++ b/src/entities/feed/model/report.type.ts @@ -1,5 +1,12 @@ +export interface IReportFeedParamsDTO { + feedId: string; +} export interface IReportFeedReqDTO { category: string; content: string; isBlind: boolean; } + +export interface IReportFeedResDTO { + isReported: boolean; +} diff --git a/src/entities/feed/model/write.type.ts b/src/entities/feed/model/write.type.ts index 9ca7903..0ffb4e1 100644 --- a/src/entities/feed/model/write.type.ts +++ b/src/entities/feed/model/write.type.ts @@ -1,6 +1,18 @@ import { TFeedScope } from './common.type'; -export interface IWriteFeedReqDTO { +// 피드 작성 +export interface IWriteFeedParamsDTO { + feedId: string; +} +export type TWriteFeedReqDTO = IFeedEditCommonDTO; + +// 피드 수정 +export interface IModifyFeedParamsDTO { + feedId: string; +} +export type TModifyFeedReqDTO = IFeedEditCommonDTO; + +export interface IFeedEditCommonDTO { content: string; images: string[]; scope: TFeedScope; diff --git a/src/entities/user/model/type.ts b/src/entities/user/model/common.type.ts similarity index 100% rename from src/entities/user/model/type.ts rename to src/entities/user/model/common.type.ts diff --git a/src/entities/user/model/index.ts b/src/entities/user/model/index.ts index b38ebc9..7fb28e9 100644 --- a/src/entities/user/model/index.ts +++ b/src/entities/user/model/index.ts @@ -1 +1 @@ -export * from './type'; +export * from './common.type'; diff --git a/src/features/.gitkeep b/src/features/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/src/features/hideFeed/index.ts b/src/features/hideFeed/index.ts new file mode 100644 index 0000000..9f8ccad --- /dev/null +++ b/src/features/hideFeed/index.ts @@ -0,0 +1 @@ +export * from './model'; diff --git a/src/features/hideFeed/model/hide.type.ts b/src/features/hideFeed/model/hide.type.ts new file mode 100644 index 0000000..f108fbc --- /dev/null +++ b/src/features/hideFeed/model/hide.type.ts @@ -0,0 +1,15 @@ +// 피드 숨기기 +export interface IHideFeedParamsDTO { + feedId: string; +} +export interface IHideFeedResDTO { + isHidden: boolean; +} + +// 피드 숨기기 취소 +export interface ICancelHideFeedParamsDTO { + feedId: string; +} +export interface ICancelHideResDTO { + isHidden: boolean; +} diff --git a/src/features/hideFeed/model/index.ts b/src/features/hideFeed/model/index.ts new file mode 100644 index 0000000..80135bb --- /dev/null +++ b/src/features/hideFeed/model/index.ts @@ -0,0 +1 @@ +export * from './hide.type'; diff --git a/src/features/searchFeed/index.ts b/src/features/searchFeed/index.ts new file mode 100644 index 0000000..9f8ccad --- /dev/null +++ b/src/features/searchFeed/index.ts @@ -0,0 +1 @@ +export * from './model'; diff --git a/src/features/searchFeed/model/index.ts b/src/features/searchFeed/model/index.ts new file mode 100644 index 0000000..fcb073f --- /dev/null +++ b/src/features/searchFeed/model/index.ts @@ -0,0 +1 @@ +export * from './types'; diff --git a/src/features/searchFeed/model/types.ts b/src/features/searchFeed/model/types.ts new file mode 100644 index 0000000..ff46f18 --- /dev/null +++ b/src/features/searchFeed/model/types.ts @@ -0,0 +1,7 @@ +import { IFeed } from '@/entities/feed'; +import { IScrollablePage } from '@/shared/types'; + +//피드 검색 +export interface ISearchFeedResDTO { + feed: IScrollablePage; +} diff --git a/src/features/searchUser/index.ts b/src/features/searchUser/index.ts new file mode 100644 index 0000000..9f8ccad --- /dev/null +++ b/src/features/searchUser/index.ts @@ -0,0 +1 @@ +export * from './model'; diff --git a/src/features/searchUser/model/index.ts b/src/features/searchUser/model/index.ts new file mode 100644 index 0000000..fcb073f --- /dev/null +++ b/src/features/searchUser/model/index.ts @@ -0,0 +1 @@ +export * from './types'; diff --git a/src/features/searchUser/model/types.ts b/src/features/searchUser/model/types.ts new file mode 100644 index 0000000..e17bc6f --- /dev/null +++ b/src/features/searchUser/model/types.ts @@ -0,0 +1,7 @@ +import { IUser } from '@/entities/user'; +import { IScrollablePage } from '@/shared/types'; + +//유저 검색 +export interface ISearchUserResDTO { + user: IScrollablePage; +} diff --git a/src/shared/types/common.type.ts b/src/shared/types/common.type.ts new file mode 100644 index 0000000..5ad8aff --- /dev/null +++ b/src/shared/types/common.type.ts @@ -0,0 +1,7 @@ +export interface IScrollablePage { + contents: T; + currentPageNumber: number; + pageSize: number; + numberOfElements: number; + hasNextPage: boolean; +} diff --git a/src/shared/types/image.ts b/src/shared/types/image.type.ts similarity index 100% rename from src/shared/types/image.ts rename to src/shared/types/image.type.ts diff --git a/src/shared/types/index.ts b/src/shared/types/index.ts index cf09068..79bb4c5 100644 --- a/src/shared/types/index.ts +++ b/src/shared/types/index.ts @@ -1 +1,2 @@ -export * from './image'; +export * from './image.type'; +export * from './common.type';