Skip to content

Commit

Permalink
Feature/backend (#198)
Browse files Browse the repository at this point in the history
* Modify: CI/CD 수정

* Feat: navigation API 개발 완료

* Modify: navigation API 수정

* Fix: navigation API 예외처리

* Feat: CORS http 포트 추가

* Modify: CORS 옵션 수정

* Modify: CORS 옵션 수정

* Feat: https 서버 업데이트

* HTTPS 적용

* Feat: COSR 옵션 https 추가

* Feat: 없는 지하철역 예외처리

* Feat: 없는 지하철역 예외처리

* Modify: 예외처리 진행
  • Loading branch information
sw0501 authored Dec 6, 2023
1 parent c64863a commit 90caef7
Show file tree
Hide file tree
Showing 4 changed files with 343 additions and 236 deletions.
264 changes: 156 additions & 108 deletions BackendJS/BackendTS/routes/subwaydata.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ function getSubwayStationInfo(stCd, stNm, callback) {
method: 'GET'
}, function (error, response, body) {
const stationinfo = JSON.parse(body).body[0];
//NULL error
if (stationinfo === undefined) {
return callback(null);
}
callback({
railCd: stationinfo.railOprIsttCd,
lnCd: stationinfo.lnCd,
Expand Down Expand Up @@ -157,6 +161,9 @@ function getLiftMove(stCd, stNm, railCd, lnCd, callback) {
return __awaiter(this, void 0, void 0, function* () {
//목적지 별로 구분하여 제공
const liftMoveParse = JSON.parse(body).body;
if (liftMoveParse === undefined) {
return callback(null);
}
let liftInfo = {
direction: "",
info: []
Expand Down Expand Up @@ -200,7 +207,12 @@ function getElevatorPos(stCd, stNm, railCd, lnCd, callback) {
method: 'GET'
}, function (error, response, body) {
const ElevatorPosInfo = JSON.parse(body).body;
callback(ElevatorPosInfo);
if (ElevatorPosInfo === undefined) {
return callback(null);
}
else {
callback(ElevatorPosInfo);
}
});
}
catch (e) {
Expand All @@ -227,22 +239,27 @@ function getElevatorMove(stCd, stNm, railCd, lnCd, callback) {
info: []
};
const elevatorMoveParse = JSON.parse(body).body;
for (let i = 0; i < elevatorMoveParse.length; i++) {
if (elevatorMoveParse[i].mvTpOrdr === 1) {
if (elevatorInfo.info.length !== 0) {
const direction = elevatorInfo.info[elevatorInfo.info.length - 2].mvContDtl.split('승강장')[0].substr(3);
elevatorInfo.direction = direction;
elevatorMove.push(elevatorInfo);
elevatorInfo.direction = "";
elevatorInfo.info = [];
if (elevatorMoveParse === undefined) {
return callback(null);
}
else {
for (let i = 0; i < elevatorMoveParse.length; i++) {
if (elevatorMoveParse[i].mvTpOrdr === 1) {
if (elevatorInfo.info.length !== 0) {
const direction = elevatorInfo.info[elevatorInfo.info.length - 2].mvContDtl.split('승강장')[0].substr(3);
elevatorInfo.direction = direction;
elevatorMove.push(elevatorInfo);
elevatorInfo.direction = "";
elevatorInfo.info = [];
}
}
elevatorInfo.info.push(elevatorMoveParse[i]);
}
elevatorInfo.info.push(elevatorMoveParse[i]);
const direction = elevatorInfo.info[elevatorInfo.info.length - 2].mvContDtl.split('승강장')[0].substr(3);
elevatorInfo.direction = direction;
elevatorMove.push(elevatorInfo);
callback(elevatorMove);
}
const direction = elevatorInfo.info[elevatorInfo.info.length - 2].mvContDtl.split('승강장')[0].substr(3);
elevatorInfo.direction = direction;
elevatorMove.push(elevatorInfo);
callback(elevatorMove);
});
}
catch (e) {
Expand All @@ -263,55 +280,47 @@ function getTransferList(stCd, stNm, railCd, lnCd, callback) {
console.log(err);
}
let sourceStation = [];
/*
if (results.length == 0) {
return callback({
error: 404,
errorString: "Not Transfer Station"
for (let i = 0; i < results.length; i++) {
sourceStation.push({
stCd: results[i].STIN_CD,
stNm: results[i].STIN_NM,
railCd: results[i].RAIL_OPR_ISTT_CD,
lnCd: results[i].LN_CD
});
}
*/
/*else*/ {
for (let i = 0; i < results.length; i++) {
sourceStation.push({
stCd: results[i].STIN_CD,
stNm: results[i].STIN_NM,
railCd: results[i].RAIL_OPR_ISTT_CD,
lnCd: results[i].LN_CD
});
}
}
transferList.sourceStation = sourceStation;
});
sql = "Select * FROM subcode_1 WHERE STIN_NM = ?;";
connection.query(sql, [stNm], function (err, results, fields) {
if (err) {
console.log(err);
}
if (results.length === 1) {
/*
return callback({
error: 404,
errorString: "Not Transfer Station"
});
*/
if (results.length === 0 || results.length === 1) {
return callback(null);
}
for (let i = 0; i < results.length; i++) {
if (results[i].STIN_CD != stCd) {
const sql2 = "Select * FROM subcode_1 WHERE (STIN_CD = ? or STIN_CD = ?) and RAIL_OPR_ISTT_CD = ?;";
connection.query(sql2, [parseInt(results[i].STIN_CD) + 1, parseInt(results[i].STIN_CD) - 1, results[i].RAIL_OPR_ISTT_CD], function (err, results2, fields) {
let transferStation = [];
for (let j = 0; j < results2.length; j++) {
transferStation.push({
stCd: results2[j].STIN_CD,
stNm: results2[j].STIN_NM,
railCd: results2[j].RAIL_OPR_ISTT_CD,
lnCd: results2[j].LN_CD
});
}
transferList.transferStation = transferStation;
callback(transferList);
});
else {
for (let i = 0; i < results.length; i++) {
if (results[i].STIN_CD != stCd) {
const sql2 = "Select * FROM subcode_1 WHERE (STIN_CD = ? or STIN_CD = ?) and RAIL_OPR_ISTT_CD = ?;";
connection.query(sql2, [parseInt(results[i].STIN_CD) + 1, parseInt(results[i].STIN_CD) - 1, results[i].RAIL_OPR_ISTT_CD], function (err, results2, fields) {
let transferStation = [];
if (results.length === 0) {
return callback(null);
}
else {
for (let j = 0; j < results2.length; j++) {
transferStation.push({
stCd: results2[j].STIN_CD,
stNm: results2[j].STIN_NM,
railCd: results2[j].RAIL_OPR_ISTT_CD,
lnCd: results2[j].LN_CD
});
}
transferList.transferStation = transferStation;
callback(transferList);
}
});
}
}
}
});
Expand All @@ -330,6 +339,9 @@ function getTransferInfo(stCd, stNm, railCd, lnCd, prev, chthTgtLn, chtnNextStin
if (err) {
console.log(err);
}
if (results.length === 0) {
return callback(null);
}
let prevStinCd;
if (parseInt(results[0].STIN_CD) + 1 === parseInt(chtnNextStinCd)) {
prevStinCd = parseInt(results[0].STIN_CD) - 1;
Expand All @@ -356,60 +368,65 @@ function getTransferInfo(stCd, stNm, railCd, lnCd, prev, chthTgtLn, chtnNextStin
method: 'GET'
}, function (error, response, body) {
const parse = JSON.parse(body).body;
for (let i = 0; i < parse.length; i++) {
//성수가 211 하행
//railCd로 비교
//2호선의 경우 상 하행이 반대
if (railCd === "S1" && lnCd === "2") {
//환승역 방면이 상행선이라면 2, 4만 나옴
if (prevStinCd > parseInt(chtnNextStinCd)) {
//출발 방면이 상행선이라면
if (parseInt(stCd) > parseInt(prev) && parse[i].mvPathMgNo === 2) {
transferInfo.push(parse[i]);
}
//출발 방면이 하행선이라면
else if (parseInt(stCd) < parseInt(prev) && parse[i].mvPathMgNo === 1) {
transferInfo.push(parse[i]);
}
}
//하행선인 경우
else {
//출발 방면이 상행선이라면
if (parseInt(stCd) > parseInt(prev) && parse[i].mvPathMgNo === 4) {
transferInfo.push(parse[i]);
}
//출발 방면이 하행선이라면
else if (parseInt(stCd) < parseInt(prev) && parse[i].mvPathMgNo === 3) {
transferInfo.push(parse[i]);
}
}
}
else {
//환승역 방면이 상행선이라면 1,3만 나옴
if (prevStinCd > parseInt(chtnNextStinCd)) {
//출발 방면이 상행선이라면
if (parseInt(stCd) > parseInt(prev) && parse[i].mvPathMgNo === 1) {
transferInfo.push(parse[i]);
if (parse === undefined) {
return callback(null);
}
else {
for (let i = 0; i < parse.length; i++) {
//성수가 211 하행
//railCd로 비교
//2호선의 경우 상 하행이 반대
if (railCd === "S1" && lnCd === "2") {
//환승역 방면이 상행선이라면 2, 4만 나옴
if (prevStinCd > parseInt(chtnNextStinCd)) {
//출발 방면이 상행선이라면
if (parseInt(stCd) > parseInt(prev) && parse[i].mvPathMgNo === 2) {
transferInfo.push(parse[i]);
}
//출발 방면이 하행선이라면
else if (parseInt(stCd) < parseInt(prev) && parse[i].mvPathMgNo === 1) {
transferInfo.push(parse[i]);
}
}
//출발 방면이 하행선이라면
else if (parseInt(stCd) < parseInt(prev) && parse[i].mvPathMgNo === 3) {
transferInfo.push(parse[i]);
//하행선인 경우
else {
//출발 방면이 상행선이라면
if (parseInt(stCd) > parseInt(prev) && parse[i].mvPathMgNo === 4) {
transferInfo.push(parse[i]);
}
//출발 방면이 하행선이라면
else if (parseInt(stCd) < parseInt(prev) && parse[i].mvPathMgNo === 3) {
transferInfo.push(parse[i]);
}
}
}
//하행선인 경우
else {
//출발 방면이 상행선이라면
if (parseInt(stCd) > parseInt(prev) && parse[i].mvPathMgNo === 2) {
transferInfo.push(parse[i]);
//환승역 방면이 상행선이라면 1,3만 나옴
if (prevStinCd > parseInt(chtnNextStinCd)) {
//출발 방면이 상행선이라면
if (parseInt(stCd) > parseInt(prev) && parse[i].mvPathMgNo === 1) {
transferInfo.push(parse[i]);
}
//출발 방면이 하행선이라면
else if (parseInt(stCd) < parseInt(prev) && parse[i].mvPathMgNo === 3) {
transferInfo.push(parse[i]);
}
}
//출발 방면이 하행선이라면
else if (parseInt(stCd) < parseInt(prev) && parse[i].mvPathMgNo === 4) {
transferInfo.push(parse[i]);
//하행선인 경우
else {
//출발 방면이 상행선이라면
if (parseInt(stCd) > parseInt(prev) && parse[i].mvPathMgNo === 2) {
transferInfo.push(parse[i]);
}
//출발 방면이 하행선이라면
else if (parseInt(stCd) < parseInt(prev) && parse[i].mvPathMgNo === 4) {
transferInfo.push(parse[i]);
}
}
}
}
callback(transferInfo);
}
callback(transferInfo);
});
});
}
Expand All @@ -433,12 +450,17 @@ function getConvenience(stCd, stNm, railCd, lnCd, callback) {
method: 'GET'
}, function (error, response, body) {
const parse = JSON.parse(body).body;
for (let i = 0; i < parse.length; i++) {
if (parse[i].gubun === "EV" || parse[i].gubun === "WCLF") {
conveneinceInfo.push(parse[i]);
if (parse === undefined) {
callback(null);
}
else {
for (let i = 0; i < parse.length; i++) {
if (parse[i].gubun === "EV" || parse[i].gubun === "WCLF") {
conveneinceInfo.push(parse[i]);
}
}
callback(conveneinceInfo);
}
callback(conveneinceInfo);
});
}
catch (e) {
Expand Down Expand Up @@ -537,7 +559,12 @@ router.get('/liftMove/:stCd/:stNm/:railCd/:lnCd', (req, res) => __awaiter(void 0
const railCd = req.params.railCd;
const lnCd = req.params.lnCd;
yield getLiftMove(stCd, stNm, railCd, lnCd, callback => {
return res.status(200).json(callback);
if (callback === null) {
return res.status(200).json([]);
}
else {
return res.status(200).json(callback);
}
});
}
catch (e) {
Expand All @@ -555,6 +582,9 @@ router.get('/ElevatorPos/:stCd/:stNm/:railCd/:lnCd', (req, res) => __awaiter(voi
const railCd = req.params.railCd;
const lnCd = req.params.lnCd;
yield getElevatorPos(stCd, stNm, railCd, lnCd, callback => {
if (callback === null) {
return res.status(200).json([]);
}
return res.status(200).json(callback);
});
}
Expand All @@ -573,7 +603,12 @@ router.get('/ElevatorMove/:stCd/:stNm/:railCd/:lnCd', (req, res) => __awaiter(vo
const railCd = req.params.railCd;
const lnCd = req.params.lnCd;
yield getElevatorMove(stCd, stNm, railCd, lnCd, callback => {
return res.status(200).json(callback);
if (callback === null) {
return res.status(200).json([]);
}
else {
return res.status(200).json(callback);
}
});
}
catch (e) {
Expand All @@ -591,13 +626,21 @@ router.get('/transferMove/transferList/:stCd/:stNm/:railCd/:lnCd', (req, res) =>
const railCd = req.params.railCd;
const lnCd = req.params.lnCd;
yield getTransferList(stCd, stNm, railCd, lnCd, transferInfo => {
if (transferInfo.sourceStation.length === 0 || transferInfo.transferStation.length === 0) {
if (transferInfo === null) {
return res.status(500).json({
error: 500,
errorString: "Not Transfer Station"
});
}
return res.status(200).json(transferInfo);
else if (transferInfo.sourceStation.length === 0 || transferInfo.transferStation.length === 0) {
return res.status(500).json({
error: 500,
errorString: "Not Transfer Station"
});
}
else {
return res.status(200).json(transferInfo);
}
});
}
catch (e) {
Expand All @@ -618,7 +661,12 @@ router.get('/transferMove/transferInfo/:stCd/:stNm/:railCd/:lnCd/:prevStinCd/:ch
const chthTgtLn = req.params.chthTgtLn;
const chtnNextStinCd = req.params.chtnNextStinCd;
yield getTransferInfo(stCd, stNm, railCd, lnCd, prevStinCd, chthTgtLn, chtnNextStinCd, callback => {
return res.json(callback);
if (callback === null) {
return res.status(200).json([]);
}
else {
return res.status(200).json(callback);
}
});
}
catch (e) {
Expand All @@ -637,7 +685,7 @@ router.get('/convenience/:stCd/:stNm/:railCd/:lnCd', (req, res) => __awaiter(voi
const lnCd = req.params.lnCd;
yield getConvenience(stCd, stNm, railCd, lnCd, conveneinceInfo => {
//No Data
if (conveneinceInfo.length === 0) {
if (conveneinceInfo === null) {
return res.status(500).json({
error: 404,
errorString: "No conveneince"
Expand Down
Loading

0 comments on commit 90caef7

Please sign in to comment.