-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bugfix #6020 - Fixed functionality for inviting friends to join custom habits during its creation #8078
base: dev
Are you sure you want to change the base?
Bugfix #6020 - Fixed functionality for inviting friends to join custom habits during its creation #8078
Conversation
Added functionality for inviting friends during creating custom habit into HabitServiceImpl; Added necessary test in HabitServiceImplTest and refactoret according to changes in HabitServiceImpl; Refactored creating CustomHabitDtoRequest in ModelUtils according to change in CustomHabitDtoRequest;
WalkthroughThe pull request introduces a new feature for inviting friends to custom habits within the GreenCity application. The changes primarily focus on enhancing the Changes
Sequence DiagramsequenceDiagram
participant User
participant HabitService
participant HabitAssignService
participant Friend
User->>HabitService: Create Custom Habit
HabitService->>HabitService: Save Habit
alt Friends to Invite
HabitService->>HabitAssignService: Invite Friends
HabitAssignService->>Friend: Send Email Notification
end
Poem
✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
service-api/src/main/java/greencity/dto/habit/CustomHabitDtoRequest.java (1)
44-44
: Consider adding validation annotations for the friendsToInvite field.While the implementation is correct, consider adding validation annotations to ensure data integrity:
@Valid
to validate eachUserFriendDto
in the set@Size(max=...)
to limit the number of friends that can be invited at once- private Set<UserFriendDto> friendsToInvite = new HashSet<>(); + @Valid + @Size(max = 100, message = "Cannot invite more than {max} friends at once") + private Set<UserFriendDto> friendsToInvite = new HashSet<>();service/src/main/java/greencity/service/HabitServiceImpl.java (1)
541-550
: Consider adding error handling for friend invitations.While the implementation is correct, consider adding:
- Validation to ensure friends exist and are actually friends with the user
- Error handling for failed invitations
- Batch size limit for invitations
private void inviteFriendsToJoinHabit(CustomHabitDtoRequest addCustomHabitDtoRequest, User user, Habit habit) { if (!addCustomHabitDtoRequest.getFriendsToInvite().isEmpty()) { + if (addCustomHabitDtoRequest.getFriendsToInvite().size() > 100) { + throw new BadRequestException("Cannot invite more than 100 friends at once"); + } List<Long> friendsIds = addCustomHabitDtoRequest.getFriendsToInvite().stream() .map(UserFriendDto::getId) .collect(Collectors.toList()); + // Verify these are actual friends + if (!friendService.areAllFriends(user.getId(), friendsIds)) { + throw new BadRequestException("Some users are not in your friends list"); + } habitAssignService.inviteFriendForYourHabitWithEmailNotification( modelMapper.map(user, UserVO.class), friendsIds, habit.getId(), Locale.of(user.getLanguage().getCode())); } }service/src/test/java/greencity/service/HabitServiceImplTest.java (1)
820-892
: Consider adding more test cases for friend invitations.The test provides good coverage but consider adding these scenarios:
- Empty friends set
- Invalid friend IDs
- Maximum friends limit
- Failed invitation handling
Example test case:
@Test void addCustomHabitWithTooManyFriendsTest() { CustomHabitDtoRequest request = ModelUtils.getAddCustomHabitDtoRequestForServiceTest(); Set<UserFriendDto> tooManyFriends = IntStream.range(0, 101) .mapToObj(i -> ModelUtils.getUserFriendDto().setId((long) i)) .collect(Collectors.toSet()); request.setFriendsToInvite(tooManyFriends); assertThrows(BadRequestException.class, () -> habitService.addCustomHabit(request, null, "[email protected]")); }
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
service-api/src/main/java/greencity/dto/habit/CustomHabitDtoRequest.java
(3 hunks)service/src/main/java/greencity/service/HabitServiceImpl.java
(5 hunks)service/src/test/java/greencity/ModelUtils.java
(1 hunks)service/src/test/java/greencity/service/HabitServiceImplTest.java
(6 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: build
🔇 Additional comments (4)
service-api/src/main/java/greencity/dto/habit/CustomHabitDtoRequest.java (1)
4-4
: LGTM! Import added for the new field.The import statement for
UserFriendDto
is correctly added to support the new friends invitation feature.service/src/main/java/greencity/service/HabitServiceImpl.java (2)
8-8
: LGTM! Required imports added.The new imports support the friend invitation feature and stream operations.
Also applies to: 49-49, 53-53
516-518
: LGTM! Efficient translation handling.The implementation efficiently combines translations using Stream.concat and sets them directly on the habit entity.
service/src/test/java/greencity/ModelUtils.java (1)
2637-2637
: Well-structured addition of friends invitation support!Good choice using HashSet for the
friendsToInvite
field as it prevents duplicate invitations and provides efficient operations.
Quality Gate passedIssues Measures |
GreenCity PR
Issue Link 📋
#6020
Added
CustomHabitDtoRequest
;HabitServiceImpl
;HabitServiceImplTest
and refactored according to changes inHabitServiceImpl
;Changed
CustomHabitDtoRequest
inModelUtils
according to change inCustomHabitDtoRequest
;Summary Of Changes 🔥
Fixed functionality for inviting friends to join custom habits during its creation
Summary by CodeRabbit
Release Notes
New Features
Improvements
Technical Updates