Skip to content

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

Merged
merged 11 commits into from
Dec 10, 2023

Conversation

tmddus2
Copy link
Collaborator

@tmddus2 tmddus2 commented Dec 10, 2023

작업 개요

강의 조회 API 응답 형식 수정
내 정보 조회 API 응답 형식 수정

작업 사항

강의 조회하는 API 응답 형식을 다음과 같이 수정하였습니다. /lecture?code=768928 강의 코드와 함께 GET 요청을 보냅니다.
응답은 다음과 같습니다.

{
    "title": "최종테스트",
    "description": "리액트 배워보자~",
    "presenter": {
        "username": "볼볼록",
        "email": "[email protected]"
    }
}

내 정보 조회 API는 로그인 된 클라이언트만 호출할 수 있도록 HTTP request header에 있는 Authorization 토큰 값을 사용합니다.
/profile GET 요청을 보냅니다. 응답은 다음과 같습니다.

{
    "username": "볼볼록",
    "email": "[email protected]",
    "lecture_id": [
        {
            "title": "최종테스트",
            "description": "리액트 배워보자~",
            "presenter_id": {
                "username": "볼볼록"
            }
        },
        {
            "title": "최종테스트22",
            "description": "리액트 배워보자~",
            "presenter_id": {
                "username": "볼볼록"
            }
        }
    ]
}

본인이 참여했던 강의 정보를 응답해줍니다.

고민한 점들(필수 X)

기존의 Reference 방식으로 collection 간의 의존관계 설정을 해주었습니다. 그런데 NoSQL인 MongoDB 특성 상 값을 조회할 때 join 같은 연산을 해서 가져오기 보다는 값을 JSON 형태로 저장해둔 뒤에 조회하는 게 더 낫다고 판단했습니다. 그래서 기존의 Reference 방식에서 Embedded 방식으로 바꾸었습니다. 그런데 Embedded 방식의 단점이 값 자체를 저장하는 방식이다보니 값이 변경이 일어났을 때 업데이트가 쉽지 않다는 단점이 있었습니다. 닉네임 변경 등 값이 변경됐을 때 유연하게 값을 조회해오기 위해서 다시 Reference 방식으로 변경하고 다른 컬렉션의 값을 읽어오기 위해 populate를 사용하였습니다.

Copy link

netlify bot commented Dec 10, 2023

Deploy Preview for boarlog ready!

Name Link
🔨 Latest commit 2e2ea7c
🔍 Latest deploy log https://app.netlify.com/sites/boarlog/deploys/6575e0d13dd56000071aaaeb
😎 Deploy Preview https://deploy-preview-245--boarlog.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@tmddus2 tmddus2 requested a review from platinouss December 10, 2023 11:27
@tmddus2 tmddus2 self-assigned this Dec 10, 2023
@tmddus2 tmddus2 added 🛠️ Refactor 리팩토링 작업 BE 백엔드 작업 labels Dec 10, 2023
Copy link
Member

@platinouss platinouss left a 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 };
Copy link
Member

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 }));
Copy link
Member

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의 생성자 파라미터 적절하게 수정하는 방식도 괜찮을 것 같아요 !

아니면 저희 한번 전체적으로 리팩토링 할 때 그때 개선해도 좋을 것 같습니다

@tmddus2 tmddus2 requested a review from platinouss December 10, 2023 16:01
@platinouss platinouss merged commit 0e8f089 into boostcampwm2023:dev Dec 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BE 백엔드 작업 🛠️ Refactor 리팩토링 작업
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants