Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ 피드 숨기기, 숨기기 취소 모킹 API Handler 추가 및 type 정리 #17

Merged
merged 12 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 53 additions & 40 deletions src/app/mocks/handlers/feed.ts
Original file line number Diff line number Diff line change
@@ -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<IReportFeedParamsDTO>(
'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<IReportFeedResDTO>({
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('피드 등록을 위해 컨텐츠를 작성해야 합니다.');
Expand All @@ -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<IModifyFeedParamsDTO>(
'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) => {
Legitgoons marked this conversation as resolved.
Show resolved Hide resolved
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({});
},
),
];
53 changes: 53 additions & 0 deletions src/app/mocks/handlers/hide.ts
Original file line number Diff line number Diff line change
@@ -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<IHideFeedParamsDTO>(
'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<IHideFeedResDTO>({
isHidden: true,
});
},
),

// 2️⃣ 피드 숨기기 취소
http.delete<ICancelHideFeedParamsDTO>(
'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<ICancelHideResDTO>({
isHidden: false,
});
},
),
];
7 changes: 5 additions & 2 deletions src/app/mocks/handlers/search.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -28,7 +31,7 @@ export const searchHandlers = [
const totalFeeds = contents.length;
const hasNextPage = totalFeeds > page * size;

return createHttpSuccessResponse({
return createHttpSuccessResponse<ISearchFeedResDTO>({
feed: {
contents,
currentPageNumber: page,
Expand Down Expand Up @@ -62,7 +65,7 @@ export const searchHandlers = [
const totalFeeds = contents.length;
const hasNextPage = totalFeeds > page * size;

return createHttpSuccessResponse({
return createHttpSuccessResponse<ISearchUserResDTO>({
user: {
contents,
currentPageNumber: page,
Expand Down
Empty file removed src/entities/.gitkeep
Empty file.
4 changes: 2 additions & 2 deletions src/entities/feed/model/common.type.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
7 changes: 7 additions & 0 deletions src/entities/feed/model/report.type.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
export interface IReportFeedParamsDTO {
feedId: string;
}
BangDori marked this conversation as resolved.
Show resolved Hide resolved
export interface IReportFeedReqDTO {
category: string;
content: string;
isBlind: boolean;
}

export interface IReportFeedResDTO {
isReported: boolean;
}
14 changes: 13 additions & 1 deletion src/entities/feed/model/write.type.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/entities/user/model/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './type';
export * from './common.type';
Empty file removed src/features/.gitkeep
Empty file.
1 change: 1 addition & 0 deletions src/features/hideFeed/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './model';
15 changes: 15 additions & 0 deletions src/features/hideFeed/model/hide.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 피드 숨기기
export interface IHideFeedParamsDTO {
feedId: string;
}
export interface IHideFeedResDTO {
isHidden: boolean;
}

// 피드 숨기기 취소
export interface ICancelHideFeedParamsDTO {
feedId: string;
}
export interface ICancelHideResDTO {
isHidden: boolean;
}
1 change: 1 addition & 0 deletions src/features/hideFeed/model/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './hide.type';
1 change: 1 addition & 0 deletions src/features/searchFeed/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './model';
1 change: 1 addition & 0 deletions src/features/searchFeed/model/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './types';
7 changes: 7 additions & 0 deletions src/features/searchFeed/model/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { IFeed } from '@/entities/feed';
import { IScrollablePage } from '@/shared/types';

//피드 검색
export interface ISearchFeedResDTO {
feed: IScrollablePage<IFeed[]>;
}
1 change: 1 addition & 0 deletions src/features/searchUser/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './model';
1 change: 1 addition & 0 deletions src/features/searchUser/model/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './types';
7 changes: 7 additions & 0 deletions src/features/searchUser/model/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { IUser } from '@/entities/user';
import { IScrollablePage } from '@/shared/types';

//유저 검색
export interface ISearchUserResDTO {
user: IScrollablePage<IUser[]>;
}
7 changes: 7 additions & 0 deletions src/shared/types/common.type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export interface IScrollablePage<T> {
contents: T;
currentPageNumber: number;
pageSize: number;
numberOfElements: number;
hasNextPage: boolean;
}
File renamed without changes.
3 changes: 2 additions & 1 deletion src/shared/types/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './image';
export * from './image.type';
export * from './common.type';