3.9 KiB
3.9 KiB
TODO: Allow Users to Join Cooperatives via User Settings
Overview
Implement functionality to allow users to join cooperatives stored in the user's settings JSON field, with a dedicated composable and controller for managing user additional details and enabling quick search of users by cooperative membership.
Step 1: Database Schema Update
- Verify that
settingsfield inuserstable is already JSON type (already exists and cast as array) - No migration needed -
settingsfield already supports array data
Step 2: Create UserAdditionalDetailsController
- Create
app/Http/Controllers/UserManagement/UserAdditionalDetailsController.php - Implement
getDetails()method - Retrieve user's additional details including cooperatives - Implement
updateCooperatives()method - Add/remove cooperatives from user settings - Implement
searchUsersByCooperative()method - Quick search for users by cooperative hashkey - Implement
getUserCooperatives()method - Get all cooperatives a user has joined - Use ResponseHelper for consistent API responses
- Add proper authorization checks using UserPermissions
Step 3: Create useUserAdditionalDetails Composable
- Create
resources/js/composables/useUserAdditionalDetails.js - Implement
fetchUserDetails()- Fetch current user's additional details - Implement
joinCooperative(cooperativeHash)- Add cooperative to user's settings - Implement
leaveCooperative(cooperativeHash)- Remove cooperative from user's settings - Implement
getJoinedCooperatives()- Get list of cooperatives user has joined - Implement
searchUsersByCooperative(cooperativeHash)- Search users by cooperative - Add loading states and error handling
- Follow existing composable patterns (useUserSettings.js as reference)
Step 4: Register Routes
- Add routes in
routes/api.phpor appropriate route file:POST /UserAdditionalDetails/Get- Get user detailsPOST /UserAdditionalDetails/UpdateCooperatives- Update cooperatives in settingsPOST /UserAdditionalDetails/SearchByCooperative- Search users by cooperativePOST /UserAdditionalDetails/GetCooperatives- Get user's cooperatives
Step 5: Update User Model (if needed)
- Verify
settingsfield is in$fillablearray (already present) - Verify
settingsfield is cast asarray(already present) - Add helper method
getCooperativesAttribute()to easily access cooperatives from settings - Add helper method
hasJoinedCooperative($cooperativeHash)to check membership
Step 6: Integration with Existing Cooperative System
- Ensure compatibility with existing
CooperativeController::joinCooperative() - When user joins via CooperativeController, also update user settings
- Maintain consistency between
cooperative_memberstable and user settings
Step 7: Testing & Validation
- Test joining a cooperative updates user settings correctly
- Test leaving a cooperative removes from user settings
- Test quick search returns correct users by cooperative
- Test authorization and permission checks
- Test edge cases (duplicate joins, non-existent cooperatives)
Files to Create/Modify
- NEW:
app/Http/Controllers/UserManagement/UserAdditionalDetailsController.php - NEW:
resources/js/composables/useUserAdditionalDetails.js - MODIFY:
routes/api.php(or appropriate route file) - MODIFY:
app/Models/User.php(add helper methods) - MODIFY:
app/Http/Controllers/Market/CooperativeController.php(sync with settings)
Technical Notes
- Cooperatives will be stored in
settings.cooperativesas an array of hashkeys - Example structure:
settings: { cooperatives: ['hash1', 'hash2', ...] } - Quick search should use JSON query to find users with specific cooperative in settings
- Follow existing patterns from
useUserSettings.jsandCooperativeController.php