fix find groups for user and add vote deletion when user removed from…#94
Conversation
Reviewer's GuideThis PR refactors group membership retrieval by replacing and renaming the repository query, implements automatic deletion of a user’s votes when they’re removed from a group (including service wiring and tests), and applies minor formatting cleanups. Sequence diagram for user removal from group and vote deletionsequenceDiagram
participant Admin as actor Admin/User
participant GroupService
participant GroupMembershipService
participant VoteRepository
participant GroupMembershipRepository
Admin->>GroupService: removeMemberFromGroup(groupId, userId, currentUser)
GroupService->>GroupMembershipService: removeMemberFromGroup(groupId, userId, currentUser)
GroupMembershipService->>VoteRepository: deleteUserVotesInGroup(groupId, userId)
VoteRepository-->>GroupMembershipService: (votes deleted)
GroupMembershipService->>GroupMembershipRepository: delete(membership)
GroupMembershipRepository-->>GroupMembershipService: (membership deleted)
GroupMembershipService-->>GroupService: (done)
GroupService-->>Admin: (done)
Class diagram for updated GroupRepository and VoteRepositoryclassDiagram
class GroupRepository {
+Page<Group> findGroupsByUserMembership(Long userId, Pageable pageable)
}
class VoteRepository {
+void deleteUserVotesInGroup(Long groupId, Long userId)
}
Class diagram for updated GroupMembershipServiceclassDiagram
class GroupMembershipService {
+GroupMembershipResponse addMemberToGroup(Long groupId, Long userId, GroupRole role, User currentUser)
+void removeMemberFromGroup(Long groupId, Long userId, User currentUser)
-VoteRepository voteRepository
}
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey @szymongrabski - I've reviewed your changes and they look great!
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Code Coverage
|
There was a problem hiding this comment.
Summary of Changes
Hello @szymongrabski, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request addresses an issue with group retrieval for users and introduces vote deletion when a user is removed from a group. The changes ensure that group memberships are accurately reflected and that orphaned votes are cleaned up when a user leaves a group, maintaining data integrity.
Highlights
- Group Retrieval: Modified the
GroupRepositoryto more accurately find groups a user is a member of by adjusting the query to only check for membership viaGroupMembershipentries. - Vote Deletion: Implemented a mechanism to delete a user's votes within a group when the user is removed from that group. This ensures data consistency and prevents orphaned votes.
- Transactional Management: Added
@Transactionalannotation toremoveMemberFromGroupmethod inGroupMembershipServiceto ensure atomicity of operations.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Code Review
This pull request addresses finding groups for a user and adds vote deletion upon user removal. It includes repository, service, and test updates. Consider using Spring's @Transactional and verifying vote deletion in tests. Also, there's a suggestion to remove the trailing comma from the NotificationType enum.
| @@ -1,5 +1,6 @@ | |||
| package share.fare.backend.service; | |||
|
|
|||
| import jakarta.transaction.Transactional; | |||
There was a problem hiding this comment.
Consider using org.springframework.transaction.annotation.Transactional instead of jakarta.transaction.Transactional for better consistency with Spring framework-specific features.
| import jakarta.transaction.Transactional; | |
| import org.springframework.transaction.annotation.Transactional; |
| when(groupMembershipRepository.findByGroupAndUser(testGroup, testUser2)).thenReturn(Optional.ofNullable(testMembership)); | ||
| doNothing().when(groupMembershipRepository).delete(testMembership); | ||
|
|
||
| doNothing().when(voteRepository).deleteUserVotesInGroup(1L, 2L); |
There was a problem hiding this comment.
Code Coverage
|
… group
Summary by Sourcery
Fix group query to fetch only user-associated groups, add automatic vote cleanup when removing a member, and update related repository methods and tests.
New Features:
Enhancements:
Tests:
Chores: