Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
eue
Commits
caff31ae
Commit
caff31ae
authored
May 07, 2021
by
KangMin An
Browse files
Local Code 제공을 위한 코드 추가 및 수정.
parent
81e95b46
Changes
5
Show whitespace changes
Inline
Side-by-side
server/src/app.js
View file @
caff31ae
...
...
@@ -10,6 +10,7 @@ import globalRouter from "./routers/globalRouter";
import
dataRouter
from
"
./routers/dataRouter
"
;
import
{
localmiddleware
}
from
"
./middlewares
"
;
import
locCodeRouter
from
"
./routers/locCodeRouter
"
;
const
app
=
express
();
...
...
@@ -28,5 +29,6 @@ app.use(localmiddleware);
// router 사용
app
.
use
(
routes
.
home
,
globalRouter
);
app
.
use
(
routes
.
data
,
dataRouter
);
app
.
use
(
routes
.
locCode
,
locCodeRouter
);
export
default
app
;
server/src/controllers/locCodeController.js
0 → 100644
View file @
caff31ae
import
db
from
"
../db
"
;
const
DB_QUERY_ERROR_MSG
=
"
DB Query Error.
"
;
const
DB_CONNECTION_ERROR_MSG
=
"
DB Connection Error.
"
;
const
SERVER_ERROR_MSG
=
"
The server encountered an error.
"
;
const
QUERY_SUCCESS_MSG
=
"
Query Success.
"
;
const
STATUS_OK_CODE
=
200
;
const
STATUS_SERVER_ERROR_CODE
=
500
;
export
const
getDo
=
async
(
req
,
res
)
=>
{
const
query
=
"
SELECT CODE, DONAME FROM LOCDO
"
;
db
((
connErr
,
connection
)
=>
{
if
(
connErr
)
{
console
.
log
(
DB_CONNECTION_ERROR_MSG
);
res
.
status
(
STATUS_SERVER_ERROR_CODE
).
json
({
error
:
SERVER_ERROR_MSG
});
}
else
{
connection
.
query
(
query
,
(
queryErr
,
result
)
=>
{
if
(
queryErr
)
{
console
.
log
(
DB_QUERY_ERROR_MSG
);
res
.
status
(
STATUS_SERVER_ERROR_CODE
)
.
json
({
error
:
SERVER_ERROR_MSG
});
}
else
{
console
.
log
(
QUERY_SUCCESS_MSG
);
res
.
status
(
STATUS_OK_CODE
).
json
({
info
:
result
});
}
});
connection
.
release
();
}
});
};
export
const
getSGG
=
(
req
,
res
)
=>
{
const
{
params
:
{
id
},
}
=
req
;
const
query
=
`SELECT CODE, SGGNAME FROM LOCSIGUNGU WHERE DOCODE =
${
id
}
`
;
db
((
connErr
,
connection
)
=>
{
if
(
connErr
)
{
console
.
log
(
DB_CONNECTION_ERROR_MSG
);
res
.
status
(
STATUS_SERVER_ERROR_CODE
).
json
({
error
:
SERVER_ERROR_MSG
});
}
else
{
connection
.
query
(
query
,
(
queryErr
,
result
)
=>
{
if
(
queryErr
)
{
console
.
log
(
DB_QUERY_ERROR_MSG
);
res
.
status
(
STATUS_SERVER_ERROR_CODE
)
.
json
({
error
:
SERVER_ERROR_MSG
});
}
else
{
console
.
log
(
QUERY_SUCCESS_MSG
);
res
.
status
(
STATUS_OK_CODE
).
json
({
info
:
result
});
}
});
connection
.
release
();
}
});
};
export
const
getEMD
=
(
req
,
res
)
=>
{
const
{
params
:
{
id
},
}
=
req
;
const
query
=
`SELECT CODE, EMDNAME FROM LOCINFO WHERE SGGCODE =
${
id
}
`
;
db
((
connErr
,
connection
)
=>
{
if
(
connErr
)
{
console
.
log
(
DB_CONNECTION_ERROR_MSG
);
res
.
status
(
STATUS_SERVER_ERROR_CODE
).
json
({
error
:
SERVER_ERROR_MSG
});
}
else
{
connection
.
query
(
query
,
(
queryErr
,
result
)
=>
{
if
(
queryErr
)
{
console
.
log
(
DB_QUERY_ERROR_MSG
);
res
.
status
(
STATUS_SERVER_ERROR_CODE
)
.
json
({
error
:
SERVER_ERROR_MSG
});
}
else
{
console
.
log
(
QUERY_SUCCESS_MSG
);
res
.
status
(
STATUS_OK_CODE
).
json
({
info
:
result
});
}
});
connection
.
release
();
}
});
};
server/src/db.js
0 → 100644
View file @
caff31ae
import
mysql
from
"
mysql
"
;
import
dotenv
from
"
dotenv
"
;
dotenv
.
config
();
// MySQL Config
const
db_config
=
{
host
:
process
.
env
.
MYSQL_HOST
||
"
localhost
"
,
user
:
process
.
env
.
MYSQL_USER
||
"
root
"
,
password
:
process
.
env
.
MYSQL_PASSWORD
,
database
:
process
.
env
.
MYSQL_DATABASE
||
"
EUE
"
,
connectionLimit
:
5
,
};
// Creation of MySQL Pool
const
pool
=
mysql
.
createPool
(
db_config
);
// Pool을 이용시, Connection을 생성 후 반환하여 사용
const
connection
=
(
callback
)
=>
{
console
.
log
(
"
db_connection()
"
);
pool
.
getConnection
(
async
(
err
,
connection
)
=>
{
console
.
log
(
"
db_connection_poolConnection()
"
);
await
callback
(
err
,
connection
);
});
};
export
default
connection
;
server/src/routers/locCodeRouter.js
0 → 100644
View file @
caff31ae
import
express
from
"
express
"
;
import
routes
from
"
../routes
"
;
import
{
getDo
,
getEMD
,
getSGG
}
from
"
../controllers/locCodeController
"
;
const
locCodeRouter
=
express
.
Router
();
locCodeRouter
.
get
(
routes
.
do
,
getDo
);
locCodeRouter
.
get
(
routes
.
sigungu
+
routes
.
Detail
(),
getSGG
);
locCodeRouter
.
get
(
routes
.
eupmyeondong
+
routes
.
Detail
(),
getEMD
);
export
default
locCodeRouter
;
server/src/routes.js
View file @
caff31ae
...
...
@@ -12,7 +12,7 @@ const DATA_OUTSIDE = "/outside";
// # Local Code Data
const
LOCCODE
=
"
/loccode
"
;
const
DO
=
"
/do
"
;
const
SIGUNGU
=
"
/sigungu
"
;
const
SIGUNGU
=
"
/si
-
gun
-
gu
"
;
const
EUPMYEONDONG
=
"
/eup-myeon-dong
"
;
// # Auth
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment