Skip to content

Commit

Permalink
Merge pull request #16 from netCard-TUK/wonchan
Browse files Browse the repository at this point in the history
Card 전체 페이징 조회 구현
  • Loading branch information
Leewonchan14 authored Jan 23, 2024
2 parents 997791a + edd206e commit 94fbcbd
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/api/cards/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,47 @@ exports.inquiry = async (req, res) => {

return res.send(response);
};
// 모든 명함 페이징 조회
exports.findAll = async (req, res) => {
let page = req.query.page;
let size = req.query.size;

// 숫자 정규식
const regExp = /^[0-9]+$/;

// page, size가 숫자형이 아닐 경우
if (
!page ||
!size ||
!regExp.test(page) ||
!regExp.test(size)
) {
return res.send({
isSuccess: false,
message: "page, size는 숫자형으로 입력해주세요",
});
}

page = Number(page);
size = Number(size);

// page 또는 size가 0 이하일 경우
if (page < 0 || size < 0) {
return res.send({
isSuccess: false,
message: "page 또는 size는 0 이하로 입력할 수 없습니다.",
});
}

const findList = await repository.findAll(page, size);

console.log(findList);

return res.send({
isSuccess: true,
result: findList,
});
}

//특정 명함 정보 리스트 반환
exports.inquiry_list = async (req, res) => {
Expand Down
8 changes: 8 additions & 0 deletions src/api/cards/repogitory.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ exports.show_all = async (id) => {
return result.length < 0 ? null : result;
};

// 모든 명함 최신순 페이징 조회
exports.findAll = async (page, size) => {
const query = `
SELECT cards.* FROM cards ORDER BY created_at desc LIMIT ? OFFSET ?`;
const result = await pool(query, [size, page * size]);
return result.length < 0 ? null : result;
};

//특정 명함 전체 조회(이름 일치)
exports.show_all_as_name = async (name) => {
const query = `
Expand Down
3 changes: 3 additions & 0 deletions src/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ router.post(
verify,
cardsController.register
);
// 명함 전체 페이징 조회
router.get("/api/cards", cardsController.findAll);

router.get("/api/cards/search/:cardId", cardsController.inquiry);
router.get("/api/cards/search/list/:name", cardsController.inquiry_list);
router.get("/api/cards/search/all/:userId", cardsController.inquiry_all);
Expand Down

0 comments on commit 94fbcbd

Please sign in to comment.