-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #236 from ssu-student-union/feat/232-discord-webho…
…ok-signup [feat] #232 디스코드 웹훅, 봇 사용자수 알림
- Loading branch information
Showing
8 changed files
with
186 additions
and
0 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
src/main/java/ussum/homepage/application/notification/service/DiscordWebhookScheduler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package ussum.homepage.application.notification.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class DiscordWebhookScheduler { | ||
private final DiscordWebhookService discordWebhookService; | ||
|
||
@Scheduled(cron = "0 0 0 * * ?") | ||
public void sendUserStatisticsPeriodically() { | ||
discordWebhookService.sendToDiscord(); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/ussum/homepage/application/notification/service/DiscordWebhookService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package ussum.homepage.application.notification.service; | ||
|
||
import lombok.*; | ||
import org.springframework.http.*; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.web.client.RestTemplate; | ||
import ussum.homepage.application.user.service.UserService; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class DiscordWebhookService { | ||
private final UserService userService; | ||
private final RestTemplate restTemplate = new RestTemplate(); | ||
|
||
private final String DISCORD_WEBHOOK_URL = "https://discord.com/api/webhooks/1345355644236075018/ZMpO9d7Jh30jvSKf5U3gw9i9xoczFAX9f6DLN8YadBYBZDM9WxRpSr-kz1KyQbniikQA"; // 🔥 여기에 실제 웹훅 URL을 입력하세요 | ||
|
||
|
||
public void sendToDiscord() { | ||
try { | ||
String jsonMessage = userService.generateDiscordMessage(); | ||
|
||
HttpHeaders headers = new HttpHeaders(); | ||
headers.setContentType(MediaType.APPLICATION_JSON); | ||
|
||
HttpEntity<String> requestEntity = new HttpEntity<>(jsonMessage, headers); | ||
|
||
ResponseEntity<String> response = restTemplate.exchange( | ||
DISCORD_WEBHOOK_URL, HttpMethod.POST, requestEntity, String.class); | ||
|
||
} catch (Exception e) { | ||
// 디스코드로 웹훅으로 인해 앱이 죽지 않게 따로 처리하지 않음. | ||
System.err.println("디스코드 웹훅 전송 실패: " + e.getMessage()); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/main/java/ussum/homepage/domain/user/MonthlySignupStats.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package ussum.homepage.domain.user; | ||
|
||
import lombok.*; | ||
|
||
/// TODO(inho): DDD 구조에 맞게 다시 리팩토링 해야함 | ||
@Getter | ||
@AllArgsConstructor | ||
public class MonthlySignupStats { | ||
private int year; | ||
private int month; | ||
private Long count; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/java/ussum/homepage/domain/user/service/UserAnalyzer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package ussum.homepage.domain.user.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import ussum.homepage.domain.user.MonthlySignupStats; | ||
import ussum.homepage.domain.user.UserRepository; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class UserAnalyzer { | ||
private final UserRepository userRepository; | ||
|
||
public Long getTotalUserCount() { | ||
return userRepository.findTotalUserCount(); | ||
} | ||
|
||
public Long getNewUserCountBetween(LocalDateTime start, LocalDateTime end) { | ||
return userRepository.findNewUserCountBetween(start, end); | ||
} | ||
|
||
public List<MonthlySignupStats> getMonthlySignupStats(int year) { | ||
return userRepository.findMonthlySignupStats(year); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters