Skip to content

Commit

Permalink
Merge pull request #24 from TEAM-ITERVIEW/#23
Browse files Browse the repository at this point in the history
[feat] 면접 대답 저장 후 피드백 생성(chatGPT) API
  • Loading branch information
cha2y0ung authored Mar 27, 2024
2 parents aad96bf + ed42578 commit 426ccdf
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 7 deletions.
17 changes: 16 additions & 1 deletion src/controller/interviewController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { startInterviewDTO } from '../interface/DTO';
import { startInterviewDTO, makeFeedbackDTO } from '../interface/DTO';
import { Request, Response, NextFunction } from 'express';
import { message, statusCode } from '../module/constant';
import { success } from '../module/constant/utils';
Expand All @@ -19,6 +19,21 @@ const startInterview = async (req: Request, res: Response, next: NextFunction) =
}
};

const makeFeedback = async (req: Request, res: Response, next: NextFunction) => {
const makeFeedbackDTO: makeFeedbackDTO = req.body;

try {
const data = await interviewService.makeFeedback(makeFeedbackDTO);

return res
.status(statusCode.CREATED)
.send(success(statusCode.CREATED, message.MAKE_FEEDBACK_SUCCESS, data));
} catch (error) {
next(error);
}
}

export default {
startInterview,
makeFeedback,
};
10 changes: 10 additions & 0 deletions src/interface/DTO.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { LargeNumberLike } from "crypto";

export interface startInterviewDTO {
subjectText: string;
questionNum: number;
onlyVoice: boolean;
startDateTime: string;
}

export interface makeFeedbackDTO{
mumble: number;
silent: number;
talk: number;
time: number;
text: string;
}
1 change: 1 addition & 0 deletions src/module/constant/responseMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export default {
INTERNAL_SERVER_ERROR: "서버 내 오류",

START_INTERVIEW_SUCCESS: "인터뷰 시작 성공",
MAKE_FEEDBACK_SUCCESS: "피드백 생성 성공",
};
13 changes: 13 additions & 0 deletions src/router/interviewRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,18 @@ router.post(
interviewController.startInterview,
);

router.post(
'/answers/:interviewQuestionId',
[
param('interviewQuestionId').notEmpty(),
body('mumble'),
body('silent'),
body('talk'),
body('time'),
body('text'),
],
errorValidator,
interviewController.makeFeedback,
)

export default router;
72 changes: 66 additions & 6 deletions src/service/interviewService.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { startInterviewDTO } from '../interface/DTO';
import { startInterviewDTO, makeFeedbackDTO } from '../interface/DTO';
import { PrismaClient } from '@prisma/client';
import errorGenerator from '../middleware/error/errorGenerator';
import { message, statusCode } from '../module/constant';
const prisma = new PrismaClient();

const startInterview = async (startInterviewDTO: startInterviewDTO, refreshToken: string) => {
try {
const findUserId = await prisma.User.find({
const findUserId = await prisma.user.find({
where: {
refreshToken: refreshToken,
},
Expand All @@ -15,7 +15,7 @@ const startInterview = async (startInterviewDTO: startInterviewDTO, refreshToken
},
});

const findSubjectId = await prisma.Subject.find({
const findSubjectId = await prisma.subject.find({
where: {
subjectText: startInterviewDTO.subjectText,
},
Expand All @@ -24,15 +24,15 @@ const startInterview = async (startInterviewDTO: startInterviewDTO, refreshToken
},
});

const countInterviewToday = await prisma.Subject.findMany({
const countInterviewToday = await prisma.subject.findMany({
include: {
_count: {
select: {startDateTime: startInterviewDTO.startDateTime}
}
}
});

const questionList = await prisma.Question.findMany({
const questionList = await prisma.question.findMany({
where: {
subjectId: findSubjectId.id
},
Expand All @@ -49,7 +49,7 @@ const startInterview = async (startInterviewDTO: startInterviewDTO, refreshToken
selectedQuestions.push(shuffledQuestions[i]);
};

const interview = await prisma.Interview.create({
const interview = await prisma.interview.create({
data: {
userId: findUserId.id,
subjectId: findSubjectId.id,
Expand All @@ -64,12 +64,72 @@ const startInterview = async (startInterviewDTO: startInterviewDTO, refreshToken
})),
},
});

const interviewQuestionPromises = selectedQuestions.map(async (question) => {
const createdInterviewQuestion = await prisma.interviewQuestion.create({
data: {
interviewId: interview.id,
questionId: question.id,
userId: findUserId.id,
subjectId: findSubjectId.id,
}
});
return createdInterviewQuestion
});

const createdInterviewQuestion = await Promise.all(interviewQuestionPromises)
return interview;
} catch (error) {
throw error;
}
};

const makeFeedback = async (makeFeedbackDTO: makeFeedbackDTO, interviewQuestionId: number) => {
try {
const findInterviewQuestion = await.prisma.interviewQuestion.find({
where: {
id: interviewQuestionId,
},
select: {
interviewId: true,
questionId: true,
userId: true,
subjectId: true,
pin: true,
again: true,
}
});

const answer = await prisma.answer.create({
data: {
interviewQuestionId: interviewQuestionId,
questionId: findInterviewQuestion.questionId,
interviewId: findInterviewQuestion.interviewId,
text: makeFeedbackDTO.text,
mumble: makeFeedbackDTO.mumble,
silent: makeFeedbackDTO.silent,
talk: makeFeedbackDTO.talk,
time: makeFeedbackDTO.time,
}
});

const feedback = await prisma.feedback.create({
data: {
interviewQuestionId: interviewQuestionId,
answerId: answer.id,
interviewId: answer.interviewId,
score: null,
feedbackText: null,
}
})

return answer;
} catch(error) {
throw error;
}
}

export default {
startInterview,
makeFeedback,
};

0 comments on commit 426ccdf

Please sign in to comment.