-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#569 [feat] 글모임 인기 정보 관련 삭제 모듈 및 캐시 삭제 API 구현
#569 [feat] 글모임 인기 정보 관련 삭제 모듈 및 캐시 삭제 API 구현
- Loading branch information
Showing
9 changed files
with
113 additions
and
6 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
module-api/src/main/java/com/mile/controller/external/InternalController.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,18 @@ | ||
package com.mile.controller.external; | ||
|
||
import com.mile.common.CacheService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class InternalController { | ||
|
||
private final CacheService cacheService; | ||
|
||
@PostMapping("/api/v1/moim/info/cache") | ||
public void deleteMoimInfoCache() { | ||
cacheService.deleteMoimCache(); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
module-domain/src/main/java/com/mile/common/CacheService.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 com.mile.common; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.cache.CacheManager; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class CacheService { | ||
|
||
private final String MOIM_CACHE_NAME = "moimPopularInfo"; | ||
private final CacheManager cacheManager; | ||
|
||
public void deleteMoimCache() { | ||
if (cacheManager.getCache(MOIM_CACHE_NAME) != null) { | ||
cacheManager.getCache(MOIM_CACHE_NAME).clear(); | ||
} | ||
} | ||
} |
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
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
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
53 changes: 53 additions & 0 deletions
53
module-external/src/main/java/com/mile/slack/module/SendMessageModule.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,53 @@ | ||
package com.mile.slack.module; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.lang.NonNull; | ||
import org.springframework.scheduling.annotation.Async; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.ArrayList; | ||
|
||
|
||
@Component | ||
@Slf4j | ||
public class SendMessageModule implements SendWebhookMessage { | ||
private final StringBuilder sb = new StringBuilder(); | ||
|
||
@Value("${webhook.url-for-event}") | ||
private String webHookUri; | ||
|
||
@Override | ||
public void sendMessage(@NonNull final String message) { | ||
WebClient webClient = WebClient.builder() | ||
.baseUrl(webHookUri).build(); | ||
|
||
|
||
webClient.post() | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.bodyValue(generateMessage(message)) | ||
.accept(MediaType.APPLICATION_JSON) | ||
.retrieve() | ||
.bodyToMono(String.class) | ||
.doOnError(e -> log.error("WEB HOOK 전송 중 에러 발생 -> {}", e.getMessage())) | ||
.subscribe(); | ||
} | ||
|
||
private SlackMessage generateMessage(final String message) { | ||
sb.append("*[인기글 삭제 작업 완료]*").append("\n").append(message).append("\n"); | ||
sb.append("*[진행일자]*").append("\n").append(LocalDateTime.now()).append("\n"); | ||
|
||
return new SlackMessage(sb.toString()); | ||
} | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
private class SlackMessage { | ||
private String text; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
module-external/src/main/java/com/mile/slack/module/SendWebhookMessage.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.mile.slack.module; | ||
|
||
import org.springframework.lang.NonNull; | ||
|
||
public interface SendWebhookMessage { | ||
void sendMessage(@NonNull final String message); | ||
|
||
} |