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

Feat/#49 mocking #51

Merged
merged 12 commits into from
Jul 16, 2022
Merged

Feat/#49 mocking #51

merged 12 commits into from
Jul 16, 2022

Conversation

joohaem
Copy link
Member

@joohaem joohaem commented Jul 15, 2022

  • 브랜치명, 브랜치 알맞게 설정
  • Reviewer, Assignees, Label, Milestone, Issue(PR 작성 후에) 붙이기
  • PR이 승인된 경우 해당 브랜치는 삭제하기

📌 내용

  • GET 으로 받아오는 mock data 다 적용시켜놨습니다!!!!
  • 아래 사진처럼, core/api/ 폴더에서 알맞는 url 에 맞는 함수 가져가서 쓰면 됩니다 !!!!!!!
    image

📌 내가 알게 된 부분


@joohaem joohaem added this to the 🔥 Demo Day 🔥 milestone Jul 15, 2022
@joohaem joohaem self-assigned this Jul 15, 2022
@joohaem joohaem linked an issue Jul 15, 2022 that may be closed by this pull request
4 tasks
Copy link
Contributor

@NaveOWO NaveOWO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

msw 라이브러리를 사용해서 서버 받아오는거랑, 라이브러리 사용 안하고 받아오는거랑 둘다 있는 거 맞나욤...?! 아니면 내가 잠와서 잘못본 걸수도..
오빠 Mock API 이거맞나?? 만드느라 너무 수고 많았구!! 공부해서 열심히 사용해볼게욤!!!!!

line-height: 1.4;

margin-bottom: 0.4rem;

${({ theme }) => theme.fonts.body4};

overflow: hidden;
text-overflow: ellipsis;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아하링 이렇게 말줄임 할 수 있구나! 난 맨날 글자수 세면서 했는디.... 감쟈해욤!

function fetchCardsWithFilter(types: string[]) {
let params = "";
types.forEach((type) => {
params += `?search=${type}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이부분으 무슨 코드인지 잘 모르겠어욧! 일단 공부해볼게욤🙈🙈

Copy link
Member Author

@joohaem joohaem Jul 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

우리 필터 API 에 타입 넘겨주는 걸,

search: "남자"
search: "상관없음"
search: "20대"
search: "10대"

이런 식으로 넘겨야 하더라구,
그래서 인자로 ["남자", 상관없음", "20대", "10대"]를 넘겨주면 되게끔 구현해봤어요!

export const categoriesHandler = [
rest.get(`${process.env.REACT_APP_BASE_URL}/categories`, (req, res, ctx) => {
rest.get(`${process.env.REACT_APP_BASE_URL}${PATH.CATEGORIES}`, (req, res, ctx) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

근데 여기서 ctx는 뭘 말하는건지 잘 모르겠어요!!🙏

Copy link
Member Author

@joohaem joohaem Jul 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔗 ctx :: msw 공식문서 문서 한 번 확인하시면 좋을 것 같습니다!

Copy link
Contributor

@NYeonK NYeonK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

우왕 뭔가 저번에 합세할때랑 조금 달라서 신기하당~
글구 바꿀 부분이 엄청 많았을 것 같은데 진짜 고생많았다 오빠야!!!😆😆

Comment on lines +31 to +36
useEffect(() => {
(async () => {
const { data } = await real.fetchCardsWithCategory("카테고리id");
setCardLists(data.cardIdList);
})();
}, []);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아하 요롷게 받아오는 거구나~!
마이페이지 부분도 이렇게 바꿔야겠다😚

return (
<St.VoteContent key={element.id}>
<St.VoteContent key={`${ballot._id}-${idx}`}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

key값은 보통 어떤 값을 지정해주는 건가용??
${ballot._id}-${idx} 이 값을 넣은 이유가 궁금합니당!!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

key 값은, 비효율적인 리렌더링을 막기 위해 설정해주는 "고유한 값" 입니다 !

그래서 idx 로만 설정한다면, 순서가 바뀔 떄 key 값이 중복되게 되면서 비효율적인 리렌더링이 일어날 가능성이 있어요

이를 막기 위해 id 값과 같은 고유한 값으로 주어야하고, mock data 로 값이 중복되는 것 같아 -${idx} 값을 추가하였어요!
(보통은 id 값만 주면 됩니다 !! idx X !!)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오오오옹 똑똑해!!!😲😲

async POST(path: string, body: any) {
const { data } = await real.post(`/${path}`, body);
return data;
async POST<T>(path: string, body: T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any가 아니라 T인 이유가 무엇인가요?-?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

타입스크립트에서 any 타입은 모든 타입을 허용한다는 의미로, 사용을 지양해야 타입스크립트의 장점을 활용할 수 있어요

그래서 body 타입에 따라 다른 함수를 정의하기 위해 제네릭 타입인 <T> 을 활용하여 정의합니다!

Comment on lines 9 to 12
// 프로필사진 수정
// function patchProfileImg() {
// function patchProfileImg() {
// return realReq.PATCH(PATH.USERS);
// }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

필요한 부분이라소 주석을 안지운걸까요!!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네 !! 후에 쓸 것 같아요 !!!

@joohaem
Copy link
Member Author

joohaem commented Jul 16, 2022

@NaveOWO

msw 라이브러리를 사용해서 서버 받아오는거랑, 라이브러리 사용 안하고 받아오는거랑 둘다 있는 거 맞나욤...?!

우리가 하던 대로 서버와 통신하면, msw 라이브러리가 (Service Worker API를 활용해서 그 통신을 가로채서) mock api 통신으로 반환합니다

즉, 우리는 그냥 하던 방식대로 통신하면 msw 라이브러리가 알아서 data 로 반환해주는 의미입니닺

@joohaem joohaem merged commit 98e6d56 into develop Jul 16, 2022
@joohaem joohaem deleted the feat/#49-mocking branch July 16, 2022 05:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ Common ] mock api 점검
3 participants