-
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.
- Loading branch information
Showing
20 changed files
with
302 additions
and
164 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
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
19 changes: 0 additions & 19 deletions
19
src/main/java/com/khumu/alimi/data/dto/AnnouncementAuthorFollowDto.java
This file was deleted.
Oops, something went wrong.
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
38 changes: 38 additions & 0 deletions
38
src/main/java/com/khumu/alimi/data/dto/NewAnnouncementCrawledDto.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,38 @@ | ||
package com.khumu.alimi.data.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* notice crawler๊ฐ ์๋ก์ด ๊ณต์ง์ฌํญ์ crawlํ ๊ฒฝ์ฐ ๋งค์์ง๋ฅผ publish | ||
{ | ||
"announcement": { | ||
"id": 1, | ||
"title": "์๋ฐฉ์์ค ๋ณด์๊ณต์ฌ ์ํ ์๋ด ", | ||
"sub_link": "http://ce.khu.ac.kr/index.php?hCode=BOARD&page=view&idx=2330&bo_idx=1", | ||
"date": "2021-08-06 11:15:38", | ||
"author": { | ||
"id": 1, | ||
"author_name": "์ปดํจํฐ๊ณตํ๊ณผ", | ||
"followed": false | ||
}, | ||
"followers": [ | ||
"jinsu", "bo314" | ||
] | ||
} | ||
*/ | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Data | ||
@Builder | ||
public class NewAnnouncementCrawledDto { | ||
AnnouncementDto announcement; | ||
// ์๋ฆผ์ ๋ฐ์ ํ๋ณด์ธ user๋ค. ํด๋น author์ follow ์ค์ด๋ค | ||
List<String> followers; | ||
} | ||
|
||
|
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
97 changes: 97 additions & 0 deletions
97
src/main/java/com/khumu/alimi/external/slack/SlackNotifier.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,97 @@ | ||
package com.khumu.alimi.external.slack; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.annotations.SerializedName; | ||
|
||
import lombok.*; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
import javax.annotation.Nullable; | ||
import javax.annotation.PostConstruct; | ||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class SlackNotifier { | ||
@Value("${notification.slack.enabled}") | ||
private boolean slackEnabled; | ||
@Value("${notification.slack.webhook.url}") | ||
private String webhookUrl; | ||
@Value("${notification.slack.channel}") | ||
private String channel; | ||
@Value("${notification.slack.botName}") private String botName; | ||
@Value("${notification.slack.icon.emoji}") private String iconEmoji; | ||
@Value("${notification.slack.icon.url}") private String iconUrl; | ||
|
||
@Autowired | ||
Environment env; | ||
@PostConstruct | ||
public void postConstructor(){ | ||
// slack = Slack.getInstance(); | ||
} | ||
public void sendSlack(String title, String content) { | ||
if (slackEnabled) { | ||
try { // create slack | ||
SlackMessage slackMessage = SlackMessage.builder().attachments(List.of(SlackMessage.Attachment.builder() | ||
.title(title) | ||
.text(content) | ||
.footer("from " + env.getActiveProfiles()[0]) | ||
.build() | ||
)).channel(channel).build(); | ||
String payload = new Gson().toJson(slackMessage); | ||
RestTemplate restTemplate = new RestTemplate(); | ||
HttpHeaders headers = new HttpHeaders(); | ||
headers.set("Content-Type", MediaType.APPLICATION_JSON_VALUE); // send the post request | ||
HttpEntity<String> entity = new HttpEntity<>(payload, headers); | ||
restTemplate.postForEntity(webhookUrl, entity, String.class); | ||
} catch (Exception e) { | ||
log.error("Unhandled Exception occurred while send slack. [Reason] : ", e); | ||
} | ||
} | ||
} | ||
|
||
@Builder | ||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public static class SlackMessage { | ||
@SerializedName("text") | ||
private String text; | ||
@SerializedName("channel") | ||
private String channel; | ||
@SerializedName("username") | ||
private String botName; | ||
@SerializedName("icon_emoji") | ||
private String iconEmoji; | ||
@SerializedName("icon_url") | ||
private String iconUrl; | ||
@SerializedName("attachments") | ||
private List<Attachment> attachments; | ||
|
||
@Builder | ||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public static class Attachment { | ||
@SerializedName("title") | ||
private String title; | ||
@SerializedName("text") | ||
private String text; | ||
@SerializedName("color") | ||
@Builder.Default | ||
private String color = "#2222BB"; | ||
@SerializedName("footer") | ||
private String footer; | ||
} | ||
} | ||
} |
Oops, something went wrong.