Skip to content
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

Feat/fix tutoring time #55

Merged
merged 23 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
eab5e43
채팅 목록 불러오기 기반 작업
seongyunlee Sep 19, 2023
7c5c3e6
채팅 목록 불러오기 기반 작업
seongyunlee Sep 19, 2023
aea0fdd
채팅 목록 불러오기 스웨거 작업
seongyunlee Sep 20, 2023
ffa540c
채팅 보내기 repository 함수 생성
seongyunlee Sep 20, 2023
0b2f8b0
일반 질문 지정 질문 route 분리
seongyunlee Sep 20, 2023
b62f04c
일반 질문 지정 질문 로직 작성
seongyunlee Sep 20, 2023
85a1f81
지정 질문 선택시에 선생님 한테 메시지 보내짐
seongyunlee Sep 20, 2023
51e498e
일반 질문 숏과외 제안시 채팅 개시
seongyunlee Sep 20, 2023
dff65cb
일반 질문 숏과외 제안시 채팅 개시
seongyunlee Sep 20, 2023
0041fd9
Merge remote-tracking branch 'origin/dev' into feat/start_question
seongyunlee Sep 20, 2023
d15eb87
chatting list 반환할때 roomType 지정
seongyunlee Sep 20, 2023
9325ad1
chatting list 반환할때 roomType 지정
seongyunlee Sep 20, 2023
01c9ac2
학생 입장에서 일반질문 올리고 아무도 offer 없을때도 채팅 목록에서 보이게 수정
seongyunlee Sep 21, 2023
510fda0
Merge remote-tracking branch 'origin/dev' into feat/start_selected_qu…
seongyunlee Sep 21, 2023
7db6583
수업 시간 정하기 api 추가
seongyunlee Sep 22, 2023
e789049
수업 끝나면 question.status 도 finish로 바뀜
seongyunlee Sep 22, 2023
886278d
지정 질문 올릴때 question에 selectedteacherId 저장하도록 수정
seongyunlee Sep 22, 2023
83f7caf
튜터링 객체 만들때 startedAt, EndAt emptystring으로 해둔거 수정
seongyunlee Sep 22, 2023
34948f0
/tutoring/info 를 학생이 부를 때 선생님이 과외를 시작하지 않았으면 정보를 돌려주지 않고 success: fal…
seongyunlee Sep 22, 2023
f2adca9
일반 질문 학생이 선생님 선택하면 다른 선생님한테 메시지 가도록 수정.
seongyunlee Sep 22, 2023
a79ea44
선생님이 채팅 조회시 일반 질문 거절 당했을때 "normalreserve"로 분류되던걸 , "normalproposed"로 …
seongyunlee Sep 22, 2023
55ea389
Merge remote-tracking branch 'origin/dev' into feat/fix_tutoring_time
seongyunlee Sep 22, 2023
8821f2d
선생님이 채팅 조회시 일반 질문 거절 당했을때 텍스트 메시지를 받도록 변경
seongyunlee Sep 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 40 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
"@nestjs/websockets": "^10.2.1",
"agora-access-token": "^2.0.4",
"aws-sdk": "^2.1410.0",
"axios": "^1.5.0",
"cache-manager": "^5.2.3",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"cross-env": "^7.0.3",
"discord-webhook-node": "^1.1.8",
"dotenv": "^16.3.1",
Expand Down
21 changes: 20 additions & 1 deletion src/chatting/chatting.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ export class ChattingRepository {
}
}*/

