From 03fd14f69834f5fa099032c9eec3601073d50aa2 Mon Sep 17 00:00:00 2001 From: seongyunlee Date: Thu, 28 Sep 2023 00:18:01 +0900 Subject: [PATCH 1/4] =?UTF-8?q?=EC=9D=BC=EB=B0=98=20=EC=A7=88=EB=AC=B8=20?= =?UTF-8?q?=EC=84=A0=EC=83=9D=EB=8B=98=20=EC=84=A0=ED=83=9D=EC=8B=9C?= =?UTF-8?q?=EC=97=90=EB=8F=84=20=EC=98=88=EC=95=BD=20=EC=8B=9C=EA=B0=84=20?= =?UTF-8?q?=EC=A0=95=ED=95=98=EB=8A=94=20=EA=B2=83=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/offer/dto/accept-offer.dto.ts | 17 +++++++++++++++++ src/offer/offer.controller.ts | 2 ++ src/offer/offer.repository.ts | 19 +++++++------------ src/offer/offer.service.ts | 20 +++++++++++++++++--- 4 files changed, 43 insertions(+), 15 deletions(-) diff --git a/src/offer/dto/accept-offer.dto.ts b/src/offer/dto/accept-offer.dto.ts index 14c073a..dffb64f 100644 --- a/src/offer/dto/accept-offer.dto.ts +++ b/src/offer/dto/accept-offer.dto.ts @@ -1,4 +1,6 @@ import { ApiProperty } from '@nestjs/swagger'; +import { Type } from 'class-transformer'; +import { IsDate } from 'class-validator'; export class AcceptOfferDto { @ApiProperty({ @@ -7,4 +9,19 @@ export class AcceptOfferDto { '질문의 `teacherIds`에 포함되어 있어야 합니다.', }) chattingId: string; + @Type(() => Date) + @IsDate() + @ApiProperty({ + description: '수업 시작 날짜,시간', + example: '2023-11-30T18:00:00+09:00', + }) + startTime: Date; + + @Type(() => Date) + @IsDate() + @ApiProperty({ + description: '수업 종료 날짜,시간', + example: '2023-11-30T19:00:00+09:00', + }) + endTime: Date; } diff --git a/src/offer/offer.controller.ts b/src/offer/offer.controller.ts index 638e708..cb21619 100644 --- a/src/offer/offer.controller.ts +++ b/src/offer/offer.controller.ts @@ -75,6 +75,8 @@ export class OfferController { AccessToken.userId(headers), acceptOfferDto.chattingId, questionId, + acceptOfferDto.startTime, + acceptOfferDto.endTime, ); } } diff --git a/src/offer/offer.repository.ts b/src/offer/offer.repository.ts index 7157e38..dacbfa4 100644 --- a/src/offer/offer.repository.ts +++ b/src/offer/offer.repository.ts @@ -93,7 +93,12 @@ export class OfferRepository { } }*/ - async accept(userId: string, questionId: string, teacherId: string) { + async accept( + userId: string, + questionId: string, + teacherId: string, + tutoringId: string, + ) { const user: User = await this.userRepository.get(userId); if (user.role === 'teacher') { throw new Error('선생님은 질문을 수락할 수 없습니다.'); @@ -108,15 +113,7 @@ export class OfferRepository { throw new Error('질문 대기열에 존재하지 않는 선생님입니다.'); } - const tutoring = await this.tutoringRepository.create( - questionId, - userId, - question.selectedTeacherId, - ); - - const tutoringId = tutoring.id; - - await this.questionModel.update( + return await this.questionModel.update( { id: questionId }, { status: 'reserved', @@ -124,7 +121,5 @@ export class OfferRepository { tutoringId, }, ); - - return tutoring; } } diff --git a/src/offer/offer.service.ts b/src/offer/offer.service.ts index 34107c2..1d12aa2 100644 --- a/src/offer/offer.service.ts +++ b/src/offer/offer.service.ts @@ -1,6 +1,7 @@ import { ChattingRepository } from '../chatting/chatting.repository'; import { QuestionRepository } from '../question/question.repository'; import { Fail, Success } from '../response'; +import { TutoringRepository } from '../tutoring/tutoring.repository'; import { UserRepository } from '../user/user.repository'; import { OfferRepository } from './offer.repository'; import { Injectable } from '@nestjs/common'; @@ -12,6 +13,7 @@ export class OfferService { private readonly userRepository: UserRepository, private readonly chattingRepository: ChattingRepository, private readonly questionRepository: QuestionRepository, + private readonly tutoringRepository: TutoringRepository, ) {} async append(userId: string, questionId: string) { @@ -91,17 +93,29 @@ export class OfferService { } }*/ - async accept(userId: string, chattingId: string, questionId: string) { + async accept( + userId: string, + chattingId: string, + questionId: string, + startTime: Date, + endTime: Date, + ) { try { const chatting = await this.chattingRepository.getChatRoomInfo( chattingId, ); - const tutoring = await this.offerRepository.accept( - userId, + const tutoring = await this.tutoringRepository.create( questionId, + userId, chatting.teacherId, ); + await this.tutoringRepository.reserveTutoring( + tutoring.id, + startTime, + endTime, + ); + const question = await this.questionRepository.getInfo(questionId); const offerTeacherIds = question.offerTeachers; From 391b00687709c09676dee3237c1b3fa2561e6ef8 Mon Sep 17 00:00:00 2001 From: seongyunlee Date: Thu, 28 Sep 2023 00:26:19 +0900 Subject: [PATCH 2/4] =?UTF-8?q?=EC=9D=BC=EB=B0=98=20=EC=A7=88=EB=AC=B8=20?= =?UTF-8?q?=EC=84=A0=EC=83=9D=EB=8B=98=20=EC=84=A0=ED=83=9D=EC=8B=9C?= =?UTF-8?q?=EC=97=90=EB=8F=84=20=EC=98=88=EC=95=BD=20=EC=8B=9C=EA=B0=84=20?= =?UTF-8?q?=EC=A0=95=ED=95=98=EB=8A=94=20=EA=B2=83=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/offer/offer.service.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/offer/offer.service.ts b/src/offer/offer.service.ts index 595fd9a..214b5a0 100644 --- a/src/offer/offer.service.ts +++ b/src/offer/offer.service.ts @@ -2,6 +2,7 @@ import { ChattingRepository } from '../chatting/chatting.repository'; import { QuestionRepository } from '../question/question.repository'; import { Fail, Success } from '../response'; import { SocketGateway } from '../socket/socket.gateway'; +import { TutoringRepository } from '../tutoring/tutoring.repository'; import { UserRepository } from '../user/user.repository'; import { OfferRepository } from './offer.repository'; import { Injectable } from '@nestjs/common'; @@ -131,6 +132,22 @@ export class OfferService { const offerTeacherIds = question.offerTeachers; + const confirmMessage = { + text: `선생님과 수업이 확정되었습니다.\n수업 시간은 ${startTime} ~ ${endTime} 입니다.`, + }; + + await this.socketGateway.sendMessageToBothUser( + userId, + chatting.teacherId, + chattingId, + 'text', + JSON.stringify(confirmMessage), + ); + + const rejectMessage = { + text: '죄송합니다.\n다른 선생님과 수업을 진행하기로 했습니다.', + }; + for (const offerTeacherId of offerTeacherIds) { if (offerTeacherId != chatting.teacherId) { const teacherChatId = @@ -144,7 +161,7 @@ export class OfferService { offerTeacherId, teacherChatId, 'text', - '죄송합니다.\n다른 선생님과 수업을 진행하기로 했습니다.', + JSON.stringify(rejectMessage), ); } } From d54500d90224499d71eb0ffd94d330ee6930ae30 Mon Sep 17 00:00:00 2001 From: seongyunlee Date: Thu, 28 Sep 2023 01:30:42 +0900 Subject: [PATCH 3/4] =?UTF-8?q?=EC=9D=BC=EB=B0=98=20=EC=A7=88=EB=AC=B8=20?= =?UTF-8?q?=EC=84=A0=EC=83=9D=EB=8B=98=20=EC=84=A0=ED=83=9D=EC=8B=9C?= =?UTF-8?q?=EC=97=90=EB=8F=84=20=EC=98=88=EC=95=BD=20=EC=8B=9C=EA=B0=84=20?= =?UTF-8?q?=EC=A0=95=ED=95=98=EB=8A=94=20=EA=B2=83=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/offer/offer.service.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/offer/offer.service.ts b/src/offer/offer.service.ts index 214b5a0..2c6ebda 100644 --- a/src/offer/offer.service.ts +++ b/src/offer/offer.service.ts @@ -132,6 +132,8 @@ export class OfferService { const offerTeacherIds = question.offerTeachers; + await this.questionRepository.changeStatus(questionId, 'reserved'); + const confirmMessage = { text: `선생님과 수업이 확정되었습니다.\n수업 시간은 ${startTime} ~ ${endTime} 입니다.`, }; From 426981eaba079a0b3790f85dbc687c2026d9cbb2 Mon Sep 17 00:00:00 2001 From: seongyunlee Date: Thu, 28 Sep 2023 02:32:06 +0900 Subject: [PATCH 4/4] =?UTF-8?q?=EC=9D=BC=EB=B0=98=20=EC=A7=88=EB=AC=B8=20?= =?UTF-8?q?=EC=84=A0=EC=83=9D=EB=8B=98=20=EC=84=A0=ED=83=9D=EC=8B=9C?= =?UTF-8?q?=EC=97=90=EB=8F=84=20=EC=98=88=EC=95=BD=20=EC=8B=9C=EA=B0=84=20?= =?UTF-8?q?=EC=A0=95=ED=95=98=EB=8A=94=20=EA=B2=83=EC=9C=BC=EB=A1=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/chatting/chatting.service.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/chatting/chatting.service.ts b/src/chatting/chatting.service.ts index 6981371..e522ea7 100644 --- a/src/chatting/chatting.service.ts +++ b/src/chatting/chatting.service.ts @@ -101,11 +101,16 @@ export class ChattingService { let status: ChattingStatus; if (questionInfo.status == 'pending') { status = ChattingStatus.pending; - } else if (questionInfo.status == 'reserved') { + } else if ( + questionInfo.status == 'reserved' && + userInfo.role == 'teacher' + ) { status = roomInfo.teacherId == questionInfo.selectedTeacherId ? ChattingStatus.reserved : ChattingStatus.pending; + } else { + status = ChattingStatus.reserved; } let roomImage: string; let opponentInfo: User | undefined;