From 58b172cec7fc9035f5f2be2148f78b48cb000bba Mon Sep 17 00:00:00 2001 From: sohyundoh Date: Tue, 27 Aug 2024 13:58:56 +0900 Subject: [PATCH 1/3] =?UTF-8?q?#328=20[fix]=20slack=20api=20=EC=9D=98?= =?UTF-8?q?=EC=A1=B4=EC=84=B1=20=EC=97=85=EA=B7=B8=EB=A0=88=EC=9D=B4?= =?UTF-8?q?=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index c789db67..d153d245 100644 --- a/build.gradle +++ b/build.gradle @@ -62,7 +62,7 @@ dependencies { implementation group: 'io.jsonwebtoken', name: 'jjwt-jackson', version: '0.11.2' // Slack Webhook - implementation 'com.slack.api:slack-api-client:1.28.0' + implementation 'com.slack.api:slack-api-client:1.30.0' implementation 'com.google.code.gson:gson:2.10.1' implementation 'com.squareup.okhttp3:okhttp:4.10.0' implementation 'com.slack.api:slack-app-backend:1.28.0' From 59cb64247d38a1813496e62fb34f1dcdafd29bb1 Mon Sep 17 00:00:00 2001 From: sohyundoh Date: Tue, 27 Aug 2024 14:00:30 +0900 Subject: [PATCH 2/3] =?UTF-8?q?#328=20[fix]=20slack=20util=20deprecated=20?= =?UTF-8?q?api=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../asap/server/infra/slack/SlackUtil.java | 42 +++++++------------ 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/src/main/java/com/asap/server/infra/slack/SlackUtil.java b/src/main/java/com/asap/server/infra/slack/SlackUtil.java index 8a44713c..8b14fcaf 100644 --- a/src/main/java/com/asap/server/infra/slack/SlackUtil.java +++ b/src/main/java/com/asap/server/infra/slack/SlackUtil.java @@ -4,6 +4,7 @@ import com.slack.api.model.block.Blocks; import com.slack.api.model.block.LayoutBlock; import com.slack.api.model.block.composition.BlockCompositions; +import com.slack.api.webhook.Payload; import com.slack.api.webhook.WebhookPayloads; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -25,29 +26,19 @@ public class SlackUtil { @Value("${slack.webhook.url}") private String webhookUrl; - private StringBuilder sb= new StringBuilder(); + private final StringBuilder sb= new StringBuilder(); - private String NEW_LINE = "\n"; - private String DOUBLE_NEW_LINE = "\n\n"; + private final String NEW_LINE = "\n"; + private final String DOUBLE_NEW_LINE = "\n\n"; - //slack으로 알림보내기 public void sendAlert(Exception error, HttpServletRequest request) throws IOException{ - // 메시지 내용인 LayoutBlock List 생성 - List layoutBlocks= generateLayoutBlock(error,request); + List layoutBlocks= generateLayoutBlock(error,request); - // 슬랙의 send API과 webhookURL을 통해 생성한 메시지 내용 전송 Slack.getInstance().send(webhookUrl, WebhookPayloads - .payload(p-> - // 메시지 전송 유저명 - p.username("Exception is detected") - // 메시지 전송 유저 아이콘 이미지 URL - .iconUrl("https://yt3.googleusercontent.com/ytc/AGIKgqMVUzRrhoo1gDQcqvPo0PxaJz7e0gqDXT0D78R5VQ=s900-c-k-c0x00ffffff-no-rj") - // 메시지 내용 - .blocks(layoutBlocks))); + .payload(p -> p.blocks(layoutBlocks))); } - // 전체 메시지가 담긴 LayoutBlock 생성 - private List generateLayoutBlock(Exception error, HttpServletRequest request) { + private List generateLayoutBlock(Exception error, HttpServletRequest request) { return Blocks.asBlocks( getHeader("Internal Server Error Detected"), Blocks.divider(), @@ -55,44 +46,39 @@ private List generateLayoutBlock(Exception error, HttpServletRequest request) { Blocks.divider(), getSection(generateErrorPointMessage(request)), Blocks.divider(), - // 이슈 생성을 위해 프로젝트의 Issue URL을 입력하여 바로가기 링크를 생성 getSection("") ); } - // 예외 정보 메시지 생성 private String generateErrorMessage(Exception error) { sb.setLength(0); - sb.append("*[Exception]*" + NEW_LINE + error.toString() + DOUBLE_NEW_LINE); - sb.append("*[From]*" + NEW_LINE + readRootStackTrace(error) + DOUBLE_NEW_LINE); + sb.append("*[Exception]*").append(NEW_LINE).append(error.toString()).append(DOUBLE_NEW_LINE); + sb.append("*[From]*").append(NEW_LINE).append(readRootStackTrace(error)).append(DOUBLE_NEW_LINE); return sb.toString(); } - // HttpServletRequest를 사용하여 예외발생 요청에 대한 정보 메시지 생성 private String generateErrorPointMessage(HttpServletRequest request) { sb.setLength(0); - sb.append("*[Details]*" + NEW_LINE); - sb.append("Request URL : " + request.getRequestURL().toString() + NEW_LINE); - sb.append("Request Method : " + request.getMethod() + NEW_LINE); - sb.append("Request Time : " + new Date() + NEW_LINE); + sb.append("*[Details]*").append(NEW_LINE); + sb.append("Request URL : ").append(request.getRequestURL().toString()).append(NEW_LINE); + sb.append("Request Method : ").append(request.getMethod()).append(NEW_LINE); + sb.append("Request Time : ").append(new Date()).append(NEW_LINE); return sb.toString(); } - // 예외발생 클래스 정보 return private String readRootStackTrace(Exception error) { return error.getStackTrace()[0].toString(); } - // 에러 로그 메시지의 제목 return + private LayoutBlock getHeader(String text) { return Blocks.header(h->h.text( plainText(pt->pt.emoji(true) .text(text)))); } - // 에러 로그 메시지 내용 return private LayoutBlock getSection(String message) { return Blocks.section(s-> s.text(BlockCompositions.markdownText(message))); From 155647874cd1546e1c8d151308b0787aa09e3dca Mon Sep 17 00:00:00 2001 From: sohyundoh Date: Tue, 27 Aug 2024 14:01:12 +0900 Subject: [PATCH 3/3] =?UTF-8?q?#328=20[fix]=20UserMeetingSchedule=20?= =?UTF-8?q?=ED=85=8C=EC=9D=B4=EB=B8=94=20Auditing=20Time=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/persistence/domain/time/UserMeetingSchedule.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/asap/server/persistence/domain/time/UserMeetingSchedule.java b/src/main/java/com/asap/server/persistence/domain/time/UserMeetingSchedule.java index 287f14a9..eb11a460 100644 --- a/src/main/java/com/asap/server/persistence/domain/time/UserMeetingSchedule.java +++ b/src/main/java/com/asap/server/persistence/domain/time/UserMeetingSchedule.java @@ -1,5 +1,6 @@ package com.asap.server.persistence.domain.time; +import com.asap.server.persistence.domain.AuditingTimeEntity; import com.asap.server.persistence.domain.enums.TimeSlot; import jakarta.persistence.Column; import jakarta.persistence.Entity; @@ -18,7 +19,7 @@ @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class UserMeetingSchedule { +public class UserMeetingSchedule extends AuditingTimeEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id;