Skip to content

Commit

Permalink
feat : /main/v2 -> page, pageSize 페이징처리 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
seungwanRyu01 committed Sep 13, 2023
1 parent 67f62f1 commit 7ef85af
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
16 changes: 13 additions & 3 deletions src/app/Controller/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,9 @@ exports.deleteUser = async function (req, res) {
* genderFilter(A,F,M) A : 전체, F : 여성, M : 남성
* ageFilterMax(N, 숫자)
* ageFilterMin(N, 숫자)
* runningTag(A : 퇴근 후, B : 출근 전, H : 휴일, W : 전체)
* runningTag(A : 퇴근 후, B : 출근 전, H : 휴일, W : 전체),
* page(현재 페이지 위치),
* pageSize(한 페이지 당 출력 갯수)
*/
exports.main2 = async function (req, res) {

Expand All @@ -784,6 +786,8 @@ exports.main2 = async function (req, res) {
const keywordSearch = req.query.keywordSearch; // N : 필터 x, 그 외 키워드 검색
const userId = req.query.userId;
const runningTag = req.query.runningTag;
const page = req.query.page;
const pageSize = req.query.pageSize;

// 빈 값 체크
if (!userLongitude) return res.send(response(baseResponse.LONGITUDE_EMPTY));
Expand All @@ -801,6 +805,8 @@ exports.main2 = async function (req, res) {
return res.send(response(baseResponse.AGE_MAX_FILTER_EMPTY));
if (!keywordSearch) return res.send(response(baseResponse.KEY_WORD_EMPTY));
if (!runningTag) return res.send(response(baseResponse.RUNNONGTAG_EMPTY));
if (!page) return res.send(response(baseResponse.PAGE_EMPTY));
if (!pageSize) return res.send(response(baseResponse.PAGE_SIZE_EMPTY));

// 길이 체크
if (keywordSearch.length > 10)
Expand Down Expand Up @@ -913,7 +919,9 @@ exports.main2 = async function (req, res) {
jobCondition,
ageCondition,
keywordCondition,
runningTagCondition
runningTagCondition,
page,
pageSize
);
return res.send(response(baseResponse.SUCCESS, mainResult));
} else {
Expand All @@ -929,7 +937,9 @@ exports.main2 = async function (req, res) {
ageCondition,
keywordCondition,
runningTagCondition,
userId
userId,
page,
pageSize
);
return res.send(response(baseResponse.SUCCESS, mainResult));
}
Expand Down
16 changes: 10 additions & 6 deletions src/app/Dao/userDao.js
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,9 @@ async function getMain2(
jobCondition,
ageCondition,
keywordCondition,
runningTagCondition
runningTagCondition,
page,
pageSize
) {
const getMainQuery = `
SELECT P.postId, P.createdAt as postingTime, postUserId, U.nickName, U.profileImageUrl, title,
Expand Down Expand Up @@ -673,8 +675,8 @@ async function getMain2(
WHERE P.status != 'D' ${distanceCondition} ${whetherEndCondition} ${genderCondition} ${jobCondition} ${ageCondition} ${keywordCondition} ${runningTagCondition}
and U.status != 'R'
ORDER BY "${sortCondition}"
LIMIT 10;
`;
LIMIT ${(page - 1) * pageSize}, ${pageSize};
`;
const [mainRows] = await connection.query(getMainQuery);
return mainRows;
}
Expand All @@ -692,7 +694,9 @@ async function getMain2Login(
ageCondition,
keywordCondition,
runningTagCondition,
userId
userId,
page,
pageSize
) {
const getMainQuery = `
SELECT P.postId, P.createdAt as postingTime, postUserId, U.nickName, U.profileImageUrl, title,
Expand Down Expand Up @@ -724,8 +728,8 @@ async function getMain2Login(
WHERE P.status != 'D' ${distanceCondition} ${whetherEndCondition} ${genderCondition} ${jobCondition} ${ageCondition} ${keywordCondition} ${runningTagCondition}
and U.status != 'R'
ORDER BY "${sortCondition}"
LIMIT 10;
`;
LIMIT ${(page - 1) * pageSize}, ${pageSize};
`;
const [mainRows] = await connection.query(getMainQuery);
return mainRows;
}
Expand Down
16 changes: 12 additions & 4 deletions src/app/Provider/userProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,9 @@ exports.getMain2 = async function (
jobCondition,
ageCondition,
keywordCondition,
runningTagCondition
runningTagCondition,
page,
pageSize
) {
const connection = await pool.getConnection(async (conn) => conn);
try {
Expand All @@ -309,7 +311,9 @@ exports.getMain2 = async function (
jobCondition,
ageCondition,
keywordCondition,
runningTagCondition
runningTagCondition,
page,
pageSize
);

if (getMainResult.length !== 0) {
Expand Down Expand Up @@ -344,7 +348,9 @@ exports.getMain2Login = async function (
ageCondition,
keywordCondition,
runningTagCondition,
userId
userId,
page,
pageSize
) {
const connection = await pool.getConnection(async (conn) => conn);
try {
Expand All @@ -360,7 +366,9 @@ exports.getMain2Login = async function (
ageCondition,
keywordCondition,
runningTagCondition,
userId
userId,
page,
pageSize
);

if (getMainResult.length !== 0) {
Expand Down

0 comments on commit 7ef85af

Please sign in to comment.