-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.txt
488 lines (457 loc) · 16.2 KB
/
node.txt
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
var fs = require('fs');
const express = require('express');
var http = require('http');
var bodyParser = require('body-parser')
var socketio = require('socket.io')
const app = express();
app.set('port',process.env.PORT || 3000);
app.use(bodyParser.urlencoded({extended:false}));
app.use(bodyParser.json());
var mongoose = require('mongoose');
const { json } = require('express');
mongoose.connect('mongodb://127.0.0.1:27017/pro3');
var db = mongoose.connection;
db.on('error', function(){
console.log('Connection Failed!');
});
db.once('open', function() {
console.log('Connected!');
});
var information = mongoose.Schema({
name : 'string',
email : 'string',
mode : 'string'
});
var waitinginfo = mongoose.Schema({
rider : 'string',
from : 'string',
to : 'string',
driverEmail : 'string',
driverName : 'string'
});
var gpsinfo = mongoose.Schema({
email : 'string',
latitude : 'number',
longitude : 'number'
});
var recordinfo = mongoose.Schema({
from : 'string',
to : 'string',
startTime : 'string',
endTime : 'string',
price : 'string'
})
var User = mongoose.model('user', information);
var Rider = mongoose.model('rider', information);
var Driver = mongoose.model('driver', information);
var Waiting = mongoose.model('waiting', waitinginfo);
var Matching = mongoose.model('matching', waitinginfo);
var GPS = mongoose.model('gps', gpsinfo);
var Rrecord = mongoose.model('rrecord', recordinfo);
var Drecord = mongoose.model('drecord', recordinfo);
app.post('/login/facebook', function(req, res, next) {
var userEmail = JSON.parse(req.body.fbUserData)['email'];
var userName = JSON.parse(req.body.fbUserData)['name'];
console.log("login fb Email : ", userEmail);
console.log("login fb Name : ", userName);
var newUser = new User({name:userName, email:userEmail, mode:"false"});
newUser.save(function(error, data){
if(error){
console.log(error);
}else{
console.log('Saved!');
}
});
var arr = []
arr.push({email:userEmail, name:userName, mode:""})
res.json(arr[0])
});
app.post('/login/mode', function(req, res, next){
var userEmail = JSON.parse(req.body.fbUserData)['email'];
var userName = JSON.parse(req.body.fbUserData)['name'];
var userMode = JSON.parse(req.body.fbUserData)['mode'];
console.log("login mode : ", userMode);
async function findif() {
var user = await User.find({email:userEmail, mode:'false'})
return user
};
findif().then( result => {
var arr = []
if(userMode == "rider"){
var newRider = new Rider({name:userName, email:userEmail, mode:"rider"});
newRider.save(function(error, data){
if(error){
console.log(error);
}else{
console.log('Rider Saved!');
}
});
}
else if(userMode == "driver"){
var newDriver = new Driver({name:userName, email:userEmail, mode:"driver"});
newDriver.save(function(error, data){
if(error){
console.log(error);
}else{
console.log('Driver Saved!');
}
});
}
else{
console.log('MODE ERROR!');
}
arr.push({email:result[0].email, name:result[0].name, mode:userMode})
console.log(arr[0])
res.json(arr[0])
});
/*
(async() => {
await Info.updateOne({email:userEmail}, {mode:userMode});
var arr = []
arr.push({email:userEmail, name:userName, mode:userMode})
console.log(arr.toString())
res.json()
})();*/
});
app.post('/call/waiting', function(req, res, next){
var waitingRider = JSON.parse(req.body.waitingData)['rider'];
var start = JSON.parse(req.body.waitingData)['from'];
var goal= JSON.parse(req.body.waitingData)['to'];
var arr = []
console.log("waiting : ", waitingRider)
console.log("from : ", start)
console.log("to : ", goal)
//Waiting
var newWaiting = new Waiting({rider:waitingRider, from:start, to:goal, driverEmail:"null", driverName:"null"});
newWaiting.save(function(error, data){
if(error){
console.log(error);
}else{
console.log('New Waiting!!');
}
});
arr.push({rider:waitingRider, from:start, to:goal})
console.log(arr[0])
res.json(arr[0])
})
app.post('/listen/waiting', function(req, res, next){
/*
(async() => {
await Info.updateOne({email:userEmail}, {mode:userMode});
var arr = []
arr.push({email:userEmail, name:userName, mode:userMode})
console.log(arr.toString())
res.json()
})();*/
var arr=[]
//(method) Model<Document<any>>.count
//(callback?: (err: any, count: number) => void): any (+1 overload)
Waiting.countDocuments({}, function(err, count){
if(count!=0){
async function findif() {
var user = await Waiting.find()
//console.log(user)
console.log(count)
return user
};
findif().then( result => {
arr.push({
rider:result[0].rider,
from:result[0].from,
to:result[0].to,
driverEmail:result[0].driverEmail,
driverName:result[0].drvierName
})
console.log("result:",arr)
res.json(arr[0])
});
}
else{
arr.push({
rider:"null",
from:"null",
to:"null",
driverEmail:"null",
driverName:"null"
})
console.log(arr[0])
res.json(arr[0])
}
});
})
app.post('/response/waiting', function(req, res, next){
var waitingRider = JSON.parse(req.body.responseData)['rider']
var responseEmail = JSON.parse(req.body.responseData)['driverEmail']
var responseName = JSON.parse(req.body.responseData)['driverName']
//console.log("waiting rider : ", waitingRider)
async function findif() {
var user = await Waiting.find({rider:waitingRider})
return user
};
findif().then( result => {
//console.log(result)
var arr = []
var newMatching = new Matching({
rider:result[0].rider,
from:result[0].from,
to:result[0].to,
driverEmail:responseEmail,
driverName:responseName});
newMatching.save(function(error, data){
if(error){
console.log(error);
}else{
console.log('Matching Saved!');
Waiting.deleteMany({rider:waitingRider}, function(err, result){
if(err){
console.log(err)
}
});
}
});
arr.push({
rider:result[0].rider,
from:result[0].from,
to:result[0].to,
driverEmail:responseEmail,
driverName:responseName
})
console.log(arr[0])
res.json(arr[0])
});
})
app.post('/gps', function(req, res, next){
var mode = JSON.parse(req.body.GPSdata)['mode'];
var lat = JSON.parse(req.body.GPSdata)['latitude'];
var long = JSON.parse(req.body.GPSdata)['longitude'];
var rider = JSON.parse(req.body.GPSdata)['rider'];
var driver = JSON.parse(req.body.GPSdata)['driver'];
console.log('driveremail:', driver)
var arr = []
/*
GPS
email : 'string',
latitude : 'double',
longitude : 'double'
*/
if(mode == 'rider'){
async function findif() {
var riders = await GPS.find({email:rider})
//console.log(user)
return riders
};
findif().then( result => {
console.log("rider len : ", result.length)
if(result.length!=0){ // 라이더 이메일이 저장되어 있다면
(async() => {
await GPS.updateOne({email:rider},
{latitude:lat, longitude:long}); // 경도위도 업데이트
})();
}
else{ // 라이더 이메일이 안 저장되어 있다면, 새로 저장
var newGPS = new GPS({email:rider, latitude:lat, longitude:long});
newGPS.save(function(error, data){
if(error){
console.log(error);
}
});
}
var dLat = 0.0
var dLong = 0.0
///드라이버 GPS 정보 탐색
async function findif() {
var drivers = await GPS.find({email:driver})
return drivers
};
findif().then( result => {
if(result.length!=0){ // 드라이버 GPS 정보가 있다면
// 경도위도 데이터 가져오기
dLat = result[0].latitude
dLong = result[0].longitude
}
else{ // 드라이버 GPS 정보가 없다면
// 쓰레기값 넣어주기
dLat = -1.0
dLong = -1.0
}
arr.push({riderLat:lat, riderLong:long,
driverLat:dLat, driverLong : dLong})
console.log(arr[0])
res.json(arr[0])
});
});
}else if (mode == 'driver'){
async function findif() {
var drivers = await GPS.find({email:driver})
//console.log('driver :', driver)
//console.log('drivers : ', drivers)
return drivers
};
findif().then( result => {
console.log("driver len : ", result.length)
if(result.length!=0){ // 드라이버 이메일이 저장되어 있다면
(async() => {
await GPS.updateOne({email:driver},
{latitude:lat, longitude:long}); // 경도위도 업데이트
})();
}
else{ // 드라이버 이메일이 안 저장되어 있다면, 새로 저장
var newGPS = new GPS({email:driver, latitude:lat, longitude:long});
newGPS.save(function(error, data){
if(error){
console.log(error);
}
});
}
var rLat = 0.0
var rLong = 0.0
///라이더 GPS 정보 탐색
async function findif() {
var riders = await GPS.find({email:rider})
return riders
};
findif().then( result => {
if(result.length!=0){ // 드라이버 GPS 정보가 있다면
// 경도위도 데이터 가져오기
rLat = result[0].latitude
rLong = result[0].longitude
}
else{ // 드라이버 GPS 정보가 없다면
// 쓰레기값 넣어주기
rLat = -1.0
rLong = -1.0
}
arr.push({riderLat:rLat, riderLong:rLong,
driverLat:lat, driverLong : long})
console.log(arr[0])
res.json(arr[0])
});
});
}else{
console.log("MODE ERROR!!")
arr.push({riderLat:-1.0, riderLong:-1.0,
driverLat:-1.0, driverLong : -1.0})
res.json(arr[0])
}
})
app.post('/call/matching', function(req, res, next){
var waitingRider = req.body.rider
Matching.countDocuments({}, function(err, count){
if(count!=0){
async function findif() {
var matchSet = await Matching.find({rider:waitingRider})
//console.log(user)
console.log(count)
return matchSet
};
findif().then( result => {
var arr = []
arr.push({
rider:result[0].rider,
from:result[0].from,
to:result[0].to,
driverEmail:result[0].driverEmail,
driverName:result[0].driverName
})
Matching.deleteMany({rider:result[0].rider}, function(err, result){
if(err){
console.log(err)
}
});
console.log("match:",arr)
res.json(arr[0])
});
}
else{
var arr=[]
arr.push({
rider:"null",
from:"null",
to:"null",
driverEmail:"null",
driverName:"null"
})
console.log(arr[0])
res.json(arr[0])
}
});
})
app.post('/record/rider', function(req, res, next){
var mfrom = JSON.parse(req.body.RecordData)['from'];
var mto = JSON.parse(req.body.RecordData)['to'];
var mstartTime = JSON.parse(req.body.RecordData)['startTime'];
var mendTime = JSON.parse(req.body.RecordData)['endTime'];
var mprice = JSON.parse(req.body.RecordData)['price'];
var arr = []
var newRrecord = new Rrecord({
from:mfrom, to:mto, startTime:mstartTime, endTime:mendTime, price:mprice});
newRrecord.save(function(error, data){
if(error){
console.log(error);
}else{
console.log('Rider Record Saved!');
}
});
arr.push({
from:mfrom, to:mto, startTime:mstartTime, endTime:mendTime, price:mprice
})
console.log(arr[0])
res.json(arr[0])
})
app.post('/record/driver', function(req, res, next){
console.log(req.body)
var mfrom = JSON.parse(req.body.RecordData)['from'];
var mto = JSON.parse(req.body.RecordData)['to'];
var mstartTime = JSON.parse(req.body.RecordData)['startTime'];
var mendTime = JSON.parse(req.body.RecordData)['endTime'];
var mprice = JSON.parse(req.body.RecordData)['price'];
var arr = []
var newDrecord = new Drecord({
from:mfrom, to:mto, startTime:mstartTime, endTime:mendTime, price:mprice});
newDrecord.save(function(error, data){
if(error){
console.log(error);
}else{
console.log('Driver Record Saved!');
}
});
arr.push({
from:mfrom, to:mto, startTime:mstartTime, endTime:mendTime, price:mprice
})
console.log(arr[0])
res.json(arr[0])
})
var server = http.createServer(app).listen(app.get('port'),function(){
console.log("익스프레스로 웹 서버를 실행함 : "+ app.get('port'));
});
//var io = socketio.listen(server);
/*
val REQUEST_TAKE_PHOTO = 1
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if(resultCode == RESULT_OK) {
if (requestCode == REQUEST_TAKE_PHOTO) {
var bundle: Bundle? = data?.getExtras()
var bitmap: Bitmap = bundle?.get("data") as Bitmap
var changedUri: Uri = BitmapToUri(this.requireContext(), bitmap)
//ImageDataset.add(MediaFileData(changedUri))
//gallery.setImageBitmap(bitmap)
}
refreshFragment(this, activity!!.supportFragmentManager)
}
}
fun BitmapToUri(context: Context, bitmap: Bitmap): Uri {
var bytes = ByteArrayOutputStream()
bitmap.compress(Bitmap.CompressFormat.JPEG,100, bytes)
val path = MediaStore.Images.Media.insertImage(context.contentResolver, bitmap, "Title", null)
return Uri.parse(path.toString())
}
private fun takePicture() {
//카메라 앱 실행
var capture = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
startActivityForResult(capture, REQUEST_TAKE_PHOTO)
}
fun refreshFragment(fragment: Fragment, fragmentManager: FragmentManager){
var ft: FragmentTransaction = fragmentManager.beginTransaction()
ft.detach(fragment).attach(fragment).commit()
}*/