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
e92762f2
Commit
e92762f2
authored
Jul 21, 2021
by
KangMin An
Browse files
Update : Merge Kangmin & Who.
parent
40581228
Changes
11
Hide whitespace changes
Inline
Side-by-side
server/API명세서.md
View file @
e92762f2
...
@@ -2,18 +2,16 @@
...
@@ -2,18 +2,16 @@
## API 명세 Table
## API 명세 Table
| Category | HTTP Method | URI | Description |
| Category | HTTP Method | URI | Description |
| -------------- | ----------- | -------------------------- | ----------------------------------------------------------- |
| :------------- | :---------: | :---------------- | :---------------------------------------------------------- |
| Root Directory | ﹒ | /api | api 서버를 통해 들어오는 기본 경로 |
| Root | ﹒ | /api | 서버의 기본 경로 |
| Data Collector | GET | /data/input?... | 아두이노를 통해 수집한 자료 등록 (내부, 외부는 쿼리로 구분) |
| Data Collector | GET | /data/input?... | 아두이노를 통해 수집한 자료 등록 (내부, 외부는 쿼리로 구분) |
| Data - User | GET | /data/user/:id | 사용자 지정 장소의 데이터 요청 |
| Data - User | GET | /data/user/:id | 사용자 지정 장소의 날씨 데이터 요청 |
| Data - Outside | GET | /data/outside/:id | 해당 지역구의 데이터 요청 |
| Data - Outside | GET | /data/outside/:id | 해당 지역구의 날씨 데이터 요청 |
| Local Code | GET | /loccode/doe | 행정 구역 코드 '도' 요청 |
| Local Code | GET | /data/loccode | 행정 구역 코드 요청 |
| Local Code | GET | /loccode/si-gun-gu/:id | 사용자 입력 '도'에 따른 행정 구역 코드 '시군구' 요청 |
| Auth | POST | /signup | 회원가입 요청 |
| Local Code | GET | /loccod/eup-myeon-dong/:id | 사용자 입력 '시군구'에 따른 행정 구역 코드 '읍면동' 요청 |
| Auth | POST | /login | 로그인 요청 |
| Auth | POST | /signup | 회원가입 요청 |
| Auth | POST | /:id/edit-profile | 회원 정보 수정 요청 |
| Auth | POST | /login | 로그인 요청 |
| Auth | POST | /:id/edit-profile | 회원 정보 수정 요청 |
<br><br>
<br><br>
...
@@ -47,3 +45,11 @@
...
@@ -47,3 +45,11 @@
1.
도 정보를 가져오는 경로 수정
1.
도 정보를 가져오는 경로 수정
: loccode/do -> loccode/doe
: loccode/do -> loccode/doe
### 2021.07.19 \_ 경로 수정
1.
API 서버로의 기본 주소 수정
: "/" -> "/api"
2.
행정 구역 코드 데이터 주소 수정
: "도", "시/군/구", "읍/면/동"의 데이터를 따로 요청할 수 있던 것에서, 한번에 처리하도록 변경
server/package.json
View file @
e92762f2
...
@@ -4,7 +4,8 @@
...
@@ -4,7 +4,8 @@
"description"
:
""
,
"description"
:
""
,
"main"
:
"init.js"
,
"main"
:
"init.js"
,
"scripts"
:
{
"scripts"
:
{
"dev:server"
:
"nodemon --exec
\"
npx babel-node src/init.js
\"
--delay 2"
,
"dev:server"
:
"nodemon --exec babel-node src/init.js --delay 2"
,
"dev:server_window"
:
"nodemon --exec
\"
npx babel-node src/init.js
\"
--delay 2"
,
"start"
:
"babel-node src/init.js"
"start"
:
"babel-node src/init.js"
},
},
"repository"
:
{
"repository"
:
{
...
@@ -18,12 +19,16 @@
...
@@ -18,12 +19,16 @@
},
},
"homepage"
:
"https://github.com/dorakang612/EUE#readme"
,
"homepage"
:
"https://github.com/dorakang612/EUE#readme"
,
"dependencies"
:
{
"dependencies"
:
{
"@babel/cli"
:
"^7.14.5"
,
"@babel/core"
:
"^7.11.6"
,
"@babel/node"
:
"^7.10.5"
,
"@babel/preset-env"
:
"^7.11.5"
,
"body-parser"
:
"^1.19.0"
,
"body-parser"
:
"^1.19.0"
,
"cookie-parser"
:
"^1.4.5"
,
"cookie-parser"
:
"^1.4.5"
,
"cors"
:
"^2.8.5"
,
"dotenv"
:
"^8.2.0"
,
"dotenv"
:
"^8.2.0"
,
"express"
:
"^4.17.1"
,
"express"
:
"^4.17.1"
,
"helmet"
:
"^4.1.1"
,
"helmet"
:
"^4.1.1"
,
"jsonwebtoken"
:
"^8.5.1"
,
"morgan"
:
"^1.10.0"
,
"morgan"
:
"^1.10.0"
,
"mysql2"
:
"^2.2.5"
,
"mysql2"
:
"^2.2.5"
,
"node-fetch"
:
"^2.6.1"
,
"node-fetch"
:
"^2.6.1"
,
...
@@ -35,9 +40,6 @@
...
@@ -35,9 +40,6 @@
"sequelize"
:
"^6.6.5"
"sequelize"
:
"^6.6.5"
},
},
"devDependencies"
:
{
"devDependencies"
:
{
"@babel/core"
:
"^7.14.6"
,
"@babel/node"
:
"^7.14.7"
,
"@babel/preset-env"
:
"^7.14.7"
,
"nodemon"
:
"^2.0.4"
"nodemon"
:
"^2.0.4"
}
}
}
}
server/src/app.js
View file @
e92762f2
import
cookieParser
from
"
cookie-parser
"
;
import
cookieParser
from
"
cookie-parser
"
;
import
cors
from
"
cors
"
;
import
express
from
"
express
"
;
import
express
from
"
express
"
;
import
morgan
from
"
morgan
"
;
import
morgan
from
"
morgan
"
;
import
helmet
from
"
helmet
"
;
import
helmet
from
"
helmet
"
;
...
@@ -10,7 +11,6 @@ import globalRouter from "./routers/globalRouter";
...
@@ -10,7 +11,6 @@ import globalRouter from "./routers/globalRouter";
import
dataRouter
from
"
./routers/dataRouter
"
;
import
dataRouter
from
"
./routers/dataRouter
"
;
import
{
localmiddleware
}
from
"
./middlewares
"
;
import
{
localmiddleware
}
from
"
./middlewares
"
;
import
locCodeRouter
from
"
./routers/locCodeRouter
"
;
const
app
=
express
();
const
app
=
express
();
...
@@ -18,6 +18,7 @@ const app = express();
...
@@ -18,6 +18,7 @@ const app = express();
app
.
set
(
"
view engine
"
,
"
pug
"
);
app
.
set
(
"
view engine
"
,
"
pug
"
);
app
.
set
(
"
views
"
,
path
.
join
(
__dirname
,
"
views
"
));
app
.
set
(
"
views
"
,
path
.
join
(
__dirname
,
"
views
"
));
app
.
use
(
cors
());
app
.
use
(
helmet
());
app
.
use
(
helmet
());
app
.
use
(
cookieParser
());
app
.
use
(
cookieParser
());
app
.
use
(
express
.
json
());
app
.
use
(
express
.
json
());
...
@@ -28,8 +29,7 @@ app.use(morgan("dev"));
...
@@ -28,8 +29,7 @@ app.use(morgan("dev"));
app
.
use
(
localmiddleware
);
app
.
use
(
localmiddleware
);
// router 사용
// router 사용
app
.
use
(
routes
.
home
,
globalRouter
);
app
.
use
(
routes
.
base
,
globalRouter
);
app
.
use
(
routes
.
data
,
dataRouter
);
app
.
use
(
routes
.
base
+
routes
.
data
,
dataRouter
);
app
.
use
(
routes
.
locCode
,
locCodeRouter
);
export
default
app
;
export
default
app
;
server/src/controllers/dataController.js
View file @
e92762f2
import
fs
from
"
fs
"
;
import
fetch
from
"
node-fetch
"
;
import
fetch
from
"
node-fetch
"
;
import
{
serverMSG
,
statusCode
}
from
"
../serverinfo
"
;
import
{
serverMSG
,
statusCode
}
from
"
../serverinfo
"
;
import
db
from
"
../db/index
"
;
import
db
from
"
../db/index
"
;
...
@@ -81,8 +80,54 @@ export const getDataInput = (req, res) => {
...
@@ -81,8 +80,54 @@ export const getDataInput = (req, res) => {
// 사용자의 데이터 가져오기 및 예측 값 전송
// 사용자의 데이터 가져오기 및 예측 값 전송
export
const
getUserWeatherData
=
(
req
,
res
)
=>
{
export
const
getUserWeatherData
=
(
req
,
res
)
=>
{
const
{
const
{
params
:
{
id
},
params
:
{
email
},
}
=
req
;
}
=
req
;
/* 사용자 email에 따른 사용자 날씨 데이터 가져오기 */
res
.
status
(
statusCode
.
ok
).
send
(
serverMSG
.
server_ok
);
res
.
status
(
statusCode
.
ok
).
send
(
serverMSG
.
server_ok
);
};
};
// 지역 코드 요청 처리
export
const
getLocCode
=
async
(
req
,
res
)
=>
{
/* 통합 지역 코드 및 이름 json으로 생성 및 전송 */
let
locCodes
=
[];
const
does
=
await
db
.
Doe
.
findAll
({
logging
:
false
});
const
sggs
=
await
db
.
Sgg
.
findAll
({
logging
:
false
});
const
emds
=
await
db
.
Emd
.
findAll
({
logging
:
false
});
let
doe_sgg
=
[];
let
sgg_emd
=
[];
does
.
map
((
info_doe
)
=>
{
let
temp
=
{
name_doe
:
info_doe
[
"
name_doe
"
],
code_doe
:
info_doe
[
"
code_doe
"
],
};
temp
.
sgg
=
sggs
.
filter
(
(
info_sgg
)
=>
info_sgg
[
"
code_doe
"
]
===
info_doe
[
"
code_doe
"
]
);
doe_sgg
.
push
(
temp
);
});
sggs
.
map
((
info_sgg
)
=>
{
let
temp
=
{
code_doe
:
info_sgg
[
"
code_doe
"
],
name_sgg
:
info_sgg
[
"
name_sgg
"
],
code_sgg
:
info_sgg
[
"
code_sgg
"
],
};
temp
.
emd
=
emds
.
filter
(
(
info_emd
)
=>
info_emd
[
"
code_sgg
"
]
===
info_sgg
[
"
code_sgg
"
]
);
sgg_emd
.
push
(
temp
);
});
res
.
status
(
statusCode
.
ok
).
json
({
locCodes
:
{
DOE
:
does
,
SGG
:
doe_sgg
,
EMD
:
sgg_emd
,
},
});
};
server/src/controllers/userController.js
View file @
e92762f2
import
db
from
"
../db/index
"
;
import
db
from
"
../db/index
"
;
import
dotenv
from
"
dotenv
"
;
import
dotenv
from
"
dotenv
"
;
import
jwt
from
"
jsonwebtoken
"
;
import
nodemailer
from
"
nodemailer
"
;
import
nodemailer
from
"
nodemailer
"
;
import
{
serverMSG
,
statusCode
}
from
"
../serverinfo
"
;
import
{
serverMSG
,
statusCode
}
from
"
../serverinfo
"
;
import
routes
from
"
../routes
"
;
dotenv
.
config
();
dotenv
.
config
();
...
@@ -24,7 +26,11 @@ const postMail = async (email, token) => {
...
@@ -24,7 +26,11 @@ const postMail = async (email, token) => {
from
:
`EUE Auth Supply <
${
process
.
env
.
NODEMAILER_USER
}
>`
,
from
:
`EUE Auth Supply <
${
process
.
env
.
NODEMAILER_USER
}
>`
,
to
:
email
,
to
:
email
,
subject
:
"
EUE 사용자 계정 확인용 메일.
"
,
subject
:
"
EUE 사용자 계정 확인용 메일.
"
,
text
:
`You enter locCode :
${
locCode
}
.`
,
html
:
`<a href="
${
process
.
env
.
HOST
}
:
${
process
.
env
.
PORT
}${
routes
.
base
+
routes
.
confirm
}
?token=
${
token
}
">
${
process
.
env
.
HOST
}
:
${
process
.
env
.
PORT
}${
routes
.
base
+
routes
.
confirm
}
?token=
${
token
}
</a>`
,
};
};
try
{
try
{
...
@@ -55,7 +61,7 @@ export const getLogin = (req, res) => {
...
@@ -55,7 +61,7 @@ export const getLogin = (req, res) => {
// Function for Signup Proccess.
// Function for Signup Proccess.
export
const
postSignup
=
async
(
req
,
res
)
=>
{
export
const
postSignup
=
async
(
req
,
res
)
=>
{
const
{
const
{
body
:
{
email
,
locCod
e
},
body
:
{
email
,
nick_nam
e
},
}
=
req
;
}
=
req
;
const
result
=
db
.
User
.
findOne
({
const
result
=
db
.
User
.
findOne
({
...
@@ -63,14 +69,18 @@ export const postSignup = async (req, res) => {
...
@@ -63,14 +69,18 @@ export const postSignup = async (req, res) => {
logging
:
false
,
logging
:
false
,
});
});
if
(
result
)
{
if
(
result
.
length
!=
0
)
{
res
.
status
(
statusCode
.
err
).
json
({
res
.
status
(
statusCode
.
err
).
json
({
msg
:
serverMSG
.
server_err
,
msg
:
serverMSG
.
server_err
,
content
:
"
You are aleady registered
"
,
content
:
"
You are aleady registered
"
,
});
});
}
else
{
}
else
{
db
.
User
.
create
({
email
:
email
,
locCode
:
locCod
e
},
{
logging
:
false
});
db
.
User
.
create
({
email
:
email
,
nick_name
:
nick_nam
e
},
{
logging
:
false
});
// 로그인 페이지로 넘겨주기.
// 로그인 페이지로 넘겨주기.
res
.
status
(
statusCode
.
ok
).
json
({
msg
:
serverMSG
.
server_ok
,
content
:
"
Successfully create user.
"
,
});
}
}
};
};
...
@@ -79,25 +89,44 @@ export const postLogin = (req, res) => {
...
@@ -79,25 +89,44 @@ export const postLogin = (req, res) => {
body
:
{
email
},
body
:
{
email
},
}
=
req
;
}
=
req
;
const
result
=
db
.
User
.
find
One
({
const
result
=
db
.
User
.
find
All
({
where
:
{
email
:
email
},
where
:
{
email
:
email
},
logging
:
false
,
logging
:
false
,
});
});
if
(
result
)
{
if
(
result
.
length
!=
0
)
{
// token 발행
// token 발행
const
token
=
"
ex Token
"
;
const
mail_token
=
jwt
.
sign
(
{
email
:
email
,
nick_name
:
resutl
[
0
][
"
nick_name
"
],
},
process
.
env
.
AUTH_SECRETKEY
,
{
expiresIn
:
10
*
60
,
issuer
:
"
eue.com
"
,
subject
:
"
userInfo
"
,
}
);
// 토큰이 포함된 로그인 링크 전송
// 토큰이 포함된 로그인 링크 전송
postLogin
(
email
,
token
);
postMail
(
email
,
mail_token
);
res
res
.
status
(
statusCode
.
ok
)
.
status
(
statusCode
.
ok
)
.
json
({
msg
:
serverMSG
.
server_ok
,
content
:
"
Send Mail Successfully.
"
});
.
json
({
msg
:
serverMSG
.
server_ok
,
content
:
"
Send Mail Successfully.
"
});
}
else
{
}
else
{
res
res
.
status
(
statusCode
.
err
).
json
({
.
status
(
statusCode
.
err
)
msg
:
serverMSG
.
server_err
,
.
json
({
content
:
"
You are not one of our user yet.
"
,
msg
:
serverMSG
.
server_err
,
});
content
:
"
You are still not our user.
"
,
});
}
}
};
};
export
const
getConfirm
=
(
req
,
res
)
=>
{
const
{
params
:
{
token
},
}
=
req
;
console
.
log
(
`Hi, test token :
${
token
}
`
);
};
server/src/models/user.js
View file @
e92762f2
...
@@ -18,6 +18,11 @@ export class User extends Model {
...
@@ -18,6 +18,11 @@ export class User extends Model {
allowNull
:
false
,
allowNull
:
false
,
primaryKey
:
true
,
primaryKey
:
true
,
},
},
nick_name
:
{
type
:
DataTypes
.
STRING
(
16
),
allowNull
:
false
,
unique
:
true
,
},
password
:
{
password
:
{
type
:
DataTypes
.
STRING
(
20
),
type
:
DataTypes
.
STRING
(
20
),
allowNull
:
false
,
allowNull
:
false
,
...
...
server/src/routers/dataRouter.js
View file @
e92762f2
...
@@ -2,6 +2,7 @@ import express from "express";
...
@@ -2,6 +2,7 @@ import express from "express";
import
routes
from
"
../routes
"
;
import
routes
from
"
../routes
"
;
import
{
import
{
getDataInput
,
getDataInput
,
getLocCode
,
getUserWeatherData
,
getUserWeatherData
,
}
from
"
../controllers/dataController
"
;
}
from
"
../controllers/dataController
"
;
import
{
onlyPrivate
}
from
"
../middlewares
"
;
import
{
onlyPrivate
}
from
"
../middlewares
"
;
...
@@ -10,5 +11,6 @@ const dataRouter = express.Router();
...
@@ -10,5 +11,6 @@ const dataRouter = express.Router();
dataRouter
.
get
(
routes
.
dataInput
,
getDataInput
);
dataRouter
.
get
(
routes
.
dataInput
,
getDataInput
);
dataRouter
.
get
(
routes
.
dataUser
,
onlyPrivate
,
getUserWeatherData
);
dataRouter
.
get
(
routes
.
dataUser
,
onlyPrivate
,
getUserWeatherData
);
dataRouter
.
get
(
routes
.
locCode
,
getLocCode
);
export
default
dataRouter
;
export
default
dataRouter
;
server/src/routers/globalRouter.js
View file @
e92762f2
...
@@ -2,6 +2,7 @@ import express from "express";
...
@@ -2,6 +2,7 @@ import express from "express";
import
routes
from
"
../routes
"
;
import
routes
from
"
../routes
"
;
import
{
getHome
}
from
"
../controllers/globalController
"
;
import
{
getHome
}
from
"
../controllers/globalController
"
;
import
{
import
{
getConfirm
,
getLogin
,
getLogin
,
getSignup
,
getSignup
,
postLogin
,
postLogin
,
...
@@ -10,12 +11,13 @@ import {
...
@@ -10,12 +11,13 @@ import {
const
globalRouter
=
express
.
Router
();
const
globalRouter
=
express
.
Router
();
globalRouter
.
get
(
routes
.
home
,
getHome
);
globalRouter
.
get
(
"
/
"
,
getHome
);
// For development test.
// Authentication
// Authentication
globalRouter
.
get
(
routes
.
signup
,
getSignup
);
// For development test.
globalRouter
.
get
(
routes
.
signup
,
getSignup
);
// For development test.
globalRouter
.
get
(
routes
.
login
,
getLogin
);
// For development test.
globalRouter
.
get
(
routes
.
login
,
getLogin
);
// For development test.
globalRouter
.
post
(
routes
.
signup
,
postSignup
);
globalRouter
.
post
(
routes
.
signup
,
postSignup
);
globalRouter
.
post
(
routes
.
login
,
postLogin
);
globalRouter
.
post
(
routes
.
login
,
postLogin
);
globalRouter
.
get
(
routes
.
confirm
,
getConfirm
);
export
default
globalRouter
;
export
default
globalRouter
;
server/src/routers/locCodeRouter.js
deleted
100644 → 0
View file @
40581228
import
express
from
"
express
"
;
import
routes
from
"
../routes
"
;
import
{
getDoe
,
getEMD
,
getSGG
}
from
"
../controllers/locCodeController
"
;
const
locCodeRouter
=
express
.
Router
();
locCodeRouter
.
get
(
routes
.
doe
,
getDoe
);
locCodeRouter
.
get
(
routes
.
sigungu
+
routes
.
Detail
(),
getSGG
);
locCodeRouter
.
get
(
routes
.
eupmyeondong
+
routes
.
Detail
(),
getEMD
);
export
default
locCodeRouter
;
server/src/routes.js
View file @
e92762f2
// # Global Routes
// # Global Routes
const
HOM
E
=
"
/
"
;
const
BAS
E
=
"
/
api
"
;
// # Data Routes
// # Data Routes
const
DATA
=
"
/data
"
;
const
DATA
=
"
/data
"
;
...
@@ -11,30 +11,26 @@ const DATA_OUTSIDE = "/outside";
...
@@ -11,30 +11,26 @@ const DATA_OUTSIDE = "/outside";
// # Local Code Data
// # Local Code Data
const
LOCCODE
=
"
/loccode
"
;
const
LOCCODE
=
"
/loccode
"
;
const
DOE
=
"
/doe
"
;
const
SIGUNGU
=
"
/si-gun-gu
"
;
const
EUPMYEONDONG
=
"
/eup-myeon-dong
"
;
// # Auth
// # Auth
const
SIGNUP
=
"
/signup
"
;
const
SIGNUP
=
"
/signup
"
;
const
LOGIN
=
"
/login
"
;
const
LOGIN
=
"
/login
"
;
const
CONFIRM
=
"
/confirm
"
;
const
EDIT_PROFILE
=
"
/edit-profile
"
;
const
EDIT_PROFILE
=
"
/edit-profile
"
;
// # Detail Object
// # Detail Object
const
DETAIL
=
"
/:id
"
;
const
DETAIL
=
"
/:id
"
;
const
routes
=
{
const
routes
=
{
home
:
HOM
E
,
base
:
BAS
E
,
data
:
DATA
,
data
:
DATA
,
dataInput
:
DATA_INPUT
,
dataInput
:
DATA_INPUT
,
dataUser
:
DATA_USER
,
dataUser
:
DATA_USER
,
dataOutside
:
DATA_OUTSIDE
,
dataOutside
:
DATA_OUTSIDE
,
locCode
:
LOCCODE
,
locCode
:
LOCCODE
,
doe
:
DOE
,
sigungu
:
SIGUNGU
,
eupmyeondong
:
EUPMYEONDONG
,
signup
:
SIGNUP
,
signup
:
SIGNUP
,
login
:
LOGIN
,
login
:
LOGIN
,
confirm
:
CONFIRM
,
editProfile
:
EDIT_PROFILE
,
editProfile
:
EDIT_PROFILE
,
Detail
:
(
id
)
=>
{
Detail
:
(
id
)
=>
{
if
(
id
)
{
if
(
id
)
{
...
...
server/src/views/home.pug
View file @
e92762f2
...
@@ -3,8 +3,8 @@ block content
...
@@ -3,8 +3,8 @@ block content
strong Efficient Usage of Electricity
strong Efficient Usage of Electricity
ul
ul
li
li
a(href=routes.data
+
routes.dataInput) 데이터 등록
a(href=
routes.base +
routes.data
+
routes.dataInput) 데이터 등록
li
li
a(href=routes.signup) 회원가입
a(href=
routes.base +
routes.signup) 회원가입
li
li
a(href=routes.login) 로그인
a(href=routes.base + routes.login) 로그인
\ No newline at end of file
\ No newline at end of file
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