def get_user(id): if request.method == 'GET': return User(db_client).find_by_id(id) elif request.method == 'DELETE': user = User(db_client).find_by_id(id) if user: db_resp = User(db_client).remove(db_client, id) print(db_resp) if db_resp['n'] == 1: http_resp = jsonify(succes=True, status_code=204) return http_resp else: return jsonify(success=False, status_code=404) elif request.method == 'PUT': user = User(db_client).find_by_id(id) if user: usr_to_add = User(db_client, json=request.get_json()) db_resp = usr_to_add.reload(id, db_client) http_resp = jsonify(usr_to_add.json, 200) return http_resp else: return jsonify(204)
def get_user(id): if request.method == 'GET': user = User({"_id": id}) if user.reload(): return user else: return jsonify({"error": "User not found"}), 404 elif request.method == 'DELETE': user = User({"_id": id}) resp = user.remove() if resp.hasWriteConcernError() or resp.hasWriteError(): return 404 return {}, 204
def get_user(id): if request.method == 'GET': user = User({"_id": id}) if user.reload(): return user else: return jsonify({"error": "User not found"}), 404 elif request.method == 'DELETE': ## still the old version. Turn it into the DB version user = User({"_id": id}) if user.remove(): resp = jsonify(), 204 return resp return jsonify({"error": "User not found"}), 404
def get_user(id): if request.method == 'GET': user = User({"_id": id}) if user.reload(): return user else: return jsonify({"error": "User not found"}), 404 elif request.method == 'DELETE': user = User({"_id": id}) resp = user.remove() if resp['n'] == 1: return jsonify({"success": "User was removed"}), 204 return jsonify({"error": "User not found"}), 404 elif request.method == 'PATCH': user = User({"_id": id}) data = request.get_json() for key in data: user.update_user(key, data[key]) return jsonify({"Success": "User was patched"}), 200