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

Refactor #204: mock repository와 controller로 분리하기 #205

Merged
merged 17 commits into from
Dec 5, 2024

Conversation

naarang
Copy link
Collaborator

@naarang naarang commented Dec 4, 2024

#️⃣연관된 이슈

closed #204

📝작업 내용

mock repository와 controller로 분리하기

💬리뷰 요구사항(선택)

  • 앞에 PR에 있는 변경사항 까지 포함되어있어요ㅠ 마지막 commit만 확인해주시면 됩니다!

ATeals
ATeals previously approved these changes Dec 4, 2024
Copy link
Collaborator

@ATeals ATeals left a comment

Choose a reason for hiding this comment

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

고생하셨습니다 ㅎㅎ 점점 모킹 코드가 좋아지네요.

약간 아쉬운 것은 기왕 모킹 개선을 더 해보자면, 더 Express와 같이 작성해보면 좋지않을까 생각해봐요!

Comment on lines 23 to 30
protected paginate(items: Identifiable<T>[], page: number, size: number) {
const start = (page - 1) * size;
const end = start + size;
const data = items.slice(start, end);
const maxPage = Math.ceil(items.length / size);
return { data, maxPage };
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

엄청 깔끔하네요

Comment on lines 20 to 39
async search({ query, page = 1, size = 10 }: { query?: Partial<LotusDto>; page?: number; size?: number }) {
const filtered = query ? this.memory.filter((item) => this.isPartialMatch(item, query)) : this.memory;

return this.paginate(filtered, page, size);
}

async findLotusDetail(query: Partial<LotusDto>) {
const lotus = await lotusRepository.findOne(query);

return { ...lotus, ...lotusMockFileData };
}
}

export const lotusRepository = new LotusRepository();

const insertLotus = () => {
lotusMockData.forEach((lotus) => {
lotusRepository.create(lotus);
});
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

🙋 큰 문제는 아니지만 이게 레포지토리의 코드인지는 잘 모르겠네요 저는 서비스에 둘 것 같아요.

레포지토리는 데이터의 기본적인 조회,생성,수정, 삭제 정도만 해준다고 생각하거든요.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

서비스 계층이 lotus에만 필요할 것 같아가지고 고민이 되네요ㅠ lotus, user, history에도 통일성있게 모두 서비스 계층을 추가해야될 것 같은데.. 다 추가하는게 낫겟죠..?

Comment on lines 82 to 86
author: { id: '1', nickname: 'js_master', profile: 'https://devblog.com/authors/js_master', gistUrl: '' },
logo: '/image/exampleImage.jpeg',
link: 'https://devblog.com/articles/1000000001',
isPublic: false,
gistUrl: ''
Copy link
Collaborator

Choose a reason for hiding this comment

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

🙋 유저 레포지토리를 만들었으니 기왕이면 유저 레포지토리를 통해서 유저데이터를 관리하면 좋겠네요.

Copy link
Collaborator

@ATeals ATeals left a comment

Choose a reason for hiding this comment

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

고생하셨습니당

@naarang naarang merged commit 7430c43 into main Dec 5, 2024
2 checks passed
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.

Mocking 코드 리팩토링하기
2 participants