Skip to content

Commit

Permalink
🚚 itemHandler 통합
Browse files Browse the repository at this point in the history
  • Loading branch information
juyeon-park committed Nov 3, 2023
1 parent 284bd63 commit 3c90909
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 57 deletions.
3 changes: 1 addition & 2 deletions src/lib/msw/mocks/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import authHandlers from './authHandlers'
import { itemHandlers } from './itemHandler'
import { testHandlers } from './testHandler'
import { itemHandlers } from './itemHandlers'
import { testHandlers } from './testHandler'

export const handlers = [...testHandlers, ...authHandlers, ...itemHandlers]
21 changes: 0 additions & 21 deletions src/lib/msw/mocks/itemHandler.ts

This file was deleted.

82 changes: 48 additions & 34 deletions src/lib/msw/mocks/itemHandlers.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,61 @@
import { rest } from 'msw'
import { Environment } from '@/config/environment'
import ApiEndPoint from '@/config/apiEndPoint'
import { Environment } from '@/config/environment'
import items from '@/lib/msw/mocks/data/items.json'

const baseUrl = Environment.apiAddress()

export const itemHandlers = [
rest.get(`${baseUrl}/items`, async (req, res, ctx) => {
const queryString = req.url.search
const cursorId = queryString.slice(10)
const currentPage = Number(cursorId)
const PAGE_SIZE = 5
const filterdItems = items.filter(
(item, index) =>
index >= currentPage * PAGE_SIZE &&
index < (currentPage + 1) * PAGE_SIZE,
)

return res(ctx.status(200), ctx.json(filterdItems))
}),
rest.get(`${baseUrl}${ApiEndPoint.item('3')}`, async (_req, res, ctx) => {
return res(
ctx.status(200),
ctx.json({
"code": "C001",
"message": "성공했습니다.",
"data": {
"cardResponseDto": {
"cardId": 1,
"cardTitle": "아이폰 16 팝니다",
"category": "전자기기",
"itemName": "아이폰 16",
"pokeAvailable": true,
"createdAt": '2023-10-23-20:08',
"modifiedAt": '2023-10-24-20:08',
"viewCount": 19,
"priceRange": "10만원대",
"content": "이거 진짜 쩔어요",
"status": "TRADE_AVAILABLE",
"images": [
{
"_id": 1,
"image": "이미지 url"
},
{
"_id": 2,
"image": "이미지 url"
}
],
"dibsCount": 14,
"userId": 1,
"userName": "왕쩌는 구범모",
"tradeType": "직거래",
"tradeArea": "서울시 성동구"
}
}
}),
code: 'C001',
message: '성공했습니다.',
data: {
cardResponseDto: {
cardId: 1,
cardTitle: '아이폰 16 팝니다',
category: '전자기기',
itemName: '아이폰 16',
pokeAvailable: true,
createdAt: '2023-10-23-20:08',
modifiedAt: '2023-10-24-20:08',
viewCount: 19,
priceRange: '10만원대',
content: '이거 진짜 쩔어요',
status: 'TRADE_AVAILABLE',
images: [
{
_id: 1,
image: '이미지 url',
},
{
_id: 2,
image: '이미지 url',
},
],
dibsCount: 14,
userId: 1,
userName: '왕쩌는 구범모',
tradeType: '직거래',
tradeArea: '서울시 성동구',
},
},
}),
)
}),
]

0 comments on commit 3c90909

Please sign in to comment.