Created
August 11, 2020 11:55
-
-
Save bubnenkoff/283bd1b8fc34918ba683e7ed9a4df00c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:convert'; | |
import 'dart:io'; | |
import 'package:http_middleware/database.dart'; | |
import 'package:dart_express/dart_express.dart'; | |
import 'package:http_middleware/json_match.dart'; | |
import 'package:http_middleware/global.dart'; | |
import 'dart:convert'; | |
const int PORT = 5000; | |
void main() async { | |
var pidFile = File("pid.txt"); | |
pidFile.writeAsStringSync(pid.toString()); | |
var app = express(); | |
app.use(BodyParser.json()); | |
Database db = Database(); | |
await db.connect(); | |
MatchQuery matchQuery = MatchQuery(db); | |
app.post('/notifications', (req, res) async { | |
dbEnums insertResult = await matchQuery.matchAndInsert("notifications", req.body); | |
switch (insertResult) { | |
// только в этих двух случаях есть смысл продолжать | |
// в остальных нужно чтобы была устранена причина ошибки | |
case dbEnums.success: | |
return res.json({'status': 'success'}); | |
case dbEnums.alreadyExists: | |
return res.json({'status': 'alreadyExists'}); | |
case dbEnums.insertFailed: | |
return res.json({'status': 'insertFailed'}); | |
case dbEnums.purchaseDoNotExits: | |
return res.json({'status': 'purchaseDoNotExits'}); | |
default: | |
return res.json({'status': 'unkownStatus'}); | |
} | |
}); | |
app.post('/protocols', (req, res) async { | |
dbEnums insertResult = await matchQuery.matchAndInsert("protocols", req.body); | |
switch (insertResult) { | |
// только в этих двух случаях есть смысл продолжать | |
// в остальных нужно чтобы была устранена причина ошибки | |
case dbEnums.success: | |
return res.json({'status': 'success'}); | |
case dbEnums.alreadyExists: | |
return res.json({'status': 'alreadyExists'}); | |
case dbEnums.insertFailed: | |
return res.json({'status': 'insertFailed'}); | |
case dbEnums.purchaseDoNotExits: | |
return res.json({'status': 'purchaseDoNotExits'}); | |
default: | |
return res.json({'status': 'unkownStatus'}); | |
} | |
}); | |
app.post('/contracts', (req, res) async { | |
dbEnums insertResult = await matchQuery.matchAndInsert("contracts", req.body); | |
switch (insertResult) { | |
// только в этих двух случаях есть смысл продолжать | |
// в остальных нужно чтобы была устранена причина ошибки | |
case dbEnums.success: | |
return res.json({'status': 'success'}); | |
case dbEnums.alreadyExists: | |
return res.json({'status': 'alreadyExists'}); | |
case dbEnums.insertFailed: | |
return res.json({'status': 'insertFailed'}); | |
case dbEnums.purchaseDoNotExits: | |
return res.json({'status': 'purchaseDoNotExits'}); | |
default: | |
return res.json({'status': 'unkownStatus'}); | |
} | |
}); | |
app.post('/parsing', (req, res) async { | |
var x = await db.getListOfFilesForProcessing(req.body); | |
return res.json({"data": x}); | |
}); | |
app.post('/commands', (req, res) async { | |
db.commandFromParser(req.body); | |
return res.json({}); | |
}); | |
app.listen(PORT, (port) => print('Listening on port $port')); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment