Skip to content

Commit

Permalink
http requests & db working
Browse files Browse the repository at this point in the history
  • Loading branch information
LiamBrem committed Sep 26, 2023
1 parent e883f2f commit e508405
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 15 deletions.
Empty file added models/fieldtrip.py
Empty file.
Empty file added models/teacher.py
Empty file.
7 changes: 1 addition & 6 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,8 @@ def checkHttp():

db.create_all()

user_data = {
"name": "Dawson",
"email": "email.com"
}

response = requests.post(BASE + "user", json=user_data)

response = requests.get(BASE + "user/kHYMghw6DgdfKfik")
# Print the response content and status code for debugging
print(response.json())
print("Response Status Code:", response.status_code)
Expand Down
17 changes: 8 additions & 9 deletions views/parentStudentViews.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
userBP = Blueprint('userBP', __name__)


@userBP.route('/user/<int:id>', methods=['GET'])
@userBP.route('/user/<string:id>', methods=['GET'])
def get_user(id):
# Assuming you want to retrieve a user with a specific ID
user = UserModel.query.get(id)
if user:
return jsonify({"message": "success", "user_id": user.id, "name": user.name, "email": user.email})
return jsonify({"message": "success", "user_id": user.id, "name": user.username, "email": user.email})
else:
return jsonify({"message": "User not found"}), 404

Expand All @@ -22,16 +22,13 @@ def makeID():
return id


@userBP.route('/user', methods=['POST'])
def create_user():
data = request.get_json()
if not data:
return jsonify({"message": "Invalid input data"}), 400
@userBP.route('/user/<username>/<email>', methods=['POST'])
def create_user(username, email):
print(username,email)

# generate a random 16 character long string of letters and digits
id = makeID()
username = data.get("name")
email = data.get("email")
print(id)

if not id or not username or not email:
return jsonify({"message": "Missing required fields"}), 400
Expand All @@ -42,5 +39,7 @@ def create_user():
db.session.add(newUser)
db.session.commit()

print("HERE")

return jsonify({"message": "User Created Successfully", "user_id": newUser.id, "name": newUser.username, "email": newUser.email}), 201

0 comments on commit e508405

Please sign in to comment.