Skip to content
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

"Updated HTTP requests to return JSON responses" #124

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Event/auth/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
def register_or_login():
"""Register and Login route for google authentication"""
data = request.get_json()

# lets check if the request body has the required data
if not data:
raise CustomError("Bad Request", 400, "Missing JSON data in request")

# lets collect the credential token from request body
credential_token = data.get("token")
Expand Down
2 changes: 1 addition & 1 deletion Event/events/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def update_event(event_id: str) -> tuple:
return jsonify({
"message": "item updated",
"Event_id": event_id,
"data": db_data.format()}), 201
"data": format(db_data)}), 200
except Exception as exc:
print(f"{type(exc).__name__}: {exc}")
return jsonify({"error": str(exc)}), 400
Expand Down
4 changes: 2 additions & 2 deletions Event/groups/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def update_group(group_id):
"group": group.format(),
}
),
201,
200,
)

except Exception as error: # pylint: disable=broad-except
Expand Down Expand Up @@ -242,7 +242,7 @@ def delete_group(group_id):
# Delete the group from the database
group.delete()

return jsonify({"message": "Group deleted successfully"}),204
return jsonify({"message": "Group deleted successfully"}), 204

except Exception as e:
# Handle any exceptions that may occur during deletion
Expand Down
19 changes: 14 additions & 5 deletions Event/user/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

users = Blueprint("users", __name__, url_prefix="/api/users")


# Placeholder function for future implementation
@users.route("/")
def get_active_signals():
"""
Expand All @@ -27,6 +27,7 @@ def get_active_signals():

# Checked
# GET /api/users/<string:user_id>: Get user profile
# Endpoint to retrieve user information based on user ID
@users.route("/<string:user_id>")
def get_user_info(user_id: str):
"""gets the user info for the profile page
Expand Down Expand Up @@ -59,6 +60,7 @@ def get_user_info(user_id: str):

# Checked
# PUT /api/users/<string:user_id>: Update user profile
# Endpoint to update user information based on user ID
@users.route("/<string:user_id>", methods=['PUT'], strict_slashes=False)
def update_user(user_id: str):
"""updates the user details
Expand Down Expand Up @@ -99,21 +101,28 @@ def update_user(user_id: str):
@users.route("/<string:user_id>/interests/<string:event_id>",
methods=["POST"], strict_slashes=False)
def create_interest(user_id, event_id):
"""Create interest in an event"""
"""
Registers a user's interest in a specific event.
Args:
user_id (str): The ID of the user showing interest.
event_id (str): The ID of the event the user is interested in.
Returns:
JSON response indicating the success or failure of the operation.
"""
try:
user = query_one_filtered(Users, id=user_id)
event = query_one_filtered(Events, id=event_id)

if not user:
return jsonify({"Error": "User not found"}), 404
return jsonify({"error": "User not found"}), 404

if not event:
return jsonify({"Error": "Event not found"}), 404
return jsonify({"error": "Event not found"}), 404

user.interested_events.append(event)
user.update()

return jsonify({"message": "Interest registered"}), 200
return jsonify({"message": "Interest registered"}), 201

except Exception as e:
db.session.rollback()
Expand Down