async sendMessage(roomId: string, senderId: string, format: string, message) {
async sendMessage(
roomId: string,
senderId: string,
format: string,
message?: any,
) {
const chatting = await this.chattingModel.get({ id: roomId });
chatting.messages.push({
sender: senderId,
Expand All @@ -73,10 +78,24 @@ export class ChattingRepository {
});
}

async getIdByQuestionAndTeacher(questionId: string, teacherId: string) {
const result = await this.chattingModel
.scan({ questionId, teacherId })
.exec();
if (result.length > 0) {
return result[0].id;
}
throw new Error('채팅방을 찾을 수 없습니다.');
}

async getChatRoomsInfo(roomIds: ChattingKey[]) {
return await this.chattingModel.batchGet(roomIds);
}

/*
* 채팅 객체를 생성 합니다
* 이 함수는 user.participantingChattingRooms 에 추가 해주지 않음
*/
async makeChatRoom(teacherId: string, studentId: string, questionId: string) {
const chattingRoomId = uuid();
const chatting: Chatting = {
Expand Down
29 changes: 23 additions & 6 deletions src/chatting/chatting.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,23 @@ export class ChattingService {
roomInfo.questionId,
);
console.log(questionInfo);
const { status, isSelect } = questionInfo;
const { status, isSelect, selectedTeacherId } = questionInfo;
const { schoolSubject, schoolLevel, description } =
questionInfo.problem;

let chatState: 'pending' | 'reserved' | 'refused' = 'pending';

if (status == 'pending') {
chatState = 'pending';
} else if (status == 'reserved') {
if (userRole == 'student' || selectedTeacherId == userId) {
chatState = 'reserved';
} else {
// 선생님이 api 부른 경우에 거절 당한 경우.
chatState = 'refused';
}
}

const item = {
roomImage: undefined,
id: roomInfo.id,
Expand All @@ -71,15 +84,14 @@ export class ChattingService {
return { body: JSON.parse(body), isMyMsg: isMyMsg, ...rest };
}),
opponentId: undefined,
questionState: status,
questionState: chatState,
problemImages: questionInfo.problem.mainImage,
isSelect: isSelect,
isTeacherRoom: true,
questionId: roomInfo.questionId,
schoolSubject: schoolSubject,
schoolLevel: schoolLevel,
title: undefined,
status: status,
description: description,
};

Expand Down Expand Up @@ -107,13 +119,18 @@ export class ChattingService {

roomInfosWithQuestion.forEach((roomInfo) => {
if (roomInfo.isSelect) {
if (roomInfo.status === 'pending') {
//지정 질문
if (roomInfo.questionState === 'pending') {
result.selectedProposed.push(roomInfo);
} else if (roomInfo.status === 'reserved') {
} else if (roomInfo.questionState === 'reserved') {
result.selectedReserved.push(roomInfo);
}
} else {
if (roomInfo.status === 'pending') {
//일반 질문
if (
roomInfo.questionState === 'pending' ||
roomInfo.questionState === 'refused'
) {
if (userRole == 'student') {
//grouping by questionId
if (normalProposedGrouping[roomInfo.questionId]) {
Expand Down
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AppModule } from './app.module';
import { configSwagger } from './config.swagger';
import { ValidationPipe } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import * as dotenv from 'dotenv';
import { json, urlencoded } from 'express';
Expand All @@ -9,7 +10,7 @@ async function bootstrap() {
app.enableCors();
app.use(json({ limit: '50mb' }));
app.use(urlencoded({ limit: '50mb', extended: false }));

app.useGlobalPipes(new ValidationPipe({ transform: true }));
dotenv.config();
configSwagger(app);

Expand Down
23 changes: 22 additions & 1 deletion src/offer/offer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,28 @@ export class OfferService {
chatting.teacherId,
);

return new Success('선생님 선택이 완료되었습니다.', tutoring);
const question = await this.questionRepository.getInfo(questionId);

const offerTeacherIds = question.offerTeachers;

for (const offerTeacherId of offerTeacherIds) {
if (offerTeacherId != chatting.teacherId) {
const teacherChatId =
await this.chattingRepository.getIdByQuestionAndTeacher(
questionId,
offerTeacherId,
);
//TODO: redis pub/sub으로 변경
await this.chattingRepository.sendMessage(
teacherChatId,
userId,
'text',
'죄송합니다.\n다른 선생님과 수업을 진행하기로 했습니다.',
);
}
}

return new Success('선생님 선택이 완료되었습니다.');
} catch (error) {
return new Fail(error.message);
}
Expand Down
17 changes: 16 additions & 1 deletion src/question/question.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export class QuestionRepository {
async createSelectedQuestion(
questionId: string,
userId: string,
selectedTeacherId: string,
createQuestionDto: CreateSelectedQuestionDto,
problemImages: string[],
): Promise<Question> {
Expand All @@ -83,7 +84,7 @@ export class QuestionRepository {
schoolLevel: createQuestionDto.schoolLevel,
schoolSubject: createQuestionDto.schoolSubject,
},
selectedTeacherId: '',
selectedTeacherId: selectedTeacherId,
status: 'pending',
studentId: userId,
offerTeachers: [],
Expand Down Expand Up @@ -123,6 +124,20 @@ export class QuestionRepository {
return await this.questionModel.get({ id: questionId });
}

async changeStatus(questionId: string, status: string) {
return await this.questionModel.update(
{ id: questionId },
{ status: status },
);
}

async setSeletedTeacherId(questionId: string, teacherId: string) {
return await this.questionModel.update(
{ id: questionId },
{ selectedTeacherId: teacherId },
);
}

async delete(userId: string, questionId: string) {
const user: User = await this.userRepository.get(userId);
if (user.role === 'teacher') {
Expand Down
1 change: 1 addition & 0 deletions src/question/question.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export class QuestionService {
await this.questionRepository.createSelectedQuestion(
questionId,
userId,
teacherId,
createQuestionDto,
problemImages,
);
Expand Down
4 changes: 4 additions & 0 deletions src/tutoring/descriptions/tutoring.operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ export const TutoringOperation = {
summary: '과외 정보 조희',
description: '특정 과외의 정보를 조회합니다',
},
appoint: {
summary: '과외 시간 확정',
description: '특정 과외의 시작 종료 시간을 확정합니다',
},
};
20 changes: 20 additions & 0 deletions src/tutoring/dto/create-tutoring.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { ApiProperty } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import { IsDate } from 'class-validator';

export class CreateTutoringDto {
@ApiProperty({
Expand All @@ -19,3 +21,21 @@ export class CreateTutoringDto {
})
teacherId: string;
}

export class AppointTutoringDto {
@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;
}
4 changes: 3 additions & 1 deletion src/tutoring/entities/tutoring.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export interface TutoringKey {
}

export interface Tutoring extends TutoringKey {
requestId?: string;
questionId: string;
studentId: string;
teacherId: string;
status: string;
Expand All @@ -16,4 +16,6 @@ export interface Tutoring extends TutoringKey {
teacherRTCToken?: string;
studentRTCToken?: string;
RTCAppId?: string;
reservedStart?: Date;
reservedEnd?: Date;
}
8 changes: 7 additions & 1 deletion src/tutoring/entities/tutoring.schema.ts
w8385 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const TutoringSchema = new Schema({
type: String,
hashKey: true,
},
requestId: {
questionId: {
type: String,
},
studentId: {
Expand Down Expand Up @@ -44,4 +44,10 @@ export const TutoringSchema = new Schema({
RTCAppId: {
type: String,
},
reservedStart: {
type: Date,
},
reservedEnd: {
type: Date,
},
});
Loading