-
Notifications
You must be signed in to change notification settings - Fork 3
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생하셨습니다 ㅎㅎ 점점 모킹 코드가 좋아지네요.
약간 아쉬운 것은 기왕 모킹 개선을 더 해보자면, 더 Express와 같이 작성해보면 좋지않을까 생각해봐요!
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 }; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
엄청 깔끔하네요
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); | ||
}); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙋 큰 문제는 아니지만 이게 레포지토리의 코드인지는 잘 모르겠네요 저는 서비스에 둘 것 같아요.
레포지토리는 데이터의 기본적인 조회,생성,수정, 삭제 정도만 해준다고 생각하거든요.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
서비스 계층이 lotus에만 필요할 것 같아가지고 고민이 되네요ㅠ lotus, user, history에도 통일성있게 모두 서비스 계층을 추가해야될 것 같은데.. 다 추가하는게 낫겟죠..?
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: '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙋 유저 레포지토리를 만들었으니 기왕이면 유저 레포지토리를 통해서 유저데이터를 관리하면 좋겠네요.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생하셨습니당
#️⃣연관된 이슈
closed #204
📝작업 내용
💬리뷰 요구사항(선택)