Skip to content

Commit

Permalink
add push
Browse files Browse the repository at this point in the history
  • Loading branch information
Pycomet committed Aug 10, 2020
1 parent dbf7213 commit 8ab050c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@

api.add_resource(Beat, '/')
api.add_resource(UserList, '/users')
api.add_resource(User, '/users/<user_id>')

12 changes: 6 additions & 6 deletions api/routes/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ class UserList(Resource):

def get(self):
result = users_db.find()
return make_response(result)
return make_response(result), 200

def post(self):
payload = request.get_json()
result = users_db.insert_one(payload)
return f"New user added - {result.inserted_id}"
return f"New user added - {result.inserted_id}", 200


class User(Resource):
Expand All @@ -22,9 +22,9 @@ def get(self, user_id):
result = users_db.find_one(criteria)

if result == None:
return "No User Found!"
return "No User Found!", 405
else:
return make_response(result)
return make_response(result), 200

def put(self, user_id):
criteria = {'user_id': user_id}
Expand All @@ -35,10 +35,10 @@ def put(self, user_id):
new_update,
upsert=True
).modified_count
return f"{result} User Updated"
return f"{result} User Updated", 200

def delete(self, user_id):
criteria = {'user_id': user_id}

result = users_db.delete_one(criteria).deleted_count
return f"{result} User Deleted"
return f"{result} User Deleted", 200

0 comments on commit 8ab050c

Please sign in to comment.