-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #287 from JiHongKim98/feature/user-inquiries
회원 1:1 문의하기 기능 추가
- Loading branch information
Showing
14 changed files
with
206 additions
and
6 deletions.
There are no files selected for viewing
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
25 changes: 25 additions & 0 deletions
25
src/main/java/com/example/daobe/common/config/DiscordConfig.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,25 @@ | ||
package com.example.daobe.common.config; | ||
|
||
import com.example.daobe.user.infrastructure.discord.DiscordApiClient; | ||
import com.example.daobe.user.infrastructure.discord.DiscordProperties; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.web.client.RestClient; | ||
import org.springframework.web.client.support.RestClientAdapter; | ||
import org.springframework.web.service.invoker.HttpServiceProxyFactory; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
public class DiscordConfig { | ||
|
||
private final DiscordProperties discordProperties; | ||
|
||
@Bean | ||
public DiscordApiClient createHttpInterface() { | ||
RestClient restClient = RestClient.builder().baseUrl(discordProperties.webhookUrl()).build(); | ||
RestClientAdapter adapter = RestClientAdapter.create(restClient); | ||
HttpServiceProxyFactory factory = HttpServiceProxyFactory.builderFor(adapter).build(); | ||
return factory.createClient(DiscordApiClient.class); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/example/daobe/user/application/UserExternalEventAlert.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,8 @@ | ||
package com.example.daobe.user.application; | ||
|
||
import com.example.daobe.user.domain.event.UserInquiriesEvent; | ||
|
||
public interface UserExternalEventAlert { | ||
|
||
void execute(UserInquiriesEvent event); | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/example/daobe/user/application/UserExternalEventListener.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,21 @@ | ||
package com.example.daobe.user.application; | ||
|
||
import com.example.daobe.user.domain.event.UserInquiriesEvent; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.scheduling.annotation.Async; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.event.TransactionPhase; | ||
import org.springframework.transaction.event.TransactionalEventListener; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class UserExternalEventListener { | ||
|
||
private final UserExternalEventAlert userExternalEventAlert; | ||
|
||
@Async | ||
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) | ||
public void listenInquiriesEvent(UserInquiriesEvent event) { | ||
userExternalEventAlert.execute(event); | ||
} | ||
} |
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
7 changes: 7 additions & 0 deletions
7
src/main/java/com/example/daobe/user/application/dto/UserInquiriesRequestDto.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,7 @@ | ||
package com.example.daobe.user.application.dto; | ||
|
||
public record UserInquiriesRequestDto( | ||
String email, | ||
String contents | ||
) { | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/example/daobe/user/domain/event/UserInquiriesEvent.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 com.example.daobe.user.domain.event; | ||
|
||
public record UserInquiriesEvent( | ||
Long userId, | ||
String nickname, | ||
String email, | ||
String contents | ||
) { | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/example/daobe/user/infrastructure/discord/DiscordApiClient.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,11 @@ | ||
package com.example.daobe.user.infrastructure.discord; | ||
|
||
import com.example.daobe.user.infrastructure.discord.dto.DiscordAlertPayloadDto; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.service.annotation.PostExchange; | ||
|
||
public interface DiscordApiClient { | ||
|
||
@PostExchange | ||
void execute(@RequestBody DiscordAlertPayloadDto payload); | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/example/daobe/user/infrastructure/discord/DiscordProperties.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,10 @@ | ||
package com.example.daobe.user.infrastructure.discord; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
@ConfigurationProperties(prefix = "discord") | ||
public record DiscordProperties( | ||
String webhookUrl, | ||
String messageFormat | ||
) { | ||
} |
35 changes: 35 additions & 0 deletions
35
...ain/java/com/example/daobe/user/infrastructure/discord/DiscordUserExternalEventAlert.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,35 @@ | ||
package com.example.daobe.user.infrastructure.discord; | ||
|
||
import com.example.daobe.user.application.UserExternalEventAlert; | ||
import com.example.daobe.user.domain.event.UserInquiriesEvent; | ||
import com.example.daobe.user.infrastructure.discord.dto.DiscordAlertPayloadDto; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class DiscordUserExternalEventAlert implements UserExternalEventAlert { | ||
|
||
private static final String DISCORD_MESSAGE_TITLE = "💬 1:1 문의하기"; | ||
private static final String DISCORD_MESSAGE_CONTENTS = "## 🚀 새로운 문의가 도착했습니다!"; | ||
|
||
private final DiscordApiClient discordApiClient; | ||
private final DiscordProperties discordProperties; | ||
|
||
@Override | ||
public void execute(UserInquiriesEvent event) { | ||
String description = String.format( | ||
discordProperties.messageFormat(), | ||
event.userId(), | ||
event.nickname(), | ||
event.email(), | ||
event.contents() | ||
); | ||
DiscordAlertPayloadDto payload = DiscordAlertPayloadDto.of( | ||
DISCORD_MESSAGE_CONTENTS, | ||
DISCORD_MESSAGE_TITLE, | ||
description | ||
); | ||
discordApiClient.execute(payload); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/example/daobe/user/infrastructure/discord/dto/DiscordAlertPayloadDto.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,20 @@ | ||
package com.example.daobe.user.infrastructure.discord.dto; | ||
|
||
import java.util.List; | ||
|
||
public record DiscordAlertPayloadDto( | ||
String content, | ||
List<Embeds> embeds | ||
) { | ||
|
||
public static DiscordAlertPayloadDto of(String content, String title, String description) { | ||
return new DiscordAlertPayloadDto(content, List.of(new Embeds(title, description))); | ||
} | ||
|
||
// Nested | ||
public record Embeds( | ||
String title, | ||
String description | ||
) { | ||
} | ||
} |
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
Submodule config
updated
from 8dfb36 to da1b8c