25 lines
943 B
Python
25 lines
943 B
Python
from flask import Blueprint, request, jsonify
|
|
from model.user import User
|
|
#from module.db.repositories.robot_reposytory import update_robot get_by_id
|
|
from loguru import logger as log
|
|
robots = Blueprint("robots", __name__)
|
|
|
|
robots.route('/data', methods = ['POST'])
|
|
def data():
|
|
if request.headers.get("Authorization"):
|
|
if request.is_json:
|
|
req = request.json
|
|
|
|
id = req.get('robot_id')
|
|
tms = req.get('timestamp')
|
|
loc = req.get('location')
|
|
scanRes = req.get('scan_results')
|
|
battery = req.get('battery_level')
|
|
|
|
if update_robot(id, "received", battery, loc["zone"], loc["row"], loc["self"]):
|
|
res = {"status": "received", "message_id": "123"} #for that moment i don`t now what is message
|
|
return jsonify(res)
|
|
else:
|
|
log.error('failed to update robot data')
|
|
return("Server error")
|