-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/#2/jobEdu' into Develop
- Loading branch information
Showing
7 changed files
with
220 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,4 @@ const dbconfig = { | |
|
||
const pool = new pg.Pool(dbconfig); | ||
|
||
export default pool; | ||
export default pool; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
const jobEduProvider = require("./jobEduProvider"); | ||
const baseResponse = require("../../../config/baseResponseStatus"); | ||
const { response, errResponse } = require("../../../config/response"); | ||
|
||
export const getJobEduList = async (req, res) => { | ||
try { | ||
const page = req.query.page || 1; | ||
const pageSize = req.query.pageSize || 10; | ||
const active_status = req.query.active_status; | ||
|
||
const jobEduListResult = await jobEduProvider.retrieveJobEduList( | ||
pageSize, | ||
page, | ||
active_status | ||
); | ||
|
||
return res.send(response(baseResponse.SUCCESS, jobEduListResult)); | ||
} catch (error) { | ||
console.error(error); | ||
return res.send(errResponse(baseResponse.DB_ERROR)); | ||
} | ||
}; | ||
|
||
export const getJobEduListCount = async (req, res) => { | ||
const jobEduListCountResult = await jobEduProvider.retrieveJobEduListCount(); | ||
|
||
return res.send(response(baseResponse.SUCCESS, jobEduListCountResult)); | ||
}; | ||
|
||
export const getJobEduById = async (req, res) => { | ||
const jobEduId = req.params.jobEduId; | ||
|
||
if (!jobEduId) return res.send(errResponse(baseResponse.JOBEDU_ID_EMPTY)); | ||
|
||
const jobEduByIdResult = await jobEduProvider.retrieveJobEduById(jobEduId); | ||
|
||
return res.send(response(baseResponse.SUCCESS, jobEduByIdResult)); | ||
}; | ||
|
||
export const getJobEduBySearch = async (req, res) => { | ||
const keyword = req.query.keyword; | ||
const page = req.query.page || 1; // 페이지 번호가 주어지지 않은 경우 기본값은 1 | ||
const pageSize = req.query.pageSize || 10; // 페이지 크기가 주어지지 않은 경우 기본값은 10 | ||
if (!keyword) { | ||
return res.status(400).json({ error: "keyword is required" }); | ||
} | ||
|
||
try { | ||
const data = await jobEduProvider.searchWithPagination( | ||
keyword, | ||
page, | ||
pageSize | ||
); | ||
return res.send(response(baseResponse.SUCCESS, data)); | ||
} catch (err) { | ||
console.log(err.stack); | ||
res.status(500).json({ error: "Something went wrong" }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
const { logger } = require("../../../config/winston"); | ||
import pool from "../../../config/database"; | ||
|
||
export const selectJobEduList = async function (pageSize, offset, active_status) { | ||
const query = active_status | ||
? `SELECT * FROM job_educations WHERE active_status = ${active_status} ORDER BY posted_at DESC LIMIT ${pageSize} OFFSET ${offset}` | ||
: `SELECT * FROM job_educations ORDER BY posted_at DESC LIMIT ${pageSize} OFFSET ${offset}`; | ||
|
||
try { | ||
const result = await pool.query(query); | ||
return result.rows; | ||
} catch (error) { | ||
logger.error("selectJobEduList쿼리 실패"); | ||
throw error; | ||
} | ||
}; | ||
|
||
export const selectJobEduListCount = async function () { | ||
const query = ` | ||
select count(*) as total_count from job_educations; | ||
`; | ||
|
||
try { | ||
const result = await pool.query(query); | ||
return result; | ||
} catch (error) { | ||
logger.error("selectJobEduListCount 쿼리 실패"); | ||
throw error; | ||
} | ||
}; | ||
|
||
export const selectJobEduById = async function (jobEduId) { | ||
const query = ` | ||
SELECT * FROM job_educations WHERE job_edu_id = ${jobEduId};`; | ||
|
||
try { | ||
const result = await pool.query(query); | ||
return result.rows[0]; | ||
} catch (error) { | ||
logger.error("selectJobEduById 쿼리 실패"); | ||
throw error; | ||
} | ||
}; | ||
|
||
export const selectJobEduByKeyword = async function ( | ||
keyword, | ||
offset, | ||
pageSize | ||
) { | ||
const query = ` | ||
SELECT * FROM job_educations WHERE title LIKE '%${keyword}%' OR content LIKE '%${keyword}%' ORDER BY posted_at DESC LIMIT ${pageSize} OFFSET ${offset};`; | ||
|
||
try { | ||
const result = await pool.query(query); | ||
return result.rows; | ||
} catch (error) { | ||
logger.error("selectJobEduByKeyword 쿼리 실패"); | ||
throw error; | ||
} | ||
}; | ||
|
||
export const selectJobEduTotalCountByKeyword = async function (keyword) { | ||
const query = ` | ||
SELECT count(*) as total_count FROM job_educations WHERE title LIKE '%${keyword}%' OR content LIKE '%${keyword}%';`; | ||
|
||
try { | ||
const result = await pool.query(query); | ||
return result.rows[0]["total_count"]; | ||
} catch (error) { | ||
logger.error("selectJobEduTotalCountByKeyword 쿼리 실패"); | ||
throw error; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import pool from "../../../config/database"; | ||
const jobEduDao = require("./jobEduDao"); | ||
|
||
const { logger } = require("../../../config/winston"); | ||
|
||
export const retrieveJobEduList = async function (pageSize, page, active_status) { | ||
try { | ||
const offset = (page - 1) * pageSize; | ||
const result = await jobEduDao.selectJobEduList(pageSize, offset, active_status); | ||
return result; | ||
} catch (error) { | ||
logger.error("DB 연결 실패"); | ||
throw error; | ||
} | ||
}; | ||
|
||
// 취업지원 데이터 갯수 세는 함수 | ||
export const retrieveJobEduListCount = async function () { | ||
try { | ||
const result = await jobEduDao.selectJobEduListCount(); | ||
|
||
return parseInt(result.rows[0]["total_count"]); | ||
} catch (error) { | ||
logger.error("DB 연결 실패"); | ||
logger.error(error); | ||
throw error; | ||
} | ||
}; | ||
|
||
export const retrieveJobEduById = async function (jobEduId) { | ||
try { | ||
const result = await jobEduDao.selectJobEduById(jobEduId); | ||
|
||
return result; | ||
} catch (error) { | ||
logger.error("DB 연결 실패"); | ||
logger.error(error); | ||
throw error; | ||
} | ||
}; | ||
|
||
// 취업지원 검색 함수 | ||
export const searchWithPagination = async function (keyword, page, pageSize) { | ||
try { | ||
const offset = (page - 1) * pageSize; | ||
const result = await jobEduDao.selectJobEduByKeyword( | ||
keyword, | ||
offset, | ||
pageSize | ||
); | ||
const totalCount = await jobEduDao.selectJobEduTotalCountByKeyword(keyword); | ||
return { | ||
totalCount: totalCount, | ||
data: result, | ||
}; | ||
} catch (error) { | ||
logger.error("DB 연결 실패"); | ||
logger.error(error); | ||
throw error; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module.exports = function (app) { | ||
const jobEdu = require("./jobEduController"); | ||
|
||
// 1. 취업교육 목록 API | ||
app.get("/app/jobEdu", jobEdu.getJobEduList); | ||
|
||
// 3. 취업교육 검색 API | ||
app.get("/app/jobEdu/search", jobEdu.getJobEduBySearch); | ||
|
||
// 2. 취업교육 상세 조회 API | ||
app.get("/app/jobEdu/:jobEduId", jobEdu.getJobEduById); | ||
|
||
|
||
|
||
|
||
/* | ||
내부 사용 API | ||
*/ | ||
|
||
// 취업지원 목록 개수 API | ||
app.get("/app/jobEdu/count", jobEdu.getJobEduListCount); | ||
}; |