def get_user_by_email(email): user = User.search_by_email(email) status = 200 if not isinstance(user, dict): status = 404 user = f'Error 404. User with email: {email} not found' return Response(json.dumps(user), mimetype=mimetype, status=status)
def create_user(): if not request.json: return Response(json.dumps({'error': f'Bad request.'}), mimetype=mimetype, status=400) email = request.json['email'] username = request.json['username'] password = request.json['password'] user = User.search_by_email(email) status = 200 if not isinstance(user, dict): User(email=email, username=username, password=password) result = {'result': f'Status 200. The user was created.'} else: status = 400 result = { 'error': f'Error 400. The user with Email: {email} is already in the database' } return Response(json.dumps(result), mimetype=mimetype, status=status)