Skip to content

Commit

Permalink
fix : test Dependency injection
Browse files Browse the repository at this point in the history
  • Loading branch information
MoonSangWon committed Oct 22, 2023
1 parent aae6c75 commit fd6b314
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 47 deletions.
1 change: 1 addition & 0 deletions src/main/java/mega/waka/ServerApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public String getToken() {
}
}*/
public void startBot() {
sevenDaysWakaService.update_SevenDays();
JDA jda = JDABuilder.createDefault(token)
.setActivity(Activity.playing("코딩"))
.enableIntents(GatewayIntent.MESSAGE_CONTENT)
Expand Down
47 changes: 0 additions & 47 deletions src/main/java/mega/waka/discord/DiscordListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,57 +45,11 @@ public DiscordListener(MemberRepository memberRepository, SevenDaysWakaService s
this.memberRepository = memberRepository;
this.sevenDaysWakaService = sevenDaysWakaService;
}
@Transactional
@JsonIgnore
public void update_SevenDays(){
List<Member> members = memberRepository.findAll();
String responseData="";
try {
RestTemplate restTemplate = new RestTemplate();
String apiUrl ="https://wakatime.com/api/v1/users/current/summaries?range=last_7_days";
for (Member member : members) {

UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(apiUrl);

HttpHeaders headers = new HttpHeaders();
headers.setBasicAuth(member.getSecretKey(),"");

ResponseEntity<String> response = restTemplate.exchange(
builder.toUriString(),
HttpMethod.GET,
new HttpEntity<>(headers),
String.class
);
responseData = response.getBody();

JSONParser parser = new JSONParser();
JSONObject jsonObject = (JSONObject) parser.parse(responseData);
JSONObject cumulative_total = (JSONObject) jsonObject.get("cumulative_total");
member.setSevenDays(cumulative_total.get("text").toString());

memberRepository.save(member);

DayOfWeek dayOfWeek = LocalDate.now().getDayOfWeek();
if(dayOfWeek.getDisplayName(TextStyle.FULL, Locale.KOREAN).equals("금요일") && !member.getMoney().getUpdateDate().isEqual(LocalDate.now())){
int money = member.getMoney().getAmount();
String [] time = member.getSevenDays().split(" ");
int hour = Integer.valueOf(time[0]);
money += (hour *9620)/10000;
member.getMoney().setAmount(money);
member.getMoney().setUpdateDate(LocalDate.now());
memberRepository.save(member);
}

}
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
@Override
public void onSlashCommandInteraction(SlashCommandInteractionEvent event) {
if(!event.getChannel().getId().equals("1090659127417638943")) return;
super.onSlashCommandInteraction(event);
update_SevenDays();
User user = event.getUser();
String returnMessage = "";
String newMessage = "!!!!!***근무 시간 미달자 ***!!!! \n";
Expand All @@ -117,7 +71,6 @@ public void onSlashCommandInteraction(SlashCommandInteractionEvent event) {
}
else{
memberMap.put(member.getName(),0);
System.out.println(member.getName());
}
}
List<Map.Entry<String,Integer>> sortedList = new ArrayList<>(memberMap.entrySet());
Expand Down

0 comments on commit fd6b314

Please sign in to comment.