-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
CommunityLinkPersonCommunityDeletedListener.java
30 lines (25 loc) · 1.27 KB
/
CommunityLinkPersonCommunityDeletedListener.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package com.sublinks.sublinksapi.community.listeners;
import com.sublinks.sublinksapi.community.entities.CommunityAggregate;
import com.sublinks.sublinksapi.community.repositories.CommunityAggregateRepository;
import com.sublinks.sublinksapi.person.enums.LinkPersonCommunityType;
import com.sublinks.sublinksapi.person.events.LinkPersonCommunityDeletedEvent;
import lombok.RequiredArgsConstructor;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
@Component
@RequiredArgsConstructor
public class CommunityLinkPersonCommunityDeletedListener implements
ApplicationListener<LinkPersonCommunityDeletedEvent> {
private final CommunityAggregateRepository communityAggregateRepository;
@Override
@Transactional
public void onApplicationEvent(LinkPersonCommunityDeletedEvent event) {
if (event.getLinkPersonCommunity().getLinkType() == LinkPersonCommunityType.follower) {
final CommunityAggregate communityAggregate = event.getLinkPersonCommunity().getCommunity()
.getCommunityAggregate();
communityAggregate.setSubscriberCount(communityAggregate.getSubscriberCount() - 1);
communityAggregateRepository.save(communityAggregate);
}
}
}