File tree 1 file changed +10
-6
lines changed
src/main/java/com/thisaster/testtask/user/service
1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -52,16 +52,20 @@ public User updateUser(Long userId, User user) {
52
52
}
53
53
existingUser .setRole (roleService .getByRoleId (user .getRoleId ()));
54
54
55
- Set <Subscription > updatedSubscriptions = new HashSet <>();
55
+
56
+ Set <Subscription > currentSubscriptions = new HashSet <>(existingUser .getSubscriptions ());
56
57
if (user .getSubscriptions () != null ) {
57
- for (Subscription subscription : user .getSubscriptions ()) {
58
- subscribeUserToSub (userId , subscription );
59
- subscriptionRepository .findByName (subscription .getName ())
60
- .ifPresent (updatedSubscriptions ::add );
58
+ for (Subscription newSub : user .getSubscriptions ()) {
59
+ boolean alreadySubscribed = currentSubscriptions .stream ()
60
+ .anyMatch (existingSub -> existingSub .getName ().equals (newSub .getName ()));
61
+
62
+ if (!alreadySubscribed ) {
63
+ subscribeUserToSub (userId , newSub );
64
+ }
61
65
}
62
66
}
63
67
64
- Set <Subscription > currentSubscriptions = new HashSet <>( existingUser .getSubscriptions () );
68
+ Set <Subscription > updatedSubscriptions = existingUser .getSubscriptions ();
65
69
for (Subscription currentSub : currentSubscriptions ) {
66
70
if (!updatedSubscriptions .contains (currentSub )) {
67
71
removeSubFromUser (userId , currentSub .getId ());
You can’t perform that action at this time.
0 commit comments