Skip to content

Commit

Permalink
[COZY-493] feat: 회원가입시 디스코드로 알림 보내는 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
eple0329 authored Jan 24, 2025
1 parent 5170061 commit 2bdb9c5
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 2 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ dependencies {
implementation 'io.sentry:sentry-spring-boot-starter-jakarta:7.20.0'
implementation 'io.sentry:sentry-jdbc:7.20.0'

// webflux
implementation 'org.springframework.boot:spring-boot-starter-webflux'

}

tasks.named('test') {
Expand Down
2 changes: 1 addition & 1 deletion config
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class MemberCommandService {

private final MailService mailService;

private final SignUpNotificationService signUpNotificationService;

/**
* 닉네임 유효성 검사 메서드
*
Expand Down Expand Up @@ -98,9 +100,11 @@ public SignInResponseDTO signUp(String clientId,
University memberUniversity = universityRepository.findById(signUpRequestDTO.universityId())
.orElseThrow(() -> new GeneralException(ErrorStatus._UNIVERSITY_NOT_FOUND));

memberRepository.save(
Member member = memberRepository.save(
MemberConverter.toMember(clientId, signUpRequestDTO, memberUniversity));

signUpNotificationService.sendSignUpNotification(member);

// 기존 회원으로 로그인 처리
return signInByExistingMember(clientId);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.cozymate.cozymate_server.domain.member.service;

import com.cozymate.cozymate_server.domain.member.Member;
import com.cozymate.cozymate_server.global.logging.enums.MdcKey;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;

@Service
@RequiredArgsConstructor
@Slf4j
public class SignUpNotificationService {


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

public void sendSignUpNotification(Member member) {
// WebClient를 사용하여 AWS Lambda로 회원가입 알림을 보냄
WebClient webClient = WebClient.builder().baseUrl(signUpNotificationUri).build();

Map<String, String> contentMap = new HashMap<>();

StringBuilder contentBuilder = new StringBuilder();
contentBuilder.append("### 새로운 유저 등장!\n");
contentBuilder.append("**")
.append("Id").append("**: ")
.append(member.getId()).append("\n");
contentBuilder.append("**")
.append("Nickname").append("**: ")
.append(member.getNickname()).append("\n");
contentBuilder.append("**")
.append("Gender").append("**: ")
.append(member.getGender()).append("\n");
contentBuilder.append("**")
.append("SocialType").append("**: ")
.append(member.getSocialType()).append("\n");
contentBuilder.append("**")
.append("Platform").append("**: ")
.append(MDC.get(MdcKey.REQEUST_AGENT.toString())).append("\n");
contentBuilder.append("-# ").append(LocalDateTime.now().toString()).append("\n");
contentMap.put("content", contentBuilder.toString());

// Non-Blocking 방식으로 호출하고 응답을 기다리지 않음
webClient.post()
.bodyValue(contentMap)
.retrieve()
.bodyToMono(Void.class)
.subscribe();

}

}

0 comments on commit 2bdb9c5

Please sign in to comment.