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

[FIX] 번개 탭에 따라 검색 기능 분리 #160

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions src/constants/responseMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ module.exports = {
LIGHT_GET_NEW_SUCCESS: 'New 번개 조회 성공',
LIGHT_GET_HOT_SUCCESS: 'Hot 번개 조회 성공',
LIGHT_GET_SEARCH_SUCCESS: 'Search 번개 조회 성공',
LIGHT_GET_MY_ENTER_SEARCH_SUCCESS: '내가 참여한 번개 검색 조회 성공',
LIGHT_GET_MY_SCARP_SEARCH_SUCCESS: '내가 찜한 번개 검색 조회 성공',
LIGHT_GET_MY_OPEN_SEARCH_SUCCESS: '내가 오픈한 번개 검색 조회 성공',
NOT_LIGHT_ORGANIZER: '번개 소유자가 아닙니다.',
EXIST_LIGHT_USER: '해당 번개에 참여중 입니다.',
EXIST_NOT_LIGHT_USER: '해당 번개에 참여중이 아닙니다.',
Expand Down
86 changes: 85 additions & 1 deletion src/controller/lightController.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,87 @@ const ExistLightUser = async (req, res, next) => {
return next(new Error('existLightUser Controller 에러: \n' + error));
}
};
const getSearchMyEnterLight = async (req, res, next) => {
const memberId = req.user.id;
const { crewId } = req.params;
const search = req.query.search;
const category = req.query.category;

var curpage = req.query.curpage || 1;
var pageSize = req.query.pageSize || 5;

let offset = (curpage - 1) * Number(pageSize);
let limit = Number(pageSize);

if (!memberId) {
return res.status(statusCode.BAD_REQUEST).send(util.fail(statusCode.BAD_REQUEST, responseMessage.NULL_VALUE));
}

if (search.length < 2) {
return res.status(statusCode.BAD_REQUEST).send(util.fail(statusCode.BAD_REQUEST, responseMessage.NO_TWO_SEARCH_QUERY));
}
try {
const lights = await lightService.getSearchMyEnterLight(memberId, crewId, search, category, offset, limit);

return res.status(lights.status).json(lights);
} catch (error) {
return next(new Error('getSearchLight Controller 에러: \n' + error));
}
};
const getSearchMyScrapLight = async (req, res, next) => {
const memberId = req.user.id;
const { crewId } = req.params;
const search = req.query.search;
const category = req.query.category;

var curpage = req.query.curpage || 1;
var pageSize = req.query.pageSize || 5;

let offset = (curpage - 1) * Number(pageSize);
let limit = Number(pageSize);

if (!memberId) {
return res.status(statusCode.BAD_REQUEST).send(util.fail(statusCode.BAD_REQUEST, responseMessage.NULL_VALUE));
}

if (search.length < 2) {
return res.status(statusCode.BAD_REQUEST).send(util.fail(statusCode.BAD_REQUEST, responseMessage.NO_TWO_SEARCH_QUERY));
}
try {
const lights = await lightService.getSearchMyScrapLight(memberId, crewId, search, category, offset, limit);

return res.status(lights.status).json(lights);
} catch (error) {
return next(new Error('getSearchLight Controller 에러: \n' + error));
}
};
const getSearchMyOpenLight = async (req, res, next) => {
const memberId = req.user.id;
const { crewId } = req.params;
const search = req.query.search;
const category = req.query.category;

var curpage = req.query.curpage || 1;
var pageSize = req.query.pageSize || 5;

let offset = (curpage - 1) * Number(pageSize);
let limit = Number(pageSize);

if (!memberId) {
return res.status(statusCode.BAD_REQUEST).send(util.fail(statusCode.BAD_REQUEST, responseMessage.NULL_VALUE));
}

if (search.length < 2) {
return res.status(statusCode.BAD_REQUEST).send(util.fail(statusCode.BAD_REQUEST, responseMessage.NO_TWO_SEARCH_QUERY));
}
try {
const lights = await lightService.getSearchMyOpenLight(memberId, crewId, search, category, offset, limit);

return res.status(lights.status).json(lights);
} catch (error) {
return next(new Error('getSearchLight Controller 에러: \n' + error));
}
};

