-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into community_list_mock/#47
- Loading branch information
Showing
12 changed files
with
1,563 additions
and
47 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { UserData } from '../../types/user'; | ||
export const userMockData: UserData[] = [ | ||
{ | ||
id: 'happhee', | ||
sns_id: '[email protected]', | ||
provider: 'naver', | ||
nickname: 'happhee', | ||
email: '[email protected]', | ||
}, | ||
]; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { rest } from 'msw'; | ||
import { communityMockData } from '../data/communityMockData'; | ||
import { | ||
CommunityData, | ||
PostCommentBody, | ||
PostCommunityBody, | ||
} from '../../types/community'; | ||
// 커뮤니티 게시글 작성 | ||
export const postCommunity = rest.post('/board', (req, res, ctx) => { | ||
const { category, title, content, imageList } = req.body as PostCommunityBody; | ||
const addId = communityMockData.length + 1 + ''; | ||
|
||
communityMockData.push({ | ||
id: addId, | ||
category: category, | ||
title: title, | ||
content: content, | ||
imageList: imageList, | ||
}); | ||
return res(ctx.json(communityMockData)); | ||
}); | ||
// 커뮤니티 게시글 수정 | ||
export const putCommunity = rest.put('/board/:boardId', (req, res, ctx) => { | ||
const { boardId } = req.params; | ||
}); | ||
|
||
// 커뮤니티 게시글 상세조회 | ||
export const getCommunityDetail = rest.get( | ||
'/board/:boardId', | ||
(req, res, ctx) => { | ||
const { boardId } = req.params; | ||
|
||
const communityDetail = communityMockData.filter( | ||
(community) => community.id === boardId, | ||
); | ||
|
||
return res(ctx.json(communityDetail)); | ||
}, | ||
); | ||
// 커뮤니티 게시글 리스트 조회 | ||
export const getCommunityList = rest.get('/board', (req, res, ctx) => { | ||
return res(ctx.json(communityMockData)); | ||
}); | ||
// 커뮤니티 댓글 작성 | ||
export const postComment = rest.post('/board/comment', (req, res, ctx) => { | ||
const { boardId, content } = req.body as PostCommentBody; | ||
|
||
const currentComment: CommunityData[] = communityMockData.filter( | ||
(community) => community.id === boardId, | ||
); | ||
currentComment[0].replyList?.push({ content: content }); | ||
communityMockData[Number(boardId) - 1].replyList = | ||
currentComment[0].replyList; | ||
|
||
return res(ctx.json(communityMockData)); | ||
}); | ||
// 커뮤니티 게시글 삭제 | ||
export const deleteCommunity = rest.delete( | ||
'/board/:boardId', | ||
(req, res, ctx) => { | ||
const { boardId } = req.params; | ||
|
||
const newCommunityMockData = communityMockData.filter( | ||
(community) => community.id !== boardId, | ||
); | ||
|
||
return res(ctx.json(newCommunityMockData)); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import * as toyHandlers from './toy'; | ||
import * as communityHandlers from './community'; | ||
import * as loginHandlers from './user'; | ||
|
||
export const handlers = [ | ||
...Object.values(toyHandlers), | ||
...Object.values(communityHandlers), | ||
...Object.values(loginHandlers), | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { rest } from 'msw'; | ||
import { toyMockData } from '../data/toyMockData'; | ||
import { ToyData } from '../../types/toy'; | ||
|
||
// 장난감 리스트 조회 (메인뷰) | ||
export const getHome = rest.get('/home', (req, res, ctx) => | ||
res(ctx.json(toyMockData)), | ||
); | ||
|
||
// 장난감 컬렉션 별 조회 | ||
export const getToyCollection = rest.get('/collection', (req, res, ctx) => { | ||
const theme = req.url.searchParams.get('theme'); | ||
const sort = req.url.searchParams.get('sort'); | ||
|
||
// 낮은 가격 순 | ||
function priceDesc(a: ToyData, b: ToyData) { | ||
if (a.price == b.price) { | ||
return 0; | ||
} | ||
return a.price > b.price ? 1 : -1; | ||
} | ||
// 높은 가격 순 | ||
function priceAsc(a: ToyData, b: ToyData) { | ||
if (a.price == b.price) { | ||
return 0; | ||
} | ||
return a.price < b.price ? 1 : -1; | ||
} | ||
return sort === 'price-desc' | ||
? res(ctx.json(toyMockData.sort(priceDesc))) | ||
: res(ctx.json(toyMockData.sort(priceAsc))); | ||
}); | ||
|
||
// 장난감 검색 및 필터 리스트 조회 | ||
// 필터 검증 로직은 영이 로직 짜고 생각해봐야할 것같아 | ||
export const getToyList = rest.get('/toy/list', (req, res, ctx) => { | ||
const search = req.url.searchParams.get('search'); | ||
const type = req.url.searchParams.get('type'); | ||
const month = req.url.searchParams.getAll('month'); | ||
const price = req.url.searchParams.get('price'); | ||
const playHow = req.url.searchParams.get('playHow'); | ||
const category = req.url.searchParams.get('category'); | ||
|
||
const toyList = toyMockData.filter( | ||
(toy) => | ||
toy.title.includes(`${search}`) && | ||
toy.type === Number(type) && | ||
toy.price <= Number(price) && | ||
toy.playHow === Number(playHow), | ||
); | ||
return res(ctx.json(toyList)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { rest } from 'msw'; | ||
import { userMockData } from '../data/userMockData'; | ||
import { PostSignUpBody } from '../../types/user'; | ||
// 카카오 로그인 | ||
export const getKakao = rest.get( | ||
'/auth/login/kakao/:nickname', | ||
(req, res, ctx) => { | ||
const { nickname } = req.params; | ||
const user = userMockData.filter( | ||
(user) => user.provider === 'kakao' && user.nickname === nickname, | ||
); | ||
return res(ctx.json(user)); | ||
}, | ||
); | ||
// 구글 로그인 | ||
export const getGoogle = rest.get( | ||
'/auth/login/google/:nickname', | ||
(req, res, ctx) => { | ||
const { nickname } = req.params; | ||
const user = userMockData.filter( | ||
(user) => user.provider === 'google' && user.nickname === nickname, | ||
); | ||
return res(ctx.json(user)); | ||
}, | ||
); | ||
|
||
// 네이버 로그인 | ||
export const getNaver = rest.get( | ||
'/auth/login/naver/:nickname', | ||
(req, res, ctx) => { | ||
const { nickname } = req.params; | ||
const user = userMockData.filter( | ||
(user) => user.provider === 'naver' && user.nickname === nickname, | ||
); | ||
return res(ctx.json(user)); | ||
}, | ||
); | ||
|
||
// 회원가입 | ||
export const signUp = rest.post('/auth/signup', (req, res, ctx) => { | ||
const { nickname } = req.body as PostSignUpBody; | ||
const userList = userMockData.filter((user) => user.nickname === nickname); | ||
|
||
return userList.length === 0 ? res(ctx.status(201)) : res(ctx.json(409)); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// 댓글 | ||
export interface ReplyData { | ||
userNickname?: string; | ||
content: string; | ||
createdAt?: string; | ||
} | ||
// 커뮤니티 데이터 | ||
export interface CommunityData { | ||
id: string; | ||
category: string; | ||
title: string; | ||
content: string; | ||
userNickname?: string; | ||
replyCount?: number; | ||
createdAt?: string; | ||
image?: string; | ||
imageList?: string[]; | ||
replyList?: ReplyData[]; | ||
} | ||
// 커뮤니티 게시글 작성 post body | ||
export interface PostCommunityBody { | ||
category: string; | ||
title: string; | ||
content: string; | ||
imageList?: string[]; | ||
} | ||
|
||
// 커뮤니티 댓글 | ||
export interface PostCommentBody { | ||
boardId: string; | ||
content: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export interface ToyData { | ||
price: number; //가격 | ||
priceCode: number; | ||
image: string; //이미지 | ||
siteUrl: string; | ||
title: string; | ||
month: Array<number>; //연령 | ||
playHow: number; | ||
type: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export interface UserData { | ||
id: string; | ||
sns_id: string; | ||
provider: string; | ||
nickname: string; | ||
email: string; | ||
} | ||
export interface PostSignUpBody { | ||
nickname: string; | ||
} |