-
-
Notifications
You must be signed in to change notification settings - Fork 122
Fix 152Added edit profile feature #154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -60,8 +60,13 @@ def get_profile(): | |||||||||||
| return jsonify({"error": "Profile not found"}), 404 | ||||||||||||
|
|
||||||||||||
| return jsonify({ | ||||||||||||
| "due_date": profile[7], | ||||||||||||
| "location": profile[6] | ||||||||||||
| "lmp": profile[1], | ||||||||||||
| "cycle_length": profile[2], | ||||||||||||
| "period_length": profile[3], | ||||||||||||
| "age": profile[4], | ||||||||||||
| "weight": profile[5], | ||||||||||||
| "location": profile[6], | ||||||||||||
| "due_date": profile[7] | ||||||||||||
| }), 200 | ||||||||||||
|
|
||||||||||||
| except sqlite3.OperationalError: | ||||||||||||
|
|
@@ -89,21 +94,28 @@ def update_profile(): | |||||||||||
| db = open_db() | ||||||||||||
|
|
||||||||||||
| try: | ||||||||||||
| db.execute('SELECT * FROM profile') | ||||||||||||
| # Check if profile exists | ||||||||||||
| profile = db.execute('SELECT * FROM profile').fetchone() | ||||||||||||
| if profile is None: | ||||||||||||
| return jsonify({"error": "Profile not found"}), 404 | ||||||||||||
|
|
||||||||||||
| data = request.json | ||||||||||||
| lmp = data.get('lmp') | ||||||||||||
| cycle_length = data.get('cycle_length') | ||||||||||||
| period_length = data.get('period_length') | ||||||||||||
| cycle_length = data.get('cycleLength') | ||||||||||||
| period_length = data.get('periodLength') | ||||||||||||
| age = data.get('age') | ||||||||||||
| weight = data.get('weight') | ||||||||||||
| location = data.get('location') | ||||||||||||
|
|
||||||||||||
| if not lmp or not location: | ||||||||||||
| return jsonify({"error": "Last menstrual period and location are required"}), 400 | ||||||||||||
|
|
||||||||||||
| # Recalculate due date based on new LMP and cycle length | ||||||||||||
| due_date = calculate_due_date(lmp, cycle_length) | ||||||||||||
|
|
||||||||||||
| db.execute( | ||||||||||||
| 'UPDATE profile SET due_date = ?, user_location = ?', | ||||||||||||
| (lmp, cycle_length, period_length, age, weight, location) | ||||||||||||
| 'UPDATE profile SET lmp = ?, cycleLength = ?, periodLength = ?, age = ?, weight = ?, user_location = ?, dueDate = ?', | ||||||||||||
| (lmp, cycle_length, period_length, age, weight, location, due_date) | ||||||||||||
| ) | ||||||||||||
| db.commit() | ||||||||||||
|
|
||||||||||||
|
|
@@ -112,6 +124,6 @@ def update_profile(): | |||||||||||
| agent = get_agent(db_path) | ||||||||||||
| agent.update_cache(data_type="profile", operation="update") | ||||||||||||
|
|
||||||||||||
| return jsonify({"status": "success", "message": "Profile updated successfully"}), 200 | ||||||||||||
| except sqlite3.OperationalError: | ||||||||||||
| return jsonify({"error": "Database Error"}), 500 | ||||||||||||
| return jsonify({"status": "success", "message": "Profile updated successfully", "dueDate": due_date}), 200 | ||||||||||||
| except sqlite3.OperationalError as error: | ||||||||||||
| return jsonify({"error": str(error)}), 500 | ||||||||||||
|
||||||||||||
| except sqlite3.OperationalError as error: | |
| return jsonify({"error": str(error)}), 500 | |
| except sqlite3.OperationalError as error: | |
| print(f"Database error in update_profile: {error}") # Log internally | |
| return jsonify({"error": "Database error occurred"}), 500 |
π€ Prompt for AI Agents
In Backend/routes/profile.py around lines 128-129, the except block currently
returns the raw sqlite3.OperationalError string to the client; change it to
return a generic error message (e.g., {"error": "Internal server error"}) with a
500 status to avoid leaking DB details, and log the full exception internally
(using app.logger.exception(...) or logging.exception(...)) so developers still
have the stack trace for debugging while clients only receive the generic
message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix API naming inconsistency between
get_profileandupdate_profile.The response uses snake_case field names (
cycle_length,period_length), butupdate_profile(lines 104-105) expects camelCase (cycleLength,periodLength). This inconsistency breaks the API contract and forces frontend code to transform keys differently for reads vs. writes.Additionally, hardcoded tuple indices (
profile[1],profile[2], etc.) are fragile and will break if the database schema changes or columns are reordered.π§ Proposed fix: Use consistent camelCase naming and dict-based access
First, configure the database connection to return rows as dictionaries. In
db/db.py, updateopen_db():Then update the response to use consistent camelCase:
return jsonify({ - "lmp": profile[1], - "cycle_length": profile[2], - "period_length": profile[3], - "age": profile[4], - "weight": profile[5], - "location": profile[6], - "due_date": profile[7] + "lmp": profile['lmp'], + "cycleLength": profile['cycleLength'], + "periodLength": profile['periodLength'], + "age": profile['age'], + "weight": profile['weight'], + "location": profile['user_location'], + "dueDate": profile['dueDate'] }), 200π€ Prompt for AI Agents