Commit 36bfc116 authored by Spark's avatar Spark
Browse files

Merge remote-tracking branch 'origin/premaster' into who

parents ea90c8ea e11c97e9
import { DataTypes, Model } from "sequelize";
import Emd from "./emd";
export class Weather_Out extends Model {
static init(sequelize) {
return super.init(
{
loc_code: {
type: DataTypes.INTEGER,
primaryKey: true,
references: {
model: Emd,
key: "code_emd",
},
},
collected_at: {
type: DataTypes.DATE,
primaryKey: true,
},
temp: {
type: DataTypes.FLOAT,
defaultValue: 0,
},
humi: {
type: DataTypes.FLOAT,
defaultValue: 0,
},
press: {
type: DataTypes.FLOAT,
defaultValue: 0,
},
wind_speed: {
type: DataTypes.FLOAT,
defaultValue: 0,
},
},
{
sequelize,
timestamps: false,
paranoid: false,
}
);
}
static associate(db) {
// weather_out 모델이 참조하는 테이블에 대한 외래키 설정.
db.Weather_out.belongsTo(db.Emd, {
foreignKey: "loc_code",
targetKey: "code_emd",
});
}
}
export default Weather_Out;
import fs from "fs";
import mysql from "mysql";
import dotenv from "dotenv";
dotenv.config();
// DB Connection
const db = mysql.createConnection({
host: process.env.MYSQL_HOST || "localhost",
user: process.env.MYSQL_USER || "root",
password: process.env.MYSQL_PASSWORD,
database: process.env.MYSQL_DATABASE || "EUE",
});
const inputDo = (code, name) => {
name = name.replace(/\s/g, "");
let q = `INSERT INTO LOCDO (CODE,DONAME) VALUES (${code},'${name}');`;
db.query(q, (err, result) => {
if (err) {
console.log(err);
return;
}
console.log("Result : " + result);
});
};
const inputSi = (code, name, doCode) => {
name = name.replace(/\s/g, "");
let q = `INSERT INTO LOCSIGUNGU (CODE,DOCODE,SGGNAME) VALUES (${code},${doCode},'${name}');`;
db.query(q, (err, result) => {
if (err) {
console.log(err);
return;
}
console.log("Result : " + result);
});
};
const inputDong = (code, name, doCode, siCode) => {
name = name.replace(/\s/g, "");
let q = `INSERT INTO LOCINFO (CODE,DOCODE,SGGCODE,EMDNAME) VALUES (${code},${doCode},${siCode},'${name}');`;
db.query(q, (err, result) => {
if (err) {
console.log(err);
return;
}
console.log("Result : " + result);
});
};
const setDB = () => {
// DB Connect
db.connect((err) => {
if (err) {
console.log(err);
return;
}
console.log("connected as id" + db.threadId);
});
// File Read
let originData = fs.readFileSync("data/admAddressCode.csv", "utf8");
// Separate Data & Input Data
let sepData = originData.split("\r\n");
let setDoCode = new Set();
let setSiCode = new Set();
sepData.forEach((line) => {
line = line.replace(/\s/g, "");
let addr = line.split(",");
const doCode = Number(addr[0]);
if (!setDoCode.has(doCode)) {
const doName = addr[1];
inputDo(doCode, doName);
setDoCode.add(doCode);
}
const siCode = Number(addr[2]);
if (!setSiCode.has(siCode)) {
const siName = addr[3];
inputSi(siCode, siName, doCode);
setSiCode.add(siCode);
}
const dongCode = Number(addr[4]);
const dongName = addr[5];
inputDong(dongCode, dongName, doCode, siCode);
});
// Connection Close
db.end();
};
setDB();
/*
# EUE Server Database Schema
1. LOCDO
- 행정구역 도/특별시/특별자치시 이름과 코드 저장
- LOCSIGUNGU와 LOCINFO에 참조됨
2. LOCSIGUNGU
- 행정구역 시/군/구 이름과 코드 저장
- LOCDO를 참조
- LOCINFO에 참조됨
3. LOCINFO
- 행정구역 읍/면/동 이름과 코드 및 날씨 정보 URL 저장
- LOCDO와 LOCSIGUNGU를 참조
4. USER
- 사용자 ID, PassWord, 거주지역코드, 데이터 URL 저장
- LOCINFO를 참조
*/
CREATE TABLE LOCDO
(
CODE INT NOT NULL,
DONAME VARCHAR(20) NOT NULL,
PRIMARY KEY(CODE)
);
CREATE TABLE LOCSIGUNGU
(
CODE INT NOT NULL,
DOCODE INT NOT NULL,
SGGNAME VARCHAR(20) NOT NULL,
PRIMARY KEY(CODE),
FOREIGN KEY(DOCODE) REFERENCES LOCDO(CODE) ON UPDATE CASCADE ON DELETE RESTRICT
);
CREATE TABLE LOCINFO
(
CODE INT NOT NULL,
DOCODE INT NOT NULL,
SGGCODE INT NOT NULL,
EMDNAME VARCHAR(20) NOT NULL,
DATALINK TEXT,
PRIMARY KEY(CODE),
FOREIGN KEY(DOCODE) REFERENCES LOCDO(CODE) ON UPDATE CASCADE ON DELETE RESTRICT,
FOREIGN KEY(SGGCODE) REFERENCES LOCSIGUNGU(CODE) ON UPDATE CASCADE ON DELETE RESTRICT
);
CREATE TABLE USER
(
ID VARCHAR(20) UNIQUE NOT NULL,
PW VARCHAR(20) NOT NULL,
LOCCODE INT NOT NULL,
DATALINK TEXT,
PRIMARY KEY(ID),
FOREIGN KEY(LOCCODE) REFERENCES LOCINFO(CODE) ON UPDATE CASCADE ON DELETE RESTRICT
);
\ No newline at end of file
import express from "express";
import routes from "../routes";
import { getDataInput, getUserData } from "../controllers/dataController";
import {
getDataInput,
getUserWeatherData,
} from "../controllers/dataController";
import { onlyPrivate } from "../middlewares";
const dataRouter = express.Router();
dataRouter.get(routes.dataInput, getDataInput);
dataRouter.get(routes.dataUser, onlyPrivate, getUserData);
dataRouter.get(routes.dataUser, onlyPrivate, getUserWeatherData);
export default dataRouter;
import express from "express";
import routes from "../routes";
import { getHome } from "../controllers/globalController";
import {
getLogin,
getSignup,
postLogin,
postSignup,
} from "../controllers/userController";
const globalRouter = express.Router();
globalRouter.get(routes.home, getHome);
// Authentication
globalRouter.get(routes.signup, getSignup); // For development test.
globalRouter.get(routes.login, getLogin); // For development test.
globalRouter.post(routes.signup, postSignup);
globalRouter.post(routes.login, postLogin);
export default globalRouter;
import express from "express";
import routes from "../routes";
import { getDo, getEMD, getSGG } from "../controllers/locCodeController";
import { getDoe, getEMD, getSGG } from "../controllers/locCodeController";
const locCodeRouter = express.Router();
locCodeRouter.get(routes.do, getDo);
locCodeRouter.get(routes.doe, getDoe);
locCodeRouter.get(routes.sigungu + routes.Detail(), getSGG);
locCodeRouter.get(routes.eupmyeondong + routes.Detail(), getEMD);
......
......@@ -11,12 +11,12 @@ const DATA_OUTSIDE = "/outside";
// # Local Code Data
const LOCCODE = "/loccode";
const DO = "/do";
const DOE = "/doe";
const SIGUNGU = "/si-gun-gu";
const EUPMYEONDONG = "/eup-myeon-dong";
// # Auth
const REGISTER = "/register";
const SIGNUP = "/signup";
const LOGIN = "/login";
const EDIT_PROFILE = "/edit-profile";
......@@ -30,10 +30,10 @@ const routes = {
dataUser: DATA_USER,
dataOutside: DATA_OUTSIDE,
locCode: LOCCODE,
do: DO,
doe: DOE,
sigungu: SIGUNGU,
eupmyeondong: EUPMYEONDONG,
register: REGISTER,
signup: SIGNUP,
login: LOGIN,
editProfile: EDIT_PROFILE,
Detail: (id) => {
......
......@@ -5,4 +5,6 @@ block content
li
a(href=routes.data+routes.dataInput) 데이터 등록
li
a(href=routes.data+routes.dataOutput) 데이터 출력
\ No newline at end of file
a(href=routes.signup) 회원가입
li
a(href=routes.login) 로그인
\ No newline at end of file
block content
.login-form_container
form(action=routes.login, method="post")
input(type="email", name="email", require=true, placeholder="E-mail")
input(type="submit", value="Submit")
\ No newline at end of file
block content
.signup-form_container
form(action = routes.signup, method = "post")
input(type="email", name="email", require=true, placeholder="E-mail")
input(type="number", name="locCode")
input(type="submit", value="Submit")
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment