-
Notifications
You must be signed in to change notification settings - Fork 0
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: 구독한 구글폼 응답 최신화 및 알림 발송 #15
Open
TaeyeonRoyce
wants to merge
5
commits into
main
Choose a base branch
from
13-feat-구독한-구글폼-응답-최신화-및-알림-발송
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
The head ref may contain hidden characters: "13-feat-\uAD6C\uB3C5\uD55C-\uAD6C\uAE00\uD3FC-\uC751\uB2F5-\uCD5C\uC2E0\uD654-\uBC0F-\uC54C\uB9BC-\uBC1C\uC1A1"
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9909055
chore: Scheduler 설정
TaeyeonRoyce c062ae6
feat: 구독한 구글폼의 응답수 조회 Scheduler Job 추가
TaeyeonRoyce 54a9551
style: reformat
TaeyeonRoyce 10cc28d
style: reformat (final 키워드 추가)
TaeyeonRoyce 822f74f
chore: 사용하지 않는 내장 톰캣 비활성화
TaeyeonRoyce File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1 change: 0 additions & 1 deletion
1
src/main/java/greedy/greedybot/application/googleform/GoogleCredential.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
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
61 changes: 61 additions & 0 deletions
61
src/main/java/greedy/greedybot/application/googleform/GoogleFormResponseBatch.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,61 @@ | ||
package greedy.greedybot.application.googleform; | ||
|
||
import greedy.greedybot.domain.form.GoogleFormWatch; | ||
import greedy.greedybot.domain.form.GoogleFormWatchRepository; | ||
import java.util.List; | ||
import net.dv8tion.jda.api.JDA; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class GoogleFormResponseBatch { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(GoogleFormResponseBatch.class); | ||
|
||
private final GoogleFormWatchRepository googleFormWatchDiscordRepository; | ||
private final GoogleFormApiClient googleFormApiClient; | ||
private final GoogleCredential googleCredential; | ||
private final JDA jda; | ||
|
||
@Value("${discord.google_form_alert_channel_id}") | ||
private String googleFormAlertChannelId; | ||
|
||
public GoogleFormResponseBatch(final GoogleFormWatchRepository googleFormWatchDiscordRepository, | ||
final GoogleFormApiClient googleFormApiClient, | ||
final GoogleCredential googleCredential, | ||
final JDA jda) { | ||
this.googleFormWatchDiscordRepository = googleFormWatchDiscordRepository; | ||
this.googleFormApiClient = googleFormApiClient; | ||
this.googleCredential = googleCredential; | ||
this.jda = jda; | ||
} | ||
|
||
@Scheduled(fixedDelay = 5 * 60 * 1000) // 5분마다 실행 | ||
public void fetchGoogleFormWatchResponses() { | ||
final String accessToken = googleCredential.getAccessToken(); | ||
final List<GoogleFormWatch> googleFormWatches = googleFormWatchDiscordRepository.findAll(); | ||
for (final GoogleFormWatch googleFormWatch : googleFormWatches) { | ||
log.info("[FETCH GOOGLE FORM RESPONSES] formId: {}", googleFormWatch.targetFormId()); | ||
final String formId = googleFormWatch.targetFormId(); | ||
final int responseCount = googleFormApiClient.readFormResponseCount(formId, accessToken); | ||
|
||
if (googleFormWatch.hasNewResponse(responseCount)) { | ||
updateGoogleFormWatchResponseCount(googleFormWatch, responseCount); | ||
} | ||
} | ||
} | ||
|
||
private void updateGoogleFormWatchResponseCount(final GoogleFormWatch googleFormWatch, final int responseCount) { | ||
final int previousResponseCount = googleFormWatch.responseCount(); | ||
final GoogleFormWatch updateGoogleFormWatch = googleFormWatch.updateResponseCount(responseCount); | ||
googleFormWatchDiscordRepository.updateGoogleFormWatch(updateGoogleFormWatch); | ||
final int newResponseCount = responseCount - previousResponseCount; | ||
jda.getTextChannelById(googleFormAlertChannelId).sendMessage(""" | ||
📩 %s에 %d개의 새로운 응답이 도착했어요! 총 응답 수: %d | ||
""".formatted(updateGoogleFormWatch.targetFormTitle(), newResponseCount, responseCount) | ||
).queue(); | ||
} | ||
} |
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
9 changes: 9 additions & 0 deletions
9
src/main/java/greedy/greedybot/common/configuration/SchedulerConfiguration.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,9 @@ | ||
package greedy.greedybot.common.configuration; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.scheduling.annotation.EnableScheduling; | ||
|
||
@Configuration | ||
@EnableScheduling | ||
public class SchedulerConfiguration { | ||
} |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,9 @@ spring: | |
application: | ||
name: greedy-bot | ||
|
||
main: | ||
web-application-type: none | ||
|
||
profiles: | ||
active: discord | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이것은 웹 서버 없이 spring을 실행 하는 조건 같은데

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
네, 처음에도 web 의존서 없이 사용하다가 restClient를 위해 추가했었는데요.
DiscordBot은 소켓으로 연결해서 사용 되지 않는내장 톰캣을 띄우는게 비효율적이라 생각했습니다!