Skip to content
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

🔀::WebHook 로직 추가 #235

Merged
merged 15 commits into from
Dec 27, 2023
Merged

🔀::WebHook 로직 추가 #235

merged 15 commits into from
Dec 27, 2023

Conversation

Umjiseung
Copy link
Contributor

💡 개요

회원가입을 하면 디스코드 웹훅을 이용하여 회원가입을 시도한 유저의 email과 함께 웹훅을 보내는 기능

📃 작업내용

  • global에 config에서 discord패키지를 만들어 WebHookConfiguration을 만들었다.
  • domain에서 webhook패키지를 만들어 WebHookService를 만들었다.
  • domain에 auth 중 SignupService에 webhookService를 주입하여 callEvent함수를 호출하여 회원가입을 시도하면 디스코드 웹훅로 알려줄 수 있도록 하였다.
  • kotlin-serialization라는 의존성을 추가하였다.

@Umjiseung Umjiseung self-assigned this Dec 25, 2023
@Umjiseung Umjiseung linked an issue Dec 25, 2023 that may be closed by this pull request
@Umjiseung Umjiseung added 📬 API 서버 API 통신 3️⃣Priority: Low 우선순위 하 ✨ Feature 기능 개발 labels Dec 25, 2023
@@ -46,7 +48,7 @@ class SignUpService(
val savedUser = userRepository.save(user)

saveUserRole(user)

webHookService.callEvent(user.email)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Service라는 명칭과 메서드를 직접 호출하는 것 보다는 ApplicationEventPublisher를 이용하는게 어떨까요

Comment on lines 7 to 15
@Configuration
class WebHookConfiguration {

@Bean
fun webHookService(): WebHookService {
return WebHookService()
}

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이렇게 빈 등록을 하는 것 보다는 빈 등록하고싶은 클래스에 @component 어노테이션을 붙이면 빈 등록이 자동으로 됩니당

@@ -41,6 +41,9 @@ spring:
max-file-size: ${MAX_FILE_SIZE}
max-request-size: ${MAX_REQUEST_SIZE}

discord:
webhookURL: ${SIGNUP_URL}
Copy link
Member

@baekteun baekteun Dec 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

환경변수 이름이 SIGNUP_URL이 적절한건지 궁금해요

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

36a6736 이름이 맞지않는 거 같아 수정하였습니다!

@@ -41,6 +41,9 @@ spring:
max-file-size: ${MAX_FILE_SIZE}
max-request-size: ${MAX_REQUEST_SIZE}

discord:
webhookURL: ${SIGNUP_URL}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

기존에 정의되어있는 property들이 max-file-size 같이 dash case인지라 webhookURL보다는 webhook_url 어떤가요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

36a6736 좋은 거 같습니다. 반영하여 수정하였습니다!

class AuthEventHandler(
private val discordProperties: DiscordProperties
) {
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

어차피 로깅용이면 트랜잭션 이벤트 리스너가 아니라 그냥 이벤트 리스너써서 함수 호출됐을때 실행되도록 하면 될 것 같네요

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

7d401de
참고해서 수정했습니다!

val restTemplate = RestTemplate()
val entity = HttpEntity(jsonObject.toString(), headers)
restTemplate.postForObject(discordProperties.url, entity, String::class.java)
println("3")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

print 다 찍었으면 지워주세요

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

7d401de
깜박하고 지우지 않은거같아요 수정했습니다!

Copy link
Contributor

@esperar esperar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생했어요

@Umjiseung Umjiseung merged commit ea2b364 into main Dec 27, 2023
1 check passed
@Umjiseung Umjiseung deleted the 234-signup-webhook branch December 27, 2023 03:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3️⃣Priority: Low 우선순위 하 📬 API 서버 API 통신 ✨ Feature 기능 개발
Projects
None yet
Development

Successfully merging this pull request may close these issues.

회원가입시 웹훅연결
4 participants