Skip to content

Conversation

@twalla26
Copy link
Collaborator

관련 이슈 번호

  • 작성자: 송수민
  • 작성 날짜: 2024.11.21

✅ 체크리스트

  • 코드가 정상적으로 작동하는지 확인했습니다.
  • 주요 변경사항에 대한 설명을 작성했습니다.
  • 코드 스타일 가이드에 따라 코드를 작성했습니다.

🧩 작업 내용

  • 스터디룸 생성할 때 질문 내용 전달
  • 질문지 기능 버그 fix
    • 질문 내용의 길이를 20에서 200으로 늘리기
    • 질문 리스트와 그 안의 질문을 생성하는 쿼리를 트랜잭션으로 묶기

📝 작업 상세 내역

�스터디룸 생성할 때 질문 내용도 함께 전달하도록 구현했습니다.

질문 리스트와 그 안의 질문을 생성하는 쿼리를 트랜잭션으로 묶기

  • 기존에 질문 리스트가 생성된 후, 질문을 생성하는 쿼리를 구현했었는데, 질문을 생성하는 쿼리에서 문제가 발생하면 빈 질문 리스트가 생성되는 오류가 있었습니다.
  • 이를 트랜잭션으로 묶어서 중간에 에러가 나면 아예 rollback 되도록 구현했습니다.
  • 트랜잭션 사용을 위해 queryRunner라는 것을 사용했습니다.
// question-list.service.ts
async createQuestionList(createQuestionListDto: CreateQuestionListDto) {
    const { title, contents, categoryNames, isPublic, userId } =
        createQuestionListDto;

    const categories = await this.findCategoriesByNames(categoryNames);

    const queryRunner = this.dataSource.createQueryRunner();
    await queryRunner.startTransaction();

    try {
        const questionListDto = new QuestionList();
        questionListDto.title = title;
        questionListDto.categories = categories;
        questionListDto.isPublic = isPublic;
        questionListDto.userId = userId;

        const createdQuestionList =
            await queryRunner.manager.save(questionListDto);

        const questions = contents.map((content, index) => {
            const question = new Question();
            question.content = content;
            question.index = index;
            question.questionList = createdQuestionList;

            return question;
        });

        const createdQuestions =
            await queryRunner.manager.save(questions);

        await queryRunner.commitTransaction();

        return { createdQuestionList, createdQuestions };
    } catch (error) {
        await queryRunner.rollbackTransaction();
        throw new Error(error.message);
    } finally {
        await queryRunner.release();
    }
}

📌 테스트 및 검증 결과

  • 변경 사항을 테스트하거나 검증한 방법, 간단한 결과 설명
  • 관련 스크린샷, 영상이 있다면 첨부

💬 다음 작업 또는 논의 사항

  • 내일 또는 이후에 진행할 예정인 작업
  • 추가적인 개선 사항이나 논의가 필요한 내용

Copy link
Member

@ShipFriend0516 ShipFriend0516 left a comment

Choose a reason for hiding this comment

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

빠른 수정 좋습니당

@ShipFriend0516 ShipFriend0516 merged commit 716ee13 into boostcampwm-2024:dev Nov 21, 2024
@blu3fishez
Copy link
Collaborator

고생하십니다! 바쁘시더라도 태그를 목적에 맞게 달아주세여 [Fix]!

@twalla26 twalla26 changed the title [Feat] 스터디룸 생성에 질문 내용 전달, 질문지 기능 버그 fix [Fix] 스터디룸 생성에 질문 내용 전달, 질문지 기능 버그 fix Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants