-
Notifications
You must be signed in to change notification settings - Fork 1
/
catJson.js
103 lines (87 loc) · 3.01 KB
/
catJson.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// 참고자료 : https://colab.research.google.com/drive/1a2Z0DBGbefkk3os3MbxtBFspOx5idXMV#scrollTo=k4OrsuXwwHzN
const express = require('express');
const mariadb = require('mariadb/callback');
const app = express();
app.listen('8080', () => {
console.log('Server Started');
});
var dbc = mariadb.createConnection({
host: "localhost",
database: "CatDoctor",
user: "root",
password: "mint8120"
});
dbc.connect((err) => {
if (err) throw err;
console.log('Database Connected');
});
app.get('/symptom', (req, res) => {
var query = `SELECT * FROM symptom`;
dbc.query(query, (err, result, fields) => {
if (err) return console.log(err);
res.send(result);
});
});
app.get('/symptom_classify', (req, res) => {
var query = `SELECT * FROM symptom WHERE symptom_classify=${req.query.symptom_classify}`;
dbc.query(query, (err, result, fields) => {
if (err) return console.log(err);
res.send(result);
});
});
app.get('/symptom_distinct', (req, res) => {
var query = `SELECT distinct symptom_classify, image FROM symptom`;
dbc.query(query, (err, result, fields) => {
if (err) return console.log(err);
res.send(result);
});
});
app.get('/disease_id', (req, res) => {
var query = `SELECT disease.id FROM disease inner join disease_symptom on disease_symptom.symptom_id in ${req.query.symptom_id} and disease_symptom.disease_id=disease.id`;
dbc.query(query, (err, result, fields)=> {
if (err) return;
res.send(result);
});
});
app.get('/symptom_id', (req, res) => {
var query = `SELECT distinct symptom.id, symptom.symptom_name FROM symptom inner join disease_symptom on disease_symptom.disease_id in ${req.query.disease_id} and disease_symptom.symptom_id=symptom.id`;
dbc.query(query, (err, result, fields)=> {
if (err) return;
res.send(result);
});
});
app.get('/disease', (req, res) => {
var query = `SELECT * FROM disease where id in (${req.query.id}) order by field(id, ${req.query.id})`;
dbc.query(query, (err, result, fields)=> {
if (err) return console.log(err);
res.send(result);
});
});
app.use('/image', express.static('images'));
app.use(express.urlencoded());
app.get('/user', (req, res) => {
var query = 'SELECT * FROM user';
dbc.query(query, (err, result, fields) => {
if (err) return console.log(err);
res.send(result);
});
});
app.post('/insert', (req, res) => {
//console.log(req.body.name);
var query = `INSERT INTO user VALUES (NULL, "${req.body.user_id}", "${req.body.password}", "${req.body.name}", "${req.body.nickname}")`;
//console.log(query);
dbc.query(query, (err, result, fields) => {
if (err) return console.log(err);
//res.send(result);
var str = req.body.name;
str += hasJongsung(req.body.name) ? "을" : "를";
str += " 추가했습니다.";
res.send(str)
});
})
function hasJongsung(str) {
//var jong = String.fromCharCode(str.charCodeAt(str.length - 1));
//console.log(jong);
var jong = str.charCodeAt(str.length - 1);
return ((jong - 44032) % 28 == 0) ? false : true;
}