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

학생이 자신이 올린 질문 목록을 조회하는 api #80

Merged
merged 4 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
4 changes: 4 additions & 0 deletions src/question/descriptions/question.operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ export const QuestionOperation = {
summary: '질문 정보 조회',
description: '질문 정보를 조회합니다.',
},
getMyQuestions: {
summary: '내 질문 목록 조회',
description: '내 질문 목록을 조회합니다.',
},
};
12 changes: 12 additions & 0 deletions src/question/descriptions/question.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,16 @@ export const QuestionQuery = {
enum: ['all', 'pending', 'matched', 'canceled', 'expired', 'completed'],
required: true,
},
getMyQuestions: {
status: {
name: 'status',
description: '질문 상태를 기준으로 필터링하여 목록을 조회합니다.',
enum: ['all', 'pending', 'reserved'],
},
type: {
name: 'type',
description: '질문 타입을 기준으로 필터링하여 목록을 조회합니다.',
enum: ['all', 'normal', 'selected'],
},
},
};
30 changes: 29 additions & 1 deletion src/question/question.controller.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
import { AccessToken } from '../auth/entities/auth.entity';
import { QuestionOperation } from './descriptions/question.operation';
import { QuestionQuery } from './descriptions/question.query';
import { QuestionResponse } from './descriptions/question.response';
import {
CreateNormalQuestionDto,
CreateSelectedQuestionDto,
} from './dto/create-question.dto';
import { QuestionService } from './question.service';
import { Body, Controller, Get, Headers, Param, Post } from '@nestjs/common';
import {
Body,
Controller,
Get,
Headers,
Param,
Post,
Query,
} from '@nestjs/common';
import {
ApiBearerAuth,
ApiOperation,
ApiQuery,
ApiResponse,
ApiTags,
} from '@nestjs/swagger';
Expand Down Expand Up @@ -57,6 +67,24 @@ export class QuestionController {
return this.questionService.delete(AccessToken.userId(headers), questionId);
}

@ApiTags('Student')
@ApiBearerAuth('Authorization')
@ApiOperation(QuestionOperation.getMyQuestions)
@ApiQuery(QuestionQuery.getMyQuestions.type)
@ApiQuery(QuestionQuery.getMyQuestions.status)
@Get('student/question/list/my')
getMyQuestions(
@Query('status') status: string,
@Query('type') type: string,
@Headers() headers: Headers,
) {
return this.questionService.getMyQuestions(
AccessToken.userId(headers),
status,
type,
);
}

@ApiTags('Teacher')
@ApiBearerAuth('Authorization')
@ApiOperation(QuestionOperation.list)
Expand Down
19 changes: 19 additions & 0 deletions src/question/question.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,23 @@ export class QuestionRepository {
},
);
}

async getMyQuestions(userId: string, status: string, type: string) {
console.log(status, type);
Fixed Show fixed Hide fixed
const condition = {
studentId: { eq: userId },
};
if (status !== 'all') {
condition['status'] = { eq: status };
}
if (type !== 'all') {
const isSelect = type === 'selected';
condition['isSelect'] = { eq: isSelect };
}
console.log(condition);

const questions = await this.questionModel.scan(condition).exec();

return questions.map((question) => question);
}
}
19 changes: 19 additions & 0 deletions src/question/question.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,23 @@ export class QuestionService {
return new Fail(error.message);
}
}

async getMyQuestions(userId: string, status: string, type: string) {
try {
const user = await this.userRepository.get(userId);
if (user.role !== 'student') {
return new Fail('학생 사용자가 아닙니다');
}

const questions = await this.questionRepository.getMyQuestions(
userId,
status,
type,
);
console.log(questions);
return new Success('질문 목록을 불러왔습니다.', questions);
} catch (error) {
return new Fail('사용자의 질문 목록을 불러오는데 실패했습니다.');
}
}
}