def update_note(id): if not request.is_json: raise BadRequest("Missing Json Request") title = request.json.get('title') text = request.json.get('text') note = Note.objects(id=id).first() """ *update_one()* Perform an atomic update on the fields of the first document matched by the query *update()* is for actual Document object update """ note.update(set__title=title, set__text=text, set__updated_at=datetime.utcnow) return jsonify({"message": "updated"}, note.serialize), 201
def delete_note(id): note = Note.objects(id=id).first() if not note: raise NotFound("Note not found") note.delete() return jsonify({"message": "Deleted note with success"})
def get_note(id): note = Note.objects(id=id).first() if not note: raise NotFound("Note not found") return jsonify(note.serialize)