Skip to content

Commit

Permalink
Merge pull request #277 from MOONSHOT-Team/feature/#276
Browse files Browse the repository at this point in the history
[Feat] #276 - 디스코드 회원가입 알림에 누적회원수 추가
  • Loading branch information
0lynny authored May 29, 2024
2 parents ade991d + 5993eb1 commit c9a3c11
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.RequiredArgsConstructor;
import org.moonshot.discord.SignUpEvent;
import org.moonshot.user.model.User;
import org.moonshot.user.repository.UserRepository;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
Expand All @@ -14,12 +15,15 @@
@RequiredArgsConstructor
public class UserSignUpService {

private final UserRepository userRepository;
private final ApplicationEventPublisher eventPublisher;

@Async
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void publishSignUpEvent(User user) {
Long totalUserCount = userRepository.count();
eventPublisher.publishEvent(SignUpEvent.of(
totalUserCount,
user.getName(),
user.getEmail() == null ? "" : user.getEmail(),
user.getSocialPlatform().toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
public interface UserJpaRepository extends JpaRepository<User, Long> {

Optional<User> findUserBySocialId(String socialId);
Optional<User> findUserByNickname(String nickname);
@Query("SELECT u FROM User u WHERE u.deleteAt < :currentDate")
List<User> findIdByDeletedAtBefore(LocalDateTime currentDate);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ protected void append(ILoggingEvent eventObject) {
}
}

public void signInAppend(String name, String email, String socialPlatform, LocalDateTime createdAt, String imgUrl){
public void signInAppend(Long totalUserCount, String name, String email, String socialPlatform, LocalDateTime createdAt, String imgUrl){
DiscordWebHook discordWebhook = new DiscordWebHook(DiscordConstants.signInWebhookUrl, username, avatarUrl, false);

discordWebhook.addEmbed(new EmbedObject()
.setTitle("🚀[회원 가입] 새로운 유저가 가입하였습니다.🚀")
.setTitle("🚀[회원 가입] " + totalUserCount + "번쨰 유저가 가입하였습니다.🚀")
.setColor(Color.CYAN)
.setDescription("moonshot에 새로운 유저가 가입하였습니다.")
.setThumbnail(imgUrl)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

import java.time.LocalDateTime;

public record SignUpEvent(String name, String email, String socialPlatform, LocalDateTime createdAt, String imageUrl) {
public record SignUpEvent(Long totalUserCount, String name, String email, String socialPlatform, LocalDateTime createdAt, String imageUrl) {

public static SignUpEvent of(String name, String email, String socialPlatform, LocalDateTime createdAt,
public static SignUpEvent of(Long totalUserCount, String name, String email, String socialPlatform, LocalDateTime createdAt,
String imageUrl) {
return new SignUpEvent(name, email, socialPlatform, createdAt, imageUrl);
return new SignUpEvent(totalUserCount, name, email, socialPlatform, createdAt, imageUrl);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class SignUpEventListener {
@EventListener
public void handleSignUpEvent(SignUpEvent event) {
discordAppender.signInAppend(
event.totalUserCount(),
event.name(),
event.email(),
event.socialPlatform(),
Expand Down

0 comments on commit c9a3c11

Please sign in to comment.