-
Notifications
You must be signed in to change notification settings - Fork 0
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 #207 from Team-Hankki/develop
[feat] 디스코드 알람 (#206)
- Loading branch information
Showing
14 changed files
with
165 additions
and
10 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
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
31 changes: 31 additions & 0 deletions
31
src/main/java/org/hankki/hankkiserver/api/external/service/DiscordEventListener.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,31 @@ | ||
package org.hankki.hankkiserver.api.external.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.hankki.hankkiserver.event.store.CreateStoreEvent; | ||
import org.hankki.hankkiserver.event.store.DeleteStoreEvent; | ||
import org.hankki.hankkiserver.event.user.CreateUserEvent; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.event.TransactionPhase; | ||
import org.springframework.transaction.event.TransactionalEventListener; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class DiscordEventListener { | ||
|
||
private final DiscordService discordService; | ||
|
||
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) | ||
public void sendStoreCreationNotice(CreateStoreEvent event) { | ||
discordService.sendStoreCreationMessage(event.storeName(), event.universityName()); | ||
} | ||
|
||
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) | ||
public void sendUserCreateNotice(CreateUserEvent event) { | ||
discordService.sendUserCreationMessage(event.userId(), event.userName(), event.platform()); | ||
} | ||
|
||
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT) | ||
public void sendStoreDeleteNotice(DeleteStoreEvent event) { | ||
discordService.sendStoreDeleteMessage(event.name(), event.userId()); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/org/hankki/hankkiserver/api/external/service/DiscordService.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,23 @@ | ||
package org.hankki.hankkiserver.api.external.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.hankki.hankkiserver.external.openfeign.discord.DiscordFeignClient; | ||
import org.hankki.hankkiserver.external.openfeign.discord.dto.DiscordMessage; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class DiscordService { | ||
|
||
private final DiscordFeignClient discordFeignClient; | ||
|
||
public void sendStoreCreationMessage(String storeName, String universityName) { | ||
discordFeignClient.sendStoreCreationMessage(DiscordMessage.storeCreationMessageOf(storeName, universityName)); | ||
} | ||
public void sendUserCreationMessage(Long userId, String userName, String platform) { | ||
discordFeignClient.sendUserCreationMessage(DiscordMessage.userCreationMessageOf(userId, userName, platform)); | ||
} | ||
public void sendStoreDeleteMessage(String storeName, Long userId) { | ||
discordFeignClient.sendStoreDeleteMessage(DiscordMessage.storeDeleteMessageOf(storeName, userId)); | ||
} | ||
} |
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
8 changes: 8 additions & 0 deletions
8
src/main/java/org/hankki/hankkiserver/api/store/service/command/StoreDeleteCommand.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 org.hankki.hankkiserver.api.store.service.command; | ||
|
||
public record StoreDeleteCommand(Long storeId, | ||
Long userId) { | ||
public static StoreDeleteCommand of(Long storeId, Long userId) { | ||
return new StoreDeleteCommand(storeId, userId); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/org/hankki/hankkiserver/event/EventPublisher.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,5 @@ | ||
package org.hankki.hankkiserver.event; | ||
|
||
public interface EventPublisher { | ||
void publish(Object event); | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/org/hankki/hankkiserver/event/EventPublisherAdapter.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,17 @@ | ||
package org.hankki.hankkiserver.event; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.ApplicationEventPublisher; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class EventPublisherAdapter implements EventPublisher { | ||
|
||
private final ApplicationEventPublisher applicationEventPublisher; | ||
|
||
@Override | ||
public void publish(Object event) { | ||
applicationEventPublisher.publishEvent(event); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/org/hankki/hankkiserver/event/store/CreateStoreEvent.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 org.hankki.hankkiserver.event.store; | ||
|
||
public record CreateStoreEvent (String storeName, | ||
String universityName) { | ||
public static CreateStoreEvent of(String storeName, String universityName) { | ||
return new CreateStoreEvent(storeName, universityName); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/org/hankki/hankkiserver/event/store/DeleteStoreEvent.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 org.hankki.hankkiserver.event.store; | ||
|
||
public record DeleteStoreEvent(String name, Long userId) { | ||
public static DeleteStoreEvent of(String name, Long userId) { | ||
return new DeleteStoreEvent(name, userId); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/org/hankki/hankkiserver/event/user/CreateUserEvent.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 org.hankki.hankkiserver.event.user; | ||
|
||
public record CreateUserEvent( | ||
Long userId, | ||
String userName, | ||
String platform | ||
) { | ||
public static CreateUserEvent of(Long userId, String userName, String platform) { | ||
return new CreateUserEvent(userId, userName, platform); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/org/hankki/hankkiserver/external/openfeign/discord/DiscordFeignClient.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,19 @@ | ||
package org.hankki.hankkiserver.external.openfeign.discord; | ||
|
||
import org.hankki.hankkiserver.external.openfeign.discord.dto.DiscordMessage; | ||
import org.springframework.cloud.openfeign.FeignClient; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
|
||
@FeignClient(name = "discordClient", url = "${discord.webhook.url}") | ||
public interface DiscordFeignClient { | ||
@PostMapping(value = "${discord.webhook.create-store}", produces = MediaType.APPLICATION_JSON_VALUE) | ||
void sendStoreCreationMessage(@RequestBody DiscordMessage message); | ||
|
||
@PostMapping(value = "${discord.webhook.create-user}", produces = MediaType.APPLICATION_JSON_VALUE) | ||
void sendUserCreationMessage(@RequestBody DiscordMessage message); | ||
|
||
@PostMapping(value = "${discord.webhook.delete-store}", produces = MediaType.APPLICATION_JSON_VALUE) | ||
void sendStoreDeleteMessage(@RequestBody DiscordMessage message); | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/org/hankki/hankkiserver/external/openfeign/discord/dto/DiscordMessage.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,15 @@ | ||
package org.hankki.hankkiserver.external.openfeign.discord.dto; | ||
|
||
public record DiscordMessage(String content) { | ||
public static DiscordMessage storeCreationMessageOf(String storeName, String universityName) { | ||
return new DiscordMessage(universityName+ "에 <" +storeName+ ">가 생성되었습니다."); | ||
} | ||
|
||
public static DiscordMessage userCreationMessageOf(Long userId, String userName, String platform) { | ||
return new DiscordMessage( platform + userId + "번째 유저 <" +userName+ ">가 가입했습니다."); | ||
} | ||
|
||
public static DiscordMessage storeDeleteMessageOf(String storeName, Long userId) { | ||
return new DiscordMessage( userId + "번 유저에의해 <" + storeName + ">가 삭제되었습니다."); | ||
} | ||
} |