Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] #276 - 디스코드 회원가입 알림에 누적회원수 추가 #277

Merged
merged 3 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading