-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor: 강의 조회 API 및 마이페이지 내 정보 조회 API 수정 #245
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: 강의 조회 API 및 마이페이지 내 정보 조회 API 수정 #245
Conversation
✅ Deploy Preview for boarlog ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
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.
고생하셨습니다 ! 😊
@@ -59,7 +77,10 @@ export class LectureController { | |||
throw new HttpException('해당 강의가 없습니다.', HttpStatus.NOT_FOUND); | |||
} | |||
const result = await this.lectureService.findLectureInfo(enterCodeDocument); | |||
res.status(HttpStatus.OK).send(result); | |||
const presenter = { username: result.presenter_id.username, email: result.presenter_id.email }; |
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.
result.presenter_id에 유저 정보가 매핑되나보네요 !
만약 presenter를 만드신다고 하시면 Presenter 클래스를 따로 만드시는건 어떠신가요? 그럼 JSON 타입 말고 Presenter 타입으로 선언도 해줄 수 있을 것 같습니다 !
const presenter = { username: result.presenter_id.username, email: result.presenter_id.email }; | ||
res | ||
.status(HttpStatus.OK) | ||
.send(new LectureInfoDto({ title: result.title, description: result.description, presenter: presenter })); |
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.
이 부분 개선해볼 수 있을 것 같아요 !
만약 Presenter 클래스를 만드신다고 하시면, new LectureInfoDto(result, presenter)
로만 주고, LectureInfoDto의 생성자 파라미터 적절하게 수정하는 방식도 괜찮을 것 같아요 !
아니면 저희 한번 전체적으로 리팩토링 할 때 그때 개선해도 좋을 것 같습니다
작업 개요
강의 조회 API 응답 형식 수정
내 정보 조회 API 응답 형식 수정
작업 사항
강의 조회하는 API 응답 형식을 다음과 같이 수정하였습니다.
/lecture?code=768928
강의 코드와 함께 GET 요청을 보냅니다.응답은 다음과 같습니다.
내 정보 조회 API는 로그인 된 클라이언트만 호출할 수 있도록 HTTP request header에 있는 Authorization 토큰 값을 사용합니다.
/profile
GET 요청을 보냅니다. 응답은 다음과 같습니다.본인이 참여했던 강의 정보를 응답해줍니다.
고민한 점들(필수 X)
기존의 Reference 방식으로 collection 간의 의존관계 설정을 해주었습니다. 그런데 NoSQL인 MongoDB 특성 상 값을 조회할 때 join 같은 연산을 해서 가져오기 보다는 값을 JSON 형태로 저장해둔 뒤에 조회하는 게 더 낫다고 판단했습니다. 그래서 기존의 Reference 방식에서 Embedded 방식으로 바꾸었습니다. 그런데 Embedded 방식의 단점이 값 자체를 저장하는 방식이다보니 값이 변경이 일어났을 때 업데이트가 쉽지 않다는 단점이 있었습니다. 닉네임 변경 등 값이 변경됐을 때 유연하게 값을 조회해오기 위해서 다시 Reference 방식으로 변경하고 다른 컬렉션의 값을 읽어오기 위해 populate를 사용하였습니다.