-
Notifications
You must be signed in to change notification settings - Fork 0
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
Feature(#202): 화이트보드 변경내역 추가 API 구현 #203
Conversation
미디어 서버로부터 특정 강의의 화이트보드 변경내역을 받으면 DB에 저장한다.
@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 | ||
) { |
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.
강의 로그 추가하는 API가 /lecture/강의코드
이런 식으로 매핑이 되는거 같은데 /lecture/log
이런 식으로 설정하는건 어떤가요? 어떤 게 더 좋은 API 설계인지는 잘 모르겠네요...😇
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(); |
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.
인자로 lecture를 Lecture
entity로 통째로 받았는데 lecture_id
저장할 때 lecture_id: lecture.id
이런 식으로 안해주고 그 자체를 넣어줘도 잘 저장이 되나요? 그냥 객체 자체가 json 형태로 들어가는건지 id만 들어가는건지 궁금하네요!
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.
제가 저저번주에 테스트 했을 때는 ObjectId로 타입을 선언(whiteboard-log.schema
의 18번째 라인)하기도 해서 해당 lecture의 _id값만 들어갔습니다.
일단 저희가 Lecture 스키마 클래스에서 _id를 따로 지정해주지 않았기 때문에 lecture._id로는 id를 가져올 수 없습니다 !
@Prop({ required: true, type: mongoose.Schema.Types.ObjectId, ref: 'Lecture' }) | ||
lecture_id: Lecture; |
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.
이렇게 ref 값을 지정해줄 수 있군요!
경로만 보고 의미를 직관적으로 알 수 있도록 나타냈습니다.
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.
수고 많으셨습니다!
작업 개요
미디어 서버로부터 화이트보드 변경 사항을 전달받으면 DB에 저장한다. close #202
작업 사항
구상한 컬렉션을 바탕으로 모델을 구현했습니다.
먼저 미디어 서버로부터 받을 데이터 타입을 위와 같이 DTO 형태로 구성했습니다.
미디어 서버에서 화이트보드 변경내역과 함께
/lecture/:code
로 요청하면, 매핑된 컨트롤러는 강의 참여 코드로 개설된 강의를 찾고, whiteboard_log 컬렉션에 화이트보드 변경 내역을 추가합니다. 이때 해당 강의 참여 코드로 개설된 방이 없을 경우 404를 반환합니다.