Skip to content

Commit

Permalink
Merge pull request #79 from TeamHARA/revert-78-feat/pagination
Browse files Browse the repository at this point in the history
Revert "[FEAT] 템플릿별 고민조회하기 API에도 pagination추가"
  • Loading branch information
leGit-y authored Nov 19, 2023
2 parents 624456a + eff5e5b commit 8ed981f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
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

0 comments on commit 8ed981f

Please sign in to comment.