Skip to content
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

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

ChernenkoVitaliy
Copy link
Contributor

@ChernenkoVitaliy ChernenkoVitaliy commented Jan 29, 2025

GreenCity PR

Issue Link 📋

#6020

Added

  • Added field with a set of friends into CustomHabitDtoRequest;
  • Added functionality for inviting friends during creating a custom habit into HabitServiceImpl;
  • Added necessary test in HabitServiceImplTest and refactored according to changes in HabitServiceImpl;

Changed

  • Refactored creating CustomHabitDtoRequest in ModelUtils according to change in CustomHabitDtoRequest;

Summary Of Changes 🔥

Fixed functionality for inviting friends to join custom habits during its creation

Summary by CodeRabbit

Release Notes

  • New Features

    • Added ability to invite friends when creating a custom habit
    • Enhanced habit creation workflow to support friend invitations
  • Improvements

    • Streamlined habit translation handling
    • Updated test coverage for new habit invitation functionality
  • Technical Updates

    • Refined service layer to support friend invitation process during habit creation

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;
Copy link

coderabbitai bot commented Jan 29, 2025

Walkthrough

The pull request introduces a new feature for inviting friends to custom habits within the GreenCity application. The changes primarily focus on enhancing the CustomHabitDtoRequest by adding a friendsToInvite field, updating the HabitServiceImpl to handle friend invitations, and modifying the corresponding test suite to verify the new functionality. The implementation allows users to invite friends when creating a custom habit, with support for email notifications and locale-specific interactions.

Changes

File Change Summary
service-api/.../CustomHabitDtoRequest.java Added friendsToInvite field of type Set<UserFriendDto>
service/.../HabitServiceImpl.java - Added inviteFriendsToJoinHabit method
- Modified habit translation saving logic
service/test/.../ModelUtils.java Added friendsToInvite to test model setup
service/test/.../HabitServiceImplTest.java - Added addCustomHabitWithInvitedFriendsTest
- Updated existing test method verifications

Sequence Diagram

sequenceDiagram
    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
Loading

Poem

🌱 Habits grow, friends unite,
A green city's shared delight!
Invites sent with gentle care,
Connecting souls everywhere,
One habit at a time, so bright! 🌍

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a 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 each UserFriendDto 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:

  1. Validation to ensure friends exist and are actually friends with the user
  2. Error handling for failed invitations
  3. 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:

  1. Empty friends set
  2. Invalid friend IDs
  3. Maximum friends limit
  4. 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

📥 Commits

Reviewing files that changed from the base of the PR and between aeebe5a and 78a42eb.

📒 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants