Skip to content

Conversation

@jaswanthDuddu
Copy link
Member

Description

This pull request introduces two major new features to the backend, complete with testing:

  1. Single Opportunity Endpoint: Implements a new route (GET /opportunity/<int:opportunity_id>) to fetch all details for a single opportunity. This also includes helper functions to properly serialize the opportunity data for the JSON response.
  2. User Profile Management: Adds two new protected routes, GET /profile and PUT /profile. These endpoints allow an authenticated user to fetch their own profile data and update it, including personal details (name, website, etc.) and their associated majors and departments.

These changes provide the core API functionality needed for the frontend to build the individual opportunity view page and the user profile settings page.

Fixes # (issue)

(Please link the relevant issue number here, if one exists)

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

This PR has been tested by adding new unit test files for both major features:

  1. Single Opportunity Endpoint:

    • Tests were added/updated in test_opportunity.py and test_single_opportunity_routes.py.
    • These tests verify that the endpoint successfully returns the correct opportunity data for a valid ID and correctly returns a 404 error for a non-existent ID.
  2. User Profile Management:

    • A new test file, test_profile_routes.py, was created to provide full coverage for the new endpoints.
    • Tests cover GET /profile success (for an authenticated user) and failure (for an unauthorized user).
    • Tests cover PUT /profile success (for both full and partial data updates) and failure (for an unauthorized user).

All new and existing unit tests pass locally with these changes. The User Profile Management is not fully passing, as the existing authentication code needs fixes.

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works (if a larger change)
  • New and existing unit tests pass locally with my changes

jaswanthDuddu and others added 15 commits September 29, 2025 18:15
new route that queries the database for all opportunities and returns them as a JSON list
test to ensure your new endpoint works correctly
creating a specific backend route to fetch the details of one opportunity by its ID
test verifies that the new endpoint correctly retrieves an opportunity  or handle error
Added opportunity_to_dict helper
Fix two GET endpoints for better error checks and improved data handling
created corresponding tests in test_single_opportunity_routes.py
for a smooth experience
GET /profile route to allow users to fetch their own profile data.
Added a 'user_to_dict' helper function to consistently serialize user data.
PUT /profile route for user to update their personal details.
PUT /profile route for user to update their majors and department.
GET /profile endpoint: both successful data retrieval and unauthorized access
PUT /profile endpoint: ensuring that full updates, partial updates, and unauthorized attempts are handled correctly.
ISSUE: Login helper function to streamline authentication within the tests but the tests fail as user not in DB.
@deepsource-io
Copy link

deepsource-io bot commented Oct 28, 2025

Here's the code health analysis summary for commits a047b0a..2499177. View details on DeepSource ↗.

Analysis Summary

AnalyzerStatusSummaryLink
DeepSource Python LogoPython❌ Failure
❗ 2 occurences introduced
View Check ↗

💡 If you’re a repository administrator, you can configure the quality gates from the settings.

Copy link
Member

@RafaelCenzano RafaelCenzano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good but a few things of note. Mainly I think some function calls can be removed to lower the time for a response

(nit) = nitpick - not a required change

@RafaelCenzano RafaelCenzano requested a review from Copilot November 3, 2025 03:32
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds profile management and single opportunity retrieval endpoints with comprehensive test coverage. The changes introduce new REST API routes for user profile operations and opportunity lookup functionality.

  • Adds GET and PUT endpoints for /profile with JWT authentication for user profile retrieval and updates
  • Implements single opportunity retrieval via both URL parameter (/opportunity/<id>) and JSON body (/opportunity)
  • Introduces helper functions opportunity_to_dict() and user_to_dict() for consistent serialization

Reviewed Changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
labconnect/main/profile_routes.py New module implementing profile GET/PUT endpoints with JWT authentication and user/department/major management
labconnect/main/opportunity_routes.py Adds opportunity_to_dict() helper and two new GET endpoints for single opportunity retrieval
labconnect/main/init.py Imports the new profile_routes module into the blueprint
tests/test_profile_routes.py Comprehensive tests for profile endpoints covering success cases, partial updates, and authorization
tests/test_single_opportunity_routes.py Tests for opportunity_to_dict helper and single opportunity endpoints with various error cases
README.md Updates testing documentation with command for running individual test files
.gitignore Adds virtual environment directories to ignore list

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@jaswanthDuddu
Copy link
Member Author

@RafaelCenzano made the changes from the review — lmk if you’d like any other tweaks.

Copy link
Member

@RafaelCenzano RafaelCenzano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything is looking good just have 1 comment then should be good to go

@jaswanthDuddu
Copy link
Member Author

Made the changes for the review comment, lmk any other changes needed
@RafaelCenzano @WBroadwell

@jaswanthDuddu jaswanthDuddu removed the request for review from WBroadwell November 4, 2025 00:47
Copy link
Member

@RafaelCenzano RafaelCenzano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I left a separate comment not going to hold up this PR everything is very solid but maybe make a new ticket for the future to sanitize and validate user inputs

return {"msg": "Missing JSON in request"}, 400

# Update basic User fields
user.first_name = json_data.get("first_name", user.first_name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WBroadwell not going to hold up this PR but would be good to make a ticket to validate and sanitze inputs on the frontend and backend.

Sanitization can be like this PR I have on another projects: https://github.com/alpha-phi-omega-ez/backend/pull/51/files#diff-b678c90e066bcc3eaff460004c1d8c094e9abc66acafe9226cbff14a85354882R24-R28

And validation just checkings like length limits like whats set in the database schema

@jaswanthDuddu jaswanthDuddu merged commit 3a5af97 into main Nov 4, 2025
5 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants