Add getDevicesByUserId() method to fetch registered devices#300
Add getDevicesByUserId() method to fetch registered devices#300raviendalpatadu wants to merge 3 commits into
Conversation
…egistered to userId
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughSummaryThis pull request enhances device management functionality by introducing a new method for retrieving all devices registered to a user. Key ChangesNew
Helper Method Addition: A new private Deprecation of Existing Method: The existing single-device Service Implementation Update: The ImpactThese changes improve the API's capability to handle multi-device scenarios while enhancing code maintainability through better separation of concerns and centralized DTO conversion logic. WalkthroughThe PR replaces the single-device retrieval method 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
components/org.wso2.carbon.identity.api.user.push/org.wso2.carbon.identity.rest.api.user.push.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/push/v1/core/PushDeviceManagementService.java (1)
234-246: ⚡ Quick winReuse the existing single-device mapper to avoid duplicated mapping logic.
Line 238-Line 243 duplicates
buildDeviceDTO(Device). Reusing the existing helper keeps mapping behavior consistent and reduces drift risk.Proposed refactor
private List<DeviceDTO> buildListDeviceDTO(List<Device> deviceList) { List<DeviceDTO> deviceDTOList = new ArrayList<>(); for (Device device : deviceList) { - DeviceDTO deviceDTO = new DeviceDTO(); - deviceDTO.setDeviceId(device.getDeviceId()); - deviceDTO.setName(device.getDeviceName()); - deviceDTO.setModel(device.getDeviceModel()); - deviceDTO.setProvider(device.getProvider()); - deviceDTOList.add(deviceDTO); + deviceDTOList.add(buildDeviceDTO(device)); } return deviceDTOList; }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@components/org.wso2.carbon.identity.api.user.push/org.wso2.carbon.identity.rest.api.user.push.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/push/v1/core/PushDeviceManagementService.java` around lines 234 - 246, The buildListDeviceDTO method is duplicating device mapping logic that already exists in the buildDeviceDTO(Device) method. Replace the manual field assignments (setDeviceId, setName, setModel, setProvider) inside the for loop with a call to the existing buildDeviceDTO method for each Device in the deviceList, capturing its result and adding it to the deviceDTOList. This eliminates code duplication and ensures consistent mapping behavior across both methods.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In
`@components/org.wso2.carbon.identity.api.user.push/org.wso2.carbon.identity.rest.api.user.push.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/push/v1/core/PushDeviceManagementService.java`:
- Around line 234-246: The buildListDeviceDTO method is duplicating device
mapping logic that already exists in the buildDeviceDTO(Device) method. Replace
the manual field assignments (setDeviceId, setName, setModel, setProvider)
inside the for loop with a call to the existing buildDeviceDTO method for each
Device in the deviceList, capturing its result and adding it to the
deviceDTOList. This eliminates code duplication and ensures consistent mapping
behavior across both methods.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 08f864dd-778e-4ee2-90e1-c4787b5c01d6
📒 Files selected for processing (2)
components/org.wso2.carbon.identity.api.user.push/org.wso2.carbon.identity.rest.api.user.push.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/push/v1/core/PushDeviceManagementService.javacomponents/org.wso2.carbon.identity.api.user.push/org.wso2.carbon.identity.rest.api.user.push.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/push/v1/impl/DevicesApiServiceImpl.java
fc241bf to
2b49aa0
Compare
This pull request adds a new method to retrieve devices by user ID and refactors the code to use this new method, improving clarity and maintainability. It also introduces a helper method to build lists of device DTOs from model objects.
Device retrieval improvements:
getDevicesByUserIdmethod inPushDeviceManagementServiceto fetch all devices for the current user, with improved error handling for cases where no devices are found.DevicesApiServiceImplto use the newgetDevicesByUserIdmethod instead of the old one, ensuring consistency and leveraging the improved logic.Code modularization:
buildListDeviceDTOinPushDeviceManagementServiceto convert a list ofDeviceobjects into a list ofDeviceDTOobjects, reducing code duplication and improving readability.Related Issues