Skip to content

Feat/test#25

Merged
Baptiste-Ferrand merged 2 commits into
developfrom
feat/test
Aug 6, 2025
Merged

Feat/test#25
Baptiste-Ferrand merged 2 commits into
developfrom
feat/test

Conversation

@Baptiste-Ferrand
Copy link
Copy Markdown
Contributor

#changelog

📋 Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog,
and this project adheres to Semantic Versioning.


[Unreleased]

✨ Added

🏋️‍♂️ New Coach Discovery Endpoint

  • 🎯 New API Endpoint: GET /groups/coachs/mine
    • Allows authenticated users to retrieve all coaches from groups they are members of
    • Returns coach profiles in CoachProfileRead format
    • Requires user authentication via Bearer token
    • Returns 200 with coach list on success
    • Returns 404 when no coaches are found

🔧 Backend Infrastructure Improvements

📦 Repository Layer
  • Enhanced Group Repository Interface (GroupRepository)

    • 🆕 Added find_groups_by_member_id(user_id: UUID) method signature
  • SQLAlchemy Repository Implementation (SqlAlchemyGroupRepository)

    • ✅ Implemented find_groups_by_member_id() using JOIN with group_users association table
    • 🔍 Efficient database query to find all groups where a user is a member
  • In-Memory Repository Implementation (InMemoryGroupRepository)

    • ✅ Implemented find_groups_by_member_id() for testing purposes
    • 🧪 Maintains consistency between SQLAlchemy and in-memory implementations
🎯 Service Layer
  • Group Service Enhancement (GroupService)
    • 🆕 Added get_my_coaches(user_id: UUID) method
    • 🔄 Fetches groups where user is a member
    • 👥 Collects unique coach (owner) profiles from these groups
    • 🛡️ Filters to only include users with "coach" role
    • ❌ Throws NotFoundError when no groups or coaches are found
    • 🎯 Returns list of coach profiles
🌐 API Router Updates
  • Group Router (group.py)
    • 🆕 Added /coachs/mine endpoint handler
    • 📥 Imports CoachProfileRead schema for response serialization
    • 🔐 Protected with get_current_user dependency
    • 🚨 Proper error handling with HTTP 404 for NotFoundError

🧪 Comprehensive Test Suite

📝 Test Coverage Added
  • ✅ Test 31: User successfully retrieves their coaches (200)

    • 👤 User is member of a group → receives coach profile
    • ✔️ Validates response structure and coach information
  • ❌ Test 32: Admin with no group membership gets 404

    • 🔒 Admin not member of any group → receives 404 error
  • ❌ Test 33: User leaves group then tries to get coaches (404)

    • 📤 User leaves group → no longer has coaches → receives 404
  • 👥 Test 34-37: Multiple coaches scenario

    • 🏗️ Creates second coach and group
    • 👥 User joins multiple groups with different coaches
    • ✔️ Validates user receives all unique coaches
🏗️ Test Setup & Teardown
  • 🔧 Test 29-30: Setup new group and user membership
  • 👨‍🏫 Test 34-36: Multi-coach scenario setup
  • 🧹 Test 38: Cleanup - user leaves all groups

📊 Error Handling Improvements

  • Consistent 404 Responses
    • 🚫 No groups found for user
    • 🚫 No coaches found in user's groups
    • 📝 Descriptive error messages for debugging

🔄 Business Logic Enhancements

  • Coach Uniqueness: Each coach appears only once even if they own multiple groups
  • Role Validation: Only users with "coach" role are returned
  • Membership Validation: Only active group memberships are considered

🛠️ Technical Details

Database Changes

  • No schema changes required ✅
  • Utilizes existing group_users association table
  • Leverages existing role system

Dependencies

  • Reuses existing authentication system
  • Utilizes existing CoachProfileRead schema
  • No new external dependencies

Performance Considerations

  • 🚀 Efficient JOIN query in SQLAlchemy implementation
  • 🎯 Uses set for unique coach collection
  • 💾 Minimal database queries through service layer optimization

🧪 Testing

All new functionality is covered by comprehensive tests:

  • 9 new test cases added
  • Success scenarios (200 responses)
  • Error scenarios (404 responses)
  • Edge cases (multiple coaches, leaving groups)
  • Setup/teardown scenarios

🔧 Backward Compatibility

  • Fully backward compatible
  • ✅ No breaking changes to existing APIs
  • ✅ Existing functionality unchanged
  • ✅ In-memory repository maintains test compatibility

🎉 Impact: This feature enables users to easily discover and connect with their coaches, improving the user experience and facilitating better coach-member relationships within the platform.

@Baptiste-Ferrand Baptiste-Ferrand self-assigned this Aug 6, 2025
@Baptiste-Ferrand Baptiste-Ferrand merged commit 91e44bd into develop Aug 6, 2025
2 checks passed
@Baptiste-Ferrand Baptiste-Ferrand deleted the feat/test branch August 7, 2025 09:47
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.

1 participant