Skip to content

Commit

Permalink
Fix device update problem
Browse files Browse the repository at this point in the history
  • Loading branch information
noahziheng committed Apr 10, 2018
1 parent 361407a commit 84c9609
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions libfreeiot/core/resources/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Author: Noah Gao
Updated at: 2018-02-23
"""
from flask import Response
from flask import Response, abort
from flask_restful import Resource, reqparse
from flask_jwt_simple import jwt_required
from bson import json_util, ObjectId
Expand Down Expand Up @@ -40,13 +40,22 @@ def post(self, device_id=None):
args = parser.parse_args()
if device_id is None:
data = args
data['_id'] = ObjectId()
res = mongo.db.devices.insert_one(data)
else:
data = {}
data["remark"] = args["remark"]
data["status"] = args["status"]
data["version"] = args["version"]
res = mongo.db.devices.save(data)
if not args["remark"] is None:
data["remark"] = args["remark"]
if not args["status"] is None:
data["status"] = args["status"]
if not args["version"] is None:
data["version"] = args["version"]
if not ObjectId.is_valid(device_id):
return abort(400)
if(len(data) < 1):
return abort(400)
mongo.db.devices.update_one({"_id": ObjectId(device_id)},{
"$set": data
})
return Response(
json_util.dumps(data),
mimetype='application/json'
Expand Down

0 comments on commit 84c9609

Please sign in to comment.