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

Revert "[FEAT] 템플릿별 고민조회하기 API에도 pagination추가" #79

Merged
merged 1 commit into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 4 additions & 4 deletions src/controller/worryController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ const getWorryList = async (req: Request, res: Response, next: NextFunction) =>

const getWorryListByTemplate = async (req: Request, res: Response, next: NextFunction) => {
try {
const { templateId,page,limit } = req.query;
if(!templateId || !page || !limit)
throw new ClientException("필요한 query 값이 존재하지 않습니다.");
const { templateId } = req.query;
if(!templateId)
throw new ClientException("templateId 값이 존재하지 않습니다.");
const { userId }= req.body;
const data = await worryService.getWorryListByTemplate(+templateId,userId,+page,+limit);
const data = await worryService.getWorryListByTemplate(+templateId,userId);

return res.status(sc.OK).send(success(statusCode.OK, rm.GET_WORRY_LIST_BY_TEMPLATE_SUCCESS,data));

Expand Down
28 changes: 25 additions & 3 deletions src/repository/worryRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,29 @@ const updateDeadline = async(deadlineUpdateDAO: deadlineUpdateDAO) => {
})
}

const findAllWorryListSolved = async(userId: number) => {

return await prisma.worry.findMany({
select:{
id:true,
user_id:true,
template_id:true,
title:true,
created_at:true,
updated_at:true
},
where: {
user_id: userId,
final_answer:{
not: null
}
},
orderBy:{
updated_at: 'desc'
}
})
}

const findWorryListSolved = async(userId: number, page: number, limit: number) => {

return await prisma.worry.findMany({
Expand Down Expand Up @@ -176,7 +199,7 @@ const findWorryListUnsolved = async(userId: number, page: number, limit: number)
})
}

const findWorryListByTemplate = async(templateId: number,userId: number, page: number, limit: number) => {
const findWorryListByTemplate = async(templateId: number,userId: number) => {

return await prisma.worry.findMany({
select:{
Expand All @@ -193,8 +216,6 @@ const findWorryListByTemplate = async(templateId: number,userId: number, page: n
not: null
}
},
skip: (page - 1) * limit,
take: limit,
orderBy:{
updated_at: 'desc'
}
Expand All @@ -209,6 +230,7 @@ export default {
createFinalAnswer,
updateDeadline,
findWorryListSolved,
findAllWorryListSolved,
findWorryListUnsolved,
findWorryListByTemplate

Expand Down
4 changes: 1 addition & 3 deletions src/router/worryRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ router.patch("/",
router.get("/",
auth,
[
query('templateId').notEmpty().withMessage("query string 에 'templateId' 값이 존재하지 않습니다"),
query('page').notEmpty().withMessage("query string 에 'page' 값이 존재하지 않습니다"),
query('limit').notEmpty().withMessage("query string 에 'limit' 값이 존재하지 않습니다")
query('templateId').notEmpty().withMessage("query string 에 'templateId' 값이 존재하지 않습니다")
],
validate,
worryController.getWorryListByTemplate,
Expand Down
6 changes: 3 additions & 3 deletions src/service/worryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,12 @@ const getWorryList =async (isSolved: number, page: number, limit: number, userId

}

const getWorryListByTemplate =async (templateId: number, userId: number, page: number, limit: number) => {
const getWorryListByTemplate =async (templateId: number, userId: number) => {
let worry;
if(templateId == 0)
worry = await worryRepository.findWorryListSolved(userId,page,limit);
worry = await worryRepository.findAllWorryListSolved(userId);
else
worry = await worryRepository.findWorryListByTemplate(templateId,userId,page,limit);
worry = await worryRepository.findWorryListByTemplate(templateId,userId);

if (!worry) {
throw new ClientException(rm.GET_WORRY_LIST_BY_TEMPLATE_FAIL);
Expand Down