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/question list #53

Merged
merged 4 commits into from
Jan 15, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
51 changes: 51 additions & 0 deletions src/controller/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,56 @@ import constant from "../library/constant";
// services
import reviewService from "../service/review";

/**
* @질문리스트 조회하기
* @route GET /review/:reviewId/question-list
* @access private
* @error
* 1. 필요한 값이 없습니다.
* 2. 존재하지 않는 Review 입니다.
*/
const getQuestionController = async (req: Request, res: Response) => {
try {
const resData = await reviewService.getQuestionService(
Number(req.body.userID.id),
Number(req.params.reviewId)
);

if (resData === constant.NULL_VALUE) {
response.basicResponse(
res,
returnCode.BAD_REQUEST,
false,
"필요한 값이 없습니다."
);
} else if (resData === constant.WRONG_REQUEST_VALUE) {
response.basicResponse(
res,
returnCode.BAD_REQUEST,
false,
"존재하지 않는 Review입니다."
);
} else {
response.dataResponse(
res,
returnCode.OK,
"질문리스트 조회 성공.",
true,
resData
);
}
} catch (err) {
slack.slackWebhook(req, err.message);
console.error(err.message);
response.basicResponse(
res,
returnCode.INTERNAL_SERVER_ERROR,
false,
"서버 오류"
);
}
};

/**
* @독서중 독서 전 작성
* @route POST /review/before/:isbn
Expand Down Expand Up @@ -283,6 +333,7 @@ const reviewController = {
postReviewNowController,
patchReviewController,
getReviewController,
getQuestionController,
deleteReviewController,
};

Expand Down
7 changes: 7 additions & 0 deletions src/router/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ const router = express.Router();
// 독후감 조회
router.get("/:reviewId", authMiddleware, reviewController.getReviewController);

// 질문리스트 조회
router.get(
"/:reviewId/question-list",
authMiddleware,
reviewController.getQuestionController
);

// 독서 전
router.post(
"/before/:isbn",
Expand Down
33 changes: 33 additions & 0 deletions src/service/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,38 @@ import constant from "../library/constant";
// models
import { User, Book, Review } from "../models";

/**
* @질문리스트 조회하기
* @route GET /review/:reviewId/question-list
* @access private
* @error
* 1. 필요한 값이 없습니다.
* 2. 존재하지 않는 Review 입니다.
*/

const getQuestionService = async (userId: number, reviewId: number) => {
// 필요한 값이 없을 때
if (!userId || !reviewId) {
return constant.NULL_VALUE;
}

// review 조회
const review = await Review.findOne({
where: {
id: reviewId,
user_id: userId,
is_deleted: false,
},
});

// 존재하지 않는 리뷰일 때
if (!review) {
return constant.WRONG_REQUEST_VALUE;
}

return review.question_list;
Copy link
Contributor

Choose a reason for hiding this comment

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

{ 안에 넣어주세요 ㅋ.ㅋ }

Copy link
Member Author

Choose a reason for hiding this comment

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

수정요 {fix: ㅋ.ㅋ}

Copy link
Member

Choose a reason for hiding this comment

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

🤔 객체를 감싸서 보내줘야 되는거 아닌가?? 🤔 ? 🤔흠 ㅋ 🤔

};

/**
* @독서중 독서 전 작성
* @route POST /review/before/:isbn
Expand Down Expand Up @@ -264,6 +296,7 @@ const deleteReviewService = async (userId: number, reviewId: number) => {
};

const reviewService = {
getQuestionService,
postReviewBeforeService,
postReviewNowService,
patchReviewService,
Expand Down