Skip to content

Feature(#202): 화이트보드 변경내역 추가 API 구현 #203

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

Conversation

platinouss
Copy link
Member

@platinouss platinouss commented Dec 5, 2023

작업 개요

미디어 서버로부터 화이트보드 변경 사항을 전달받으면 DB에 저장한다. close #202

작업 사항

  • 화이트보드 로그에 해당하는 mongoose 스키마 구현
whiteboard_log
{
  _id: “WHITEBOARD_LOG_1”,
  canvasJSON: string;
  viewPort: number[];
  event_date: “”,
  lecture_id: “LECTURE_1”
}

구상한 컬렉션을 바탕으로 모델을 구현했습니다.

  • 화이트보드 변경 내역 추가 API 구현
export class WhiteboardEventDto {
  canvasJSON: string;

  viewPort: number[];

  eventDate: Date;
}

먼저 미디어 서버로부터 받을 데이터 타입을 위와 같이 DTO 형태로 구성했습니다.

미디어 서버에서 화이트보드 변경내역과 함께 /lecture/:code로 요청하면, 매핑된 컨트롤러는 강의 참여 코드로 개설된 강의를 찾고, whiteboard_log 컬렉션에 화이트보드 변경 내역을 추가합니다. 이때 해당 강의 참여 코드로 개설된 방이 없을 경우 404를 반환합니다.

미디어 서버로부터 특정 강의의 화이트보드 변경내역을 받으면 DB에 저장한다.
@platinouss platinouss added ✨ Feat 기능 개발 BE 백엔드 작업 labels Dec 5, 2023
@platinouss platinouss added this to the 5주차 milestone Dec 5, 2023
@platinouss platinouss self-assigned this Dec 5, 2023
@boostcampwm2023 boostcampwm2023 deleted a comment from netlify bot Dec 5, 2023
@platinouss platinouss requested a review from tmddus2 December 6, 2023 00:58
Comment on lines 65 to 73
@Post('/:code')
@ApiQuery({ name: 'code', type: 'string' })
@ApiResponse({ status: 201 })
@ApiResponse({ status: 404, description: '해당 강의가 없습니다.' })
async addWhiteBoardLog(
@Param('code') code: string,
@Body() whiteboardEventDto: WhiteboardEventDto,
@Res() res: Response
) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

강의 로그 추가하는 API가 /lecture/강의코드 이런 식으로 매핑이 되는거 같은데 /lecture/log 이런 식으로 설정하는건 어떤가요? 어떤 게 더 좋은 API 설계인지는 잘 모르겠네요...😇

Comment on lines +68 to +75
async saveWhiteBoardLog(lecture: Lecture, whiteboardEventDto: WhiteboardEventDto) {
const whiteboardLog = new this.whiteboardLogModel({
canvasJSON: whiteboardEventDto.canvasJSON,
viewPort: whiteboardEventDto.viewPort,
event_date: whiteboardEventDto.eventDate,
lecture_id: lecture
});
return await whiteboardLog.save();
Copy link
Collaborator

Choose a reason for hiding this comment

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

인자로 lecture를 Lecture entity로 통째로 받았는데 lecture_id 저장할 때 lecture_id: lecture.id 이런 식으로 안해주고 그 자체를 넣어줘도 잘 저장이 되나요? 그냥 객체 자체가 json 형태로 들어가는건지 id만 들어가는건지 궁금하네요!

Copy link
Member Author

@platinouss platinouss Dec 6, 2023

Choose a reason for hiding this comment

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

제가 저저번주에 테스트 했을 때는 ObjectId로 타입을 선언(whiteboard-log.schema의 18번째 라인)하기도 해서 해당 lecture의 _id값만 들어갔습니다.
일단 저희가 Lecture 스키마 클래스에서 _id를 따로 지정해주지 않았기 때문에 lecture._id로는 id를 가져올 수 없습니다 !

Comment on lines +18 to +19
@Prop({ required: true, type: mongoose.Schema.Types.ObjectId, ref: 'Lecture' })
lecture_id: Lecture;
Copy link
Collaborator

Choose a reason for hiding this comment

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

이렇게 ref 값을 지정해줄 수 있군요!

@tmddus2 tmddus2 self-requested a review December 6, 2023 01:52
경로만 보고 의미를 직관적으로 알 수 있도록 나타냈습니다.
Copy link
Collaborator

@tmddus2 tmddus2 left a comment

Choose a reason for hiding this comment

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

수고 많으셨습니다!

@tmddus2 tmddus2 merged commit 1c620ed into boostcampwm2023:dev Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BE 백엔드 작업 ✨ Feat 기능 개발
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: 미디어 서버로부터 화이트보드 변경 사항을 전달받으면 DB에 저장한다.
2 participants