module.exports = {
addLight,
Expand All @@ -262,5 +343,8 @@ module.exports = {
getNewLight,
getHotLight,
getSearchLight,
ExistLightUser
ExistLightUser,
getSearchMyEnterLight,
getSearchMyScrapLight,
getSearchMyOpenLight
};
127 changes: 126 additions & 1 deletion src/db/lightDao.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,125 @@ const IsLightOrganizer = async (client, lightId, userId) => {
throw new Error('lightdao.IsLightOrganizer 에러 발생했습니다 \n' + error);
}
};
const getSearchLightUseCategoryInMyEnterLight = async (client, search, category, crewId,memberId, offset, limit) => {
try {
const { rows } = await client.query(
`
select l.id, category, scp_cnt, join_cnt, title, date, time, people_cnt, description, image, place from light l
left join (select light_id, count(id) join_cnt from light_user group by light_id) ls on l.id = ls.light_id
left join (select light_id, count(id) scp_cnt from scrap group by light_id) ld on l.id = ld.light_id
inner join light_user lu on l.id = lu.light_id
where (l.title LIKE CONCAT('%', $1::text, '%') or l.description Like CONCAT('%', $1::text, '%')) and category = $2 and l.crew_id = $3
and lu.member_id = $4
offset $5
limit $6;
`,
[search, category, crewId, memberId, offset, limit],
);
return convertSnakeToCamel.keysToCamel(rows);
} catch (error) {
throw new Error('lightdao.getSearchLightUseCategoryInMyEnterLight 에러 발생했습니다 \n' + error);
}
};
const getSearchLightNotCategoryInMyEnterLight = async (client, search, crewId, memberId, offset, limit) => {
try {
const { rows } = await client.query(
`
select l.id, category, scp_cnt, join_cnt, title, date, time, people_cnt, description, image, place from light l
left join (select light_id, count(id) join_cnt from light_user group by light_id) ls on l.id = ls.light_id
left join (select light_id, count(id) scp_cnt from scrap group by light_id) ld on l.id = ld.light_id
inner join light_user lu on l.id = lu.light_id
where (l.title LIKE CONCAT('%', $1::text, '%') or l.description Like CONCAT('%', $1::text, '%')) and l.crew_id = $2
and lu.member_id = $3
offset $4
limit $5;
`,
[search, crewId, memberId, offset, limit],
);
return convertSnakeToCamel.keysToCamel(rows);
} catch (error) {
throw new Error('lightdao.getSearchLightNotCategoryInMyEnterLight 에러 발생했습니다 \n' + error);
}
};
const getSearchLightUseCategoryInMyScrapLight = async (client, search, category, crewId,memberId, offset, limit) => {
try {
const { rows } = await client.query(
`
select l.id, category, scp_cnt, join_cnt, title, date, time, people_cnt, description, image, place from light l
left join (select light_id, count(id) join_cnt from light_user group by light_id) ls on l.id = ls.light_id
left join (select light_id, count(id) scp_cnt from scrap group by light_id) ld on l.id = ld.light_id
inner join scrap s on l.id = s.light_id
where (l.title LIKE CONCAT('%', $1::text, '%') or l.description Like CONCAT('%', $1::text, '%')) and category = $2 and l.crew_id = $3
and s.member_id = $4
offset $5
limit $6;
`,
[search, category, crewId, memberId, offset, limit],
);
return convertSnakeToCamel.keysToCamel(rows);
} catch (error) {
throw new Error('lightdao.getSearchLightUseCategoryInMyScrapLight 에러 발생했습니다 \n' + error);
}
};
const getSearchLightNotCategoryInMyScrapLight = async (client, search, crewId, memberId, offset, limit) => {
try {
const { rows } = await client.query(
`
select l.id, category, scp_cnt, join_cnt, title, date, time, people_cnt, description, image, place from light l
left join (select light_id, count(id) join_cnt from light_user group by light_id) ls on l.id = ls.light_id
left join (select light_id, count(id) scp_cnt from scrap group by light_id) ld on l.id = ld.light_id
inner join scrap s on l.id = s.light_id
where (l.title LIKE CONCAT('%', $1::text, '%') or l.description Like CONCAT('%', $1::text, '%')) and l.crew_id = $2
and s.member_id = $3
offset $4
limit $5;
`,
[search, crewId, memberId, offset, limit],
);
return convertSnakeToCamel.keysToCamel(rows);
} catch (error) {
throw new Error('lightdao.getSearchLightNotCategoryInMyScrapLight 에러 발생했습니다 \n' + error);
}
};
const getSearchLightUseCategoryInMyOpenLight = async (client, search, category, crewId,memberId, offset, limit) => {
try {
const { rows } = await client.query(
`
select l.id, category, scp_cnt, join_cnt, title, date, time, people_cnt, description, image, place from light l
left join (select light_id, count(id) join_cnt from light_user group by light_id) ls on l.id = ls.light_id
left join (select light_id, count(id) scp_cnt from scrap group by light_id) ld on l.id = ld.light_id
where (l.title LIKE CONCAT('%', $1::text, '%') or l.description Like CONCAT('%', $1::text, '%')) and category = $2 and l.crew_id = $3
and l.organizer_id = $4
offset $5
limit $6;
`,
[search, category, crewId, memberId, offset, limit],
);
return convertSnakeToCamel.keysToCamel(rows);
} catch (error) {
throw new Error('lightdao.getSearchLightUseCategoryInMyOpenLight 에러 발생했습니다 \n' + error);
}
};

