Skip to content

Commit

Permalink
[FEAT] #2 - 취업교육리스트목록 조회 API 구현 및 DB설정 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
charBS0701 committed Jul 14, 2023
1 parent a39951a commit 5dc3996
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 26 deletions.
8 changes: 3 additions & 5 deletions config/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@ import pg from "pg";
import dotenv from "dotenv";
dotenv.config();

const {logger} = require('./winston');

// TODO: 본인의 DB 계정 입력
const dbconfig = {
const dbConfig = {
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PW,
database: process.env.DB_NAME,
port: process.env.DB_PORT,
}

const client = new pg.Client(dbconfig)
const pool = new pg.Pool(dbConfig);

export default client;
export default pool;
2 changes: 2 additions & 0 deletions config/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ module.exports = function () {
/* App (Android, iOS) */
// TODO: 도메인을 추가할 경우 이곳에 Route를 추가하세요.
require('../src/app/User/userRoute')(app);
require('../src/app/JobEdu/jobEduRoute')(app);

// require('../src/app/Board/boardRoute')(app);

return app;
Expand Down
22 changes: 1 addition & 21 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,5 @@ const {logger} = require('./config/winston');

const port = 3000;
express().listen(port);
logger.info(`${process.env.NODE_ENV} - API Server Start At Port ${port}`);

// db 연결
try {
client.connect()
logger.info('DB 연결 성공')

// job_educations 테이블 조회
client.query('SELECT * FROM job_educations', (err, res) => {
if (err) {
logger.error(err.stack)
}
else {
console.log(res.rows[0])
}
})

} catch (error) {
logger.error('DB 연결 실패')
logger.error(error)
}

logger.info(`${process.env.NODE_ENV} - API Server Start At Port ${port}`);
14 changes: 14 additions & 0 deletions src/app/JobEdu/jobEduController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const jobEduProvider = require("./jobEduProvider");
const baseResponse = require("../../../config/baseResponseStatus");
const {response, errResponse} = require("../../../config/response");

export const getJobEduList = async (req, res) => {
try {
const jobEduListResult = await jobEduProvider.retrieveJobEduList();

return res.send(response(baseResponse.SUCCESS, jobEduListResult));
} catch (error) {
console.error(error);
return res.send(errResponse(baseResponse.DB_ERROR));
}
};
16 changes: 16 additions & 0 deletions src/app/JobEdu/jobEduDao.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { logger } = require("../../../config/winston");
import pool from "../../../config/database";

export const selectJobEduList = async function () {
const query = `
select * from job_educations limit 3;
`;

try {
const result = await pool.query(query);
return result;
} catch (error) {
logger.error("쿼리 실패");
throw error;
}
};
15 changes: 15 additions & 0 deletions src/app/JobEdu/jobEduProvider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pool from "../../../config/database";
const jobEduDao = require("./jobEduDao");

const { logger } = require("../../../config/winston");

export const retrieveJobEduList = async function () {
try {
const result = await jobEduDao.selectJobEduList();
return result;
} catch (error) {
logger.error("DB 연결 실패");
throw error;
}
};

7 changes: 7 additions & 0 deletions src/app/JobEdu/jobEduRoute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = function(app){
const jobEdu = require('./jobEduController');

// 1. 취업교육 목록 API
app.get('/app/jobEdu', jobEdu.getJobEduList);

};

0 comments on commit 5dc3996

Please sign in to comment.