def delete(self, google_tok): """Deletes a user from the database. Args: google_tok (str): The google token of the book being deleted. Returns: message: What happened with the delete call. """ auth_error = auth.google_tok_mismatch_headers(google_tok, request.headers) if auth_error: return auth_error user = UserModel.find_by_google_tok(google_tok) if user: user.delete_from_db() return {"message": "User deleted"} return {"message": "User with user_id (" + google_tok + ") does not exist."}, 404
def get(self, tokens): """Gets a list of all users in database that match any token from a list of tokens.. Args: tokens (str[]): A list of tokens to query with. Returns: json[]: A list of jsonified users that match the tokens. """ auth_error = auth.google_tok_mismatch_headers(google_tok, request.headers) if auth_error: return auth_error tokens = tokens.split(",") all_users = UserModel.query.filter( UserModel.google_tok.in_(tokens)).all() return {"users": [user.bare_json() for user in all_users]}
def post(self, google_tok): """Posts a user to the database. Args: google_tok (str): The google token of the user being posted. Returns: message: What happened with the post call. """ auth_error = auth.google_tok_mismatch_headers(google_tok, request.headers) if auth_error: return auth_error data = User.parser.parse_args() print("hello") if UserModel.find_by_google_tok(google_tok): return {'message': 'user '+str(google_tok)+' already exists'}, 200 user = UserModel(google_tok, data['imageURL'], data['email'], data['name'], data['givenName'], data['familyName']) user.save_to_db() return {"message": "User created successfully."}, 201