const getSearchLightNotCategoryInMyOpenLight = async (client, search, crewId, memberId, offset, limit) => {
try {
const { rows } = await client.query(
`
select l.id, category, scp_cnt, join_cnt, title, date, time, people_cnt, description, image, place from light l
left join (select light_id, count(id) join_cnt from light_user group by light_id) ls on l.id = ls.light_id
left join (select light_id, count(id) scp_cnt from scrap group by light_id) ld on l.id = ld.light_id
where (l.title LIKE CONCAT('%', $1::text, '%') or l.description Like CONCAT('%', $1::text, '%')) and l.crew_id = $2
and l.organizer_id = $3
offset $4
limit $5;
`,
[search, crewId, memberId, offset, limit],
);
return convertSnakeToCamel.keysToCamel(rows);
} catch (error) {
throw new Error('lightdao.getSearchLightNotCategoryInMyOpenLight 에러 발생했습니다 \n' + error);
}
};
module.exports = {
addLight,
putLight,
Expand All @@ -340,5 +458,12 @@ module.exports = {
getHotLight,
getSearchLightUseCategory,
getSearchLightNotCategory,
IsLightOrganizer
IsLightOrganizer,
getSearchLightUseCategoryInMyEnterLight,
getSearchLightNotCategoryInMyEnterLight,
getSearchLightUseCategoryInMyScrapLight,
getSearchLightNotCategoryInMyScrapLight,
getSearchLightUseCategoryInMyOpenLight,
getSearchLightNotCategoryInMyOpenLight

};
5 changes: 4 additions & 1 deletion src/routes/lightApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ router.get('/:crewId/new', authMiddleware, lightController.getNewLight);
router.get('/:crewId/search', authMiddleware, lightController.getSearchLight);
router.get('/:crewId/hot', authMiddleware, lightController.getHotLight);
router.get('/:crewId', lightController.getCategoryLight);
router.get('/:lightId', lightController.getLightDetail);
router.get('/detail/:lightId', lightController.getLightDetail);
router.get('/exist/:lightId', authMiddleware, lightController.ExistLightUser);
router.get('/:crewId/enter/search', authMiddleware, lightController.getSearchMyEnterLight);
router.get('/:crewId/scrap/search', authMiddleware, lightController.getSearchMyScrapLight);
router.get('/:crewId/open/search', authMiddleware, lightController.getSearchMyOpenLight);

module.exports = router;
Loading