Skip to content

Commit

Permalink
feat(Feed): MyFeed Page Mock API 추가
Browse files Browse the repository at this point in the history
Ref #54
  • Loading branch information
akariyan committed Feb 18, 2022
1 parent ea3e409 commit c03b2d3
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions mocks/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import {
WriterFactory,
} from './factories';
import { camelizeKeys } from 'humps';
import {
DEFAULT_FEED_COUNT,
DEFAULT_START_PAGE,
} from '~/shared/constants/pagination';

export const handlers = [
rest.get(`${API_URL}/services/main_contents`, (req, res, ctx) => {
Expand Down Expand Up @@ -146,4 +150,34 @@ export const handlers = [
);
},
),
rest.get(`${API_URL}/services/feed_contents`, (req, res, ctx) => {
const writerId = req.url.searchParams.get('writer_id');
const count = Number(req.url.searchParams.get('count'));
const page = Number(req.url.searchParams.get('page'));

if (!writerId || isNaN(count) || isNaN(page)) {
const errorResponse = ErrorResponseFactory.build();
return res(ctx.status(422), ctx.json(errorResponse));
}

const totalPages = Math.floor(Math.random() * (100 - 10) + 10);
const writer = WriterFactory.build({ writerId });
const contents = ContentsFactory.buildList(count);

return res(
ctx.json({
status_code: 200,
msg: '응답 성공',
data: {
writer: writer,
feed_contents_list: contents,
paging: {
start: page,
is_last: false,
total_pages: totalPages,
},
},
}),
);
}),
];

0 comments on commit c03b2d3

Please sign in to comment.