Skip to content

Connect routing logic with user preferences (requires authentication)#43

Merged
zlendo1 merged 3 commits into
developmentfrom
copilot/connect-routing-with-preferences
Oct 30, 2025
Merged

Connect routing logic with user preferences (requires authentication)#43
zlendo1 merged 3 commits into
developmentfrom
copilot/connect-routing-with-preferences

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 30, 2025

Enable AI-generated route insights to incorporate user preferences from both request payload and stored user settings. The /routes/search endpoint now requires authentication.

Changes

Schema

  • Added optional preferences: List[str] field to RouteSearchRequest

Endpoint (/routes/search)

  • Requires authentication - only authenticated users can access the endpoint
  • Collect preferences from two sources:
    1. Request body (explicit preferences)
    2. Stored user preferences (from authenticated user)
  • Pass combined list to AI service with graceful degradation on preference fetch failure

AI Service

  • Updated get_itinerary_insight(itinerary, user_preferences=None) to accept optional preferences
  • Include user_preferences in payload to /api/v1/insight/itinerary when provided

Example Usage

# Authenticated request with explicit preferences
POST /api/v1/routes/search
Authorization: Bearer <token>
{
  "origin": {"latitude": 60.17, "longitude": 24.94},
  "destination": {"latitude": 60.21, "longitude": 24.66},
  "preferences": ["prefer walking", "avoid crowded buses"]
}

# Authenticated request - merges stored preferences with request preferences
POST /api/v1/routes/search
Authorization: Bearer <token>
{
  "origin": {...},
  "destination": {...},
  "preferences": ["prefer trams"]  # Combined with stored: ["avoid buses", "eco-friendly"]
}

AI agents receive:

{
  "duration": 2700,
  "legs": [...],
  "user_preferences": ["prefer trams", "avoid buses", "eco-friendly"]
}

Note: Unauthenticated requests will receive a 401 Unauthorized response.

Original prompt

This section details on the original issue you should resolve

<issue_title>Connect the routing logic with the preferences</issue_title>
<issue_description>- search endpoint sends user preferences to AI service

  • Returning object from get_itinerary_insight stays the same
  • Insight enhancement business logic handled by backend
    • Interface change with insight/itinerary is that it can now take in user preferences
  • Write tests to cover new feature</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

- Add optional preferences field to RouteSearchRequest schema
- Update search endpoint to accept optional user authentication
- Retrieve stored user preferences for authenticated users
- Pass combined preferences (request + stored) to AI service
- Update AI service to accept and send user_preferences in payload
- Add comprehensive tests for preference integration
- All tests pass (91 tests)
- Code passes linting and formatting checks

Co-authored-by: zlendo1 <115471708+zlendo1@users.noreply.github.com>
Copilot AI changed the title [WIP] Connect routing logic with user preferences Connect routing logic with user preferences Oct 30, 2025
Copilot AI requested a review from zlendo1 October 30, 2025 11:47
@zlendo1
Copy link
Copy Markdown
Contributor

zlendo1 commented Oct 30, 2025

@copilot Make sure that search endpoint can only be reached by an existing current user (disallow unauthorized access).

- Changed endpoint to require authentication using get_current_user
- Updated all tests to provide authentication headers
- Removed unused imports
- All 91 tests pass
- Code passes linting and formatting checks

Co-authored-by: zlendo1 <115471708+zlendo1@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Oct 30, 2025

@copilot Make sure that search endpoint can only be reached by an existing current user (disallow unauthorized access).

Updated the /routes/search endpoint to require authentication. The endpoint now uses get_current_user instead of the optional authentication, so unauthorized access is disallowed.

All tests have been updated to provide authentication and all 91 tests pass successfully.

Commit: 10936c5

Copilot AI changed the title Connect routing logic with user preferences Connect routing logic with user preferences (requires authentication) Oct 30, 2025
@zlendo1 zlendo1 marked this pull request as ready for review October 30, 2025 12:13
@zlendo1 zlendo1 merged commit 79d6bac into development Oct 30, 2025
2 checks passed
@zlendo1 zlendo1 deleted the copilot/connect-routing-with-preferences branch October 30, 2025 12:14
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.

2 participants