Skip to content

Commit

Permalink
Merge pull request #112 from SWEET-DEVELOPERS/feature/#110-member
Browse files Browse the repository at this point in the history
Feature/#110 member
  • Loading branch information
hysong4u authored Feb 5, 2024
2 parents bc4f855 + 2ab3b94 commit 0a32822
Showing 1 changed file with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@
import org.sopt.sweet.global.config.auth.jwt.JwtProvider;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

@RequiredArgsConstructor
Expand Down Expand Up @@ -53,6 +52,9 @@ private String issueNewRefreshToken(Long memberId) {
@Value("${jwt.refresh-token-expire-time}")
private long REFRESH_TOKEN_EXPIRE_TIME;

@Value("${discord.webhook.url}")
private String discordWebhookUrl;

private final ObjectMapper objectMapper;
private final RedisTemplate<String, String> redisTemplate;

Expand Down Expand Up @@ -121,6 +123,7 @@ public KakaoUserInfoResponseDto saveMember(Long socialId, String nickname, Strin
.profileImg(profileImage)
.build();
memberRepository.save(member);
sendDiscordNotification(nickname);
return new KakaoUserInfoResponseDto(member.getId(), socialId, nickname, profileImage);
}
return new KakaoUserInfoResponseDto(existMember.getId(), socialId, nickname, profileImage);
Expand Down Expand Up @@ -167,6 +170,28 @@ public MemberReissueTokenResponseDto reissue(MemberTokenResponseDto memberTokenR
return MemberReissueTokenResponseDto.of(newAccessToken, newRefreshToken);
}

// ํšŒ์›๊ฐ€์ž… ์›นํ›…
public String sendDiscordNotification(String nickname) {
RestTemplate restTemplate = new RestTemplate();
Long totalMembers = memberRepository.count();

String message = totalMembers + "๋ฒˆ์งธ ๋ฉค๋ฒ„๊ฐ€ ํšŒ์›๊ฐ€์ž…ํ–ˆ์Šต๋‹ˆ๋‹ค.\n" +
"์‚ฌ์šฉ์ž๋ช…: " + nickname;

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);

Map<String, String> body = new HashMap<>();
body.put("content", message);

HttpEntity<Map<String, String>> requestEntity = new HttpEntity<>(body, headers);

restTemplate.postForEntity(discordWebhookUrl, requestEntity, String.class);
return null;
}




}

Expand Down

0 comments on commit 0a32822

Please sign in to comment.