-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
CommunityLinkPersonCommunityCreatedListener.java
30 lines (25 loc) · 1.27 KB
/
CommunityLinkPersonCommunityCreatedListener.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.LinkPersonCommunityCreatedEvent;
import lombok.RequiredArgsConstructor;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
@Component
@RequiredArgsConstructor
public class CommunityLinkPersonCommunityCreatedListener implements
ApplicationListener<LinkPersonCommunityCreatedEvent> {
private final CommunityAggregateRepository communityAggregateRepository;
@Override
@Transactional
public void onApplicationEvent(LinkPersonCommunityCreatedEvent event) {
if (event.getLinkPersonCommunity().getLinkType() == LinkPersonCommunityType.follower) {
final CommunityAggregate communityAggregate = event.getLinkPersonCommunity().getCommunity()
.getCommunityAggregate();
communityAggregate.setSubscriberCount(communityAggregate.getSubscriberCount() + 1);
communityAggregateRepository.save(communityAggregate);
}
}
}