Skip to content

Commit

Permalink
🎉 getItems, itemHandler 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
doggopawer committed Nov 2, 2023
1 parent b9f25bc commit 4900ee1
Show file tree
Hide file tree
Showing 7 changed files with 374 additions and 69 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"@types/react-dom": "^18",
"@types/tailwindcss": "^3.1.0",
"chromatic": "^7.5.4",
"encoding": "^0.1.13",
"eslint": "^8",
"eslint-config-next": "13.5.6",
"eslint-plugin-storybook": "^0.6.15",
Expand Down
145 changes: 77 additions & 68 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/config/apiEndPoint.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { GetItems } from '@/services/item/item'

const ApiEndPoint = {
login: () => '/login',
test: () => '/test',
items: (cursorId: number) => `/items?cursorId=${cursorId}`,
} as const

export default ApiEndPoint
254 changes: 254 additions & 0 deletions src/lib/msw/mocks/data/items.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,254 @@
[
{
"_id": 1,
"cardId": 1,
"cardTitle": "갤럭시 16 팝니다",
"itemName": "갤럭시 16",
"createdAt": "2023-11-01T08:08:00",
"modifiedAt": "2023-11-01T08:08:00",
"dibCount": 19,
"priceRange": "10000-50000",
"image": "이미지 링크",
"status": "EXCHANGEABLE"
},
{
"_id": 2,
"cardId": 2,
"cardTitle": "아이폰 17 팝니다",
"itemName": "아이폰 17",
"createdAt": "2023-11-01T08:08:00",
"modifiedAt": "2023-11-01T08:08:00",
"dibCount": 18,
"priceRange": "10만원대",
"image": "이미지 링크",
"status": "EXCHANGEABLE"
},
{
"_id": 3,
"cardId": 3,
"cardTitle": "아이폰 18 팝니다",
"itemName": "아이폰 18",
"createdAt": "2023-11-01T08:08:00",
"modifiedAt": "2023-11-01T08:08:00",
"dibCount": 17,
"priceRange": "20만원대",
"image": "이미지 링크",
"status": "EXCHANGEABLE"
},
{
"_id": 4,
"cardId": 1,
"cardTitle": "갤럭시 16 팝니다",
"itemName": "갤럭시 16",
"createdAt": "2023-11-01T08:08:00",
"modifiedAt": "2023-11-01T08:08:00",
"dibCount": 19,
"priceRange": "10000-50000",
"image": "이미지 링크",
"status": "EXCHANGEABLE"
},
{
"_id": 5,
"cardId": 2,
"cardTitle": "아이폰 17 팝니다",
"itemName": "아이폰 17",
"createdAt": "2023-11-01T08:08:00",
"modifiedAt": "2023-11-01T08:08:00",
"dibCount": 18,
"priceRange": "10만원대",
"image": "이미지 링크",
"status": "EXCHANGEABLE"
},
{
"_id": 6,
"cardId": 3,
"cardTitle": "아이폰 18 팝니다",
"itemName": "아이폰 18",
"createdAt": "2023-11-01T08:08:00",
"modifiedAt": "2023-11-01T08:08:00",
"dibCount": 17,
"priceRange": "20만원대",
"image": "이미지 링크",
"status": "EXCHANGEABLE"
},
{
"_id": 7,
"cardId": 1,
"cardTitle": "갤럭시 16 팝니다",
"itemName": "갤럭시 16",
"createdAt": "2023-11-01T08:08:00",
"modifiedAt": "2023-11-01T08:08:00",
"dibCount": 19,
"priceRange": "10000-50000",
"image": "이미지 링크",
"status": "EXCHANGEABLE"
},
{
"_id": 8,
"cardId": 2,
"cardTitle": "아이폰 17 팝니다",
"itemName": "아이폰 17",
"createdAt": "2023-11-01T08:08:00",
"modifiedAt": "2023-11-01T08:08:00",
"dibCount": 18,
"priceRange": "10만원대",
"image": "이미지 링크",
"status": "EXCHANGEABLE"
},
{
"_id": 9,
"cardId": 3,
"cardTitle": "아이폰 18 팝니다",
"itemName": "아이폰 18",
"createdAt": "2023-11-01T08:08:00",
"modifiedAt": "2023-11-01T08:08:00",
"dibCount": 17,
"priceRange": "20만원대",
"image": "이미지 링크",
"status": "EXCHANGEABLE"
},
{
"_id": 10,
"cardId": 1,
"cardTitle": "갤럭시 16 팝니다",
"itemName": "갤럭시 16",
"createdAt": "2023-11-01T08:08:00",
"modifiedAt": "2023-11-01T08:08:00",
"dibCount": 19,
"priceRange": "10000-50000",
"image": "이미지 링크",
"status": "EXCHANGEABLE"
},
{
"_id": 11,
"cardId": 2,
"cardTitle": "아이폰 17 팝니다",
"itemName": "아이폰 17",
"createdAt": "2023-11-01T08:08:00",
"modifiedAt": "2023-11-01T08:08:00",
"dibCount": 18,
"priceRange": "10만원대",
"image": "이미지 링크",
"status": "EXCHANGEABLE"
},
{
"_id": 3,
"cardId": 3,
"cardTitle": "아이폰 18 팝니다",
"itemName": "아이폰 18",
"createdAt": "2023-11-01T08:08:00",
"modifiedAt": "2023-11-01T08:08:00",
"dibCount": 17,
"priceRange": "20만원대",
"image": "이미지 링크",
"status": "EXCHANGEABLE"
},
{
"_id": 1,
"cardId": 1,
"cardTitle": "갤럭시 16 팝니다",
"itemName": "갤럭시 16",
"createdAt": "2023-11-01T08:08:00",
"modifiedAt": "2023-11-01T08:08:00",
"dibCount": 19,
"priceRange": "10000-50000",
"image": "이미지 링크",
"status": "EXCHANGEABLE"
},
{
"_id": 2,
"cardId": 2,
"cardTitle": "아이폰 17 팝니다",
"itemName": "아이폰 17",
"createdAt": "2023-11-01T08:08:00",
"modifiedAt": "2023-11-01T08:08:00",
"dibCount": 18,
"priceRange": "10만원대",
"image": "이미지 링크",
"status": "EXCHANGEABLE"
},
{
"_id": 3,
"cardId": 3,
"cardTitle": "아이폰 18 팝니다",
"itemName": "아이폰 18",
"createdAt": "2023-11-01T08:08:00",
"modifiedAt": "2023-11-01T08:08:00",
"dibCount": 17,
"priceRange": "20만원대",
"image": "이미지 링크",
"status": "EXCHANGEABLE"
},
{
"_id": 1,
"cardId": 1,
"cardTitle": "갤럭시 16 팝니다",
"itemName": "갤럭시 16",
"createdAt": "2023-11-01T08:08:00",
"modifiedAt": "2023-11-01T08:08:00",
"dibCount": 19,
"priceRange": "10000-50000",
"image": "이미지 링크",
"status": "EXCHANGEABLE"
},
{
"_id": 2,
"cardId": 2,
"cardTitle": "아이폰 17 팝니다",
"itemName": "아이폰 17",
"createdAt": "2023-11-01T08:08:00",
"modifiedAt": "2023-11-01T08:08:00",
"dibCount": 18,
"priceRange": "10만원대",
"image": "이미지 링크",
"status": "EXCHANGEABLE"
},
{
"_id": 3,
"cardId": 3,
"cardTitle": "아이폰 18 팝니다",
"itemName": "아이폰 18",
"createdAt": "2023-11-01T08:08:00",
"modifiedAt": "2023-11-01T08:08:00",
"dibCount": 17,
"priceRange": "20만원대",
"image": "이미지 링크",
"status": "EXCHANGEABLE"
},
{
"_id": 1,
"cardId": 1,
"cardTitle": "갤럭시 16 팝니다",
"itemName": "갤럭시 16",
"createdAt": "2023-11-01T08:08:00",
"modifiedAt": "2023-11-01T08:08:00",
"dibCount": 19,
"priceRange": "10000-50000",
"image": "이미지 링크",
"status": "EXCHANGEABLE"
},
{
"_id": 2,
"cardId": 2,
"cardTitle": "아이폰 17 팝니다",
"itemName": "아이폰 17",
"createdAt": "2023-11-01T08:08:00",
"modifiedAt": "2023-11-01T08:08:00",
"dibCount": 18,
"priceRange": "10만원대",
"image": "이미지 링크",
"status": "EXCHANGEABLE"
},
{
"_id": 3,
"cardId": 3,
"cardTitle": "아이폰 18 팝니다",
"itemName": "아이폰 18",
"createdAt": "2023-11-01T08:08:00",
"modifiedAt": "2023-11-01T08:08:00",
"dibCount": 17,
"priceRange": "20만원대",
"image": "이미지 링크",
"status": "EXCHANGEABLE"
}
]
3 changes: 2 additions & 1 deletion src/lib/msw/mocks/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { itemHandlers } from './itemHandler'
import { testHandlers } from './testHandler'

export const handlers = [...testHandlers]
export const handlers = [...testHandlers, ...itemHandlers]
21 changes: 21 additions & 0 deletions src/lib/msw/mocks/itemHandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { rest } from 'msw'
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))
}),
]
16 changes: 16 additions & 0 deletions src/services/item/item.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import ApiEndPoint from '@/config/apiEndPoint'
import apiClient from '../apiClient'

export type GetItems = {
categories: string[]
priceRange: string
name: string
cursorId: number
}

const getItems = async ({ cursorId }: GetItems) => {
const response = await apiClient.get(ApiEndPoint.items(cursorId))
return response
}

export { getItems }

0 comments on commit 4900ee1

Please sign in to comment.