From f4bb99519734cf2533dd19c9537257823c13723a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A0=95=ED=98=B8?= Date: Thu, 7 Sep 2023 00:50:37 +0900 Subject: [PATCH 01/14] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20::=20webhook=20?= =?UTF-8?q?=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- feed-infrastructure/build.gradle | 3 +++ 1 file changed, 3 insertions(+) diff --git a/feed-infrastructure/build.gradle b/feed-infrastructure/build.gradle index 4ee5fcc8..c44dfb7b 100644 --- a/feed-infrastructure/build.gradle +++ b/feed-infrastructure/build.gradle @@ -52,6 +52,9 @@ dependencies { // message implementation 'org.springframework.cloud:spring-cloud-aws-messaging:2.2.6.RELEASE' + // Webhook + implementation 'net.gpedro.integrations.slack:slack-webhook:1.4.0' + implementation(project(":feed-domain")) } From 0d75b2adee6c472733df249ba0c979c44060190c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A0=95=ED=98=B8?= Date: Thu, 7 Sep 2023 00:51:58 +0900 Subject: [PATCH 02/14] =?UTF-8?q?=F0=9F=93=91=20::=20AsyncConfig=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v1servicefeed/configuration/config/AsyncConfig.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 feed-infrastructure/src/main/java/com/xquare/v1servicefeed/configuration/config/AsyncConfig.java diff --git a/feed-infrastructure/src/main/java/com/xquare/v1servicefeed/configuration/config/AsyncConfig.java b/feed-infrastructure/src/main/java/com/xquare/v1servicefeed/configuration/config/AsyncConfig.java new file mode 100644 index 00000000..57e6cc95 --- /dev/null +++ b/feed-infrastructure/src/main/java/com/xquare/v1servicefeed/configuration/config/AsyncConfig.java @@ -0,0 +1,9 @@ +package com.xquare.v1servicefeed.configuration.config; + +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.EnableAsync; + +@EnableAsync +@Configuration +public class AsyncConfig { +} From 6afbf8dc6ca5f27fb277dbc493626f35efdd00ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A0=95=ED=98=B8?= Date: Thu, 7 Sep 2023 00:52:27 +0900 Subject: [PATCH 03/14] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=A0=95=EB=A0=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xquare/v1servicefeed/comment/api/impl/CommentApiImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/feed-domain/src/main/java/com/xquare/v1servicefeed/comment/api/impl/CommentApiImpl.java b/feed-domain/src/main/java/com/xquare/v1servicefeed/comment/api/impl/CommentApiImpl.java index b5a4d9d1..18cc3e5d 100644 --- a/feed-domain/src/main/java/com/xquare/v1servicefeed/comment/api/impl/CommentApiImpl.java +++ b/feed-domain/src/main/java/com/xquare/v1servicefeed/comment/api/impl/CommentApiImpl.java @@ -56,13 +56,13 @@ public void saveComment(CreateCommentDomainRequest request) { .build() ); - if(!feed.getUserId().equals(userId)) { + if (!feed.getUserId().equals(userId)) { sendNotification(feed); } } private void sendNotification(Feed feed) { - if(CategoryEnum.NOTICE.getName().equals(categorySpi.queryCategoryById(feed.getCategoryId()).getName())) { + if (CategoryEnum.NOTICE.getName().equals(categorySpi.queryCategoryById(feed.getCategoryId()).getName())) { commentNotificationUtil.sendNotification(feed, FEED_NOTICE_COMMENT); } else { commentNotificationUtil.sendNotification(feed, FEED_BAMBOO_COMMENT); From bd52ec031b57d6655c8c1f9ee78098bb945d1096 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A0=95=ED=98=B8?= Date: Thu, 7 Sep 2023 00:52:42 +0900 Subject: [PATCH 04/14] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20::=20webhook=20url?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- feed-infrastructure/src/main/resources/application.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/feed-infrastructure/src/main/resources/application.yml b/feed-infrastructure/src/main/resources/application.yml index 519b4eb4..d8d88ea8 100644 --- a/feed-infrastructure/src/main/resources/application.yml +++ b/feed-infrastructure/src/main/resources/application.yml @@ -46,3 +46,6 @@ springdoc: display-request-duration: true cache: disabled: true + +webhook: + url: ${webhook.url} From d38a82a26b232a6e39d3105d101cef36664f5c01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A0=95=ED=98=B8?= Date: Thu, 7 Sep 2023 00:54:19 +0900 Subject: [PATCH 05/14] =?UTF-8?q?=F0=9F=93=91=20::=20SlackReport=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xquare/v1servicefeed/webhook/SlackReport.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 feed-domain/src/main/java/com/xquare/v1servicefeed/webhook/SlackReport.java diff --git a/feed-domain/src/main/java/com/xquare/v1servicefeed/webhook/SlackReport.java b/feed-domain/src/main/java/com/xquare/v1servicefeed/webhook/SlackReport.java new file mode 100644 index 00000000..335c4066 --- /dev/null +++ b/feed-domain/src/main/java/com/xquare/v1servicefeed/webhook/SlackReport.java @@ -0,0 +1,15 @@ +package com.xquare.v1servicefeed.webhook; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public class SlackReport { + + private final String feedContent; + + private final String userName; + + private final String reportContent; +} From 5b0ca08af1adc6d2283bf9f46e8f8e6e0fd0f6a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A0=95=ED=98=B8?= Date: Thu, 7 Sep 2023 00:54:39 +0900 Subject: [PATCH 06/14] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20::=20=ED=94=BC?= =?UTF-8?q?=EB=93=9C=20=EC=8B=A0=EA=B3=A0=EC=8B=9C=20slack=20=EC=95=8C?= =?UTF-8?q?=EB=9E=8C=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../report/api/impl/ReportApiImpl.java | 18 +++++-- .../webhook/spi/SendWebhookSpi.java | 10 ++++ .../webhook/SendWebhookAdapter.java | 48 +++++++++++++++++++ 3 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 feed-domain/src/main/java/com/xquare/v1servicefeed/webhook/spi/SendWebhookSpi.java create mode 100644 feed-infrastructure/src/main/java/com/xquare/v1servicefeed/webhook/SendWebhookAdapter.java diff --git a/feed-domain/src/main/java/com/xquare/v1servicefeed/report/api/impl/ReportApiImpl.java b/feed-domain/src/main/java/com/xquare/v1servicefeed/report/api/impl/ReportApiImpl.java index 55d9a95f..c39e478b 100644 --- a/feed-domain/src/main/java/com/xquare/v1servicefeed/report/api/impl/ReportApiImpl.java +++ b/feed-domain/src/main/java/com/xquare/v1servicefeed/report/api/impl/ReportApiImpl.java @@ -2,15 +2,20 @@ import com.xquare.v1servicefeed.annotation.DomainService; import com.xquare.v1servicefeed.configuration.spi.SecuritySpi; +import com.xquare.v1servicefeed.feed.Feed; +import com.xquare.v1servicefeed.feed.spi.QueryFeedSpi; import com.xquare.v1servicefeed.report.Report; import com.xquare.v1servicefeed.report.api.ReportApi; import com.xquare.v1servicefeed.report.api.dto.CreateReportDomainRequest; import com.xquare.v1servicefeed.report.exception.CannotReportMyFeedException; import com.xquare.v1servicefeed.report.spi.CommandReportSpi; -import com.xquare.v1servicefeed.feed.Feed; -import com.xquare.v1servicefeed.feed.spi.QueryFeedSpi; +import com.xquare.v1servicefeed.user.User; +import com.xquare.v1servicefeed.user.spi.FeedUserSpi; +import com.xquare.v1servicefeed.webhook.SlackReport; +import com.xquare.v1servicefeed.webhook.spi.SendWebhookSpi; import lombok.RequiredArgsConstructor; +import java.util.List; import java.util.UUID; @RequiredArgsConstructor @@ -20,13 +25,16 @@ public class ReportApiImpl implements ReportApi { private final QueryFeedSpi queryFeedSpi; private final CommandReportSpi commandReportSpi; private final SecuritySpi securitySpi; + private final SendWebhookSpi sendWebhookSpi; + private final FeedUserSpi feedUserSpi; @Override public void saveReport(CreateReportDomainRequest request) { Feed feed = queryFeedSpi.queryFeedById(request.getFeedId()); UUID userId = securitySpi.getCurrentUserId(); + User user = feedUserSpi.queryUserByIds(List.of(userId)).get(0); - if(userId.equals(feed.getUserId())) { + if (userId.equals(feed.getUserId())) { throw CannotReportMyFeedException.EXCEPTION; } @@ -38,5 +46,9 @@ public void saveReport(CreateReportDomainRequest request) { .content(request.getContent()) .build() ); + + sendWebhookSpi.sendReportToSlack( + new SlackReport(feed.getContent(), user.getName(), request.getContent()) + ); } } diff --git a/feed-domain/src/main/java/com/xquare/v1servicefeed/webhook/spi/SendWebhookSpi.java b/feed-domain/src/main/java/com/xquare/v1servicefeed/webhook/spi/SendWebhookSpi.java new file mode 100644 index 00000000..bdfc26b2 --- /dev/null +++ b/feed-domain/src/main/java/com/xquare/v1servicefeed/webhook/spi/SendWebhookSpi.java @@ -0,0 +1,10 @@ +package com.xquare.v1servicefeed.webhook.spi; + +import com.xquare.v1servicefeed.annotation.Spi; +import com.xquare.v1servicefeed.webhook.SlackReport; + +@Spi +public interface SendWebhookSpi { + + void sendReportToSlack(SlackReport slackReport); +} diff --git a/feed-infrastructure/src/main/java/com/xquare/v1servicefeed/webhook/SendWebhookAdapter.java b/feed-infrastructure/src/main/java/com/xquare/v1servicefeed/webhook/SendWebhookAdapter.java new file mode 100644 index 00000000..d483d3a9 --- /dev/null +++ b/feed-infrastructure/src/main/java/com/xquare/v1servicefeed/webhook/SendWebhookAdapter.java @@ -0,0 +1,48 @@ +package com.xquare.v1servicefeed.webhook; + +import com.xquare.v1servicefeed.webhook.spi.SendWebhookSpi; +import lombok.RequiredArgsConstructor; +import net.gpedro.integrations.slack.SlackApi; +import net.gpedro.integrations.slack.SlackAttachment; +import net.gpedro.integrations.slack.SlackMessage; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; + +@RequiredArgsConstructor +@Component +public class SendWebhookAdapter implements SendWebhookSpi { + + private static final String REPORT_MESSAGE = "피드 신고 발생"; + private static final String REPORT_USER_NAME = "신고자"; + private static final String REPORT_CONTENT = "신고 내용"; + private static final String REPORT_FEED_CONTENT = "신고한 게시글 내용"; + private static final String MESSAGE_COLOR = "#9650FA"; + private static final String FALLBACK = "Required plain-text summary of the attachment"; + + @Value("${webhook.url}") + private String webhookUrl; + + @Override + @Async + public void sendReportToSlack(SlackReport slackReport) { + SlackAttachment slackAttachment = createSlackAttachment(slackReport); + SlackMessage slackMessage = new SlackMessage("").addAttachments(slackAttachment); + new SlackApi(webhookUrl).call(slackMessage); + } + + private SlackAttachment createSlackAttachment(SlackReport slackReport) { + SlackAttachment slackAttachment = new SlackAttachment(); + slackAttachment.setTitle(REPORT_MESSAGE); + slackAttachment.setText(getErrorReason(slackReport)); + slackAttachment.setColor(MESSAGE_COLOR); + slackAttachment.setFallback(FALLBACK); + return slackAttachment; + } + + private String getErrorReason(SlackReport slackReport) { + return REPORT_USER_NAME + " : " + slackReport.getUserName() + + "\n" + REPORT_FEED_CONTENT + " : " + slackReport.getFeedContent() + + "\n" + REPORT_CONTENT + " : " + slackReport.getReportContent(); + } +} From 2454e6d6951cde5d859faa72aa5d5ff4501d6791 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A0=95=ED=98=B8?= Date: Thu, 7 Sep 2023 13:13:06 +0900 Subject: [PATCH 07/14] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20::=20=EC=95=84?= =?UTF-8?q?=EC=9D=B4=EB=94=94=EB=A1=9C=20=EC=82=AC=EC=9A=A9=EC=9E=90=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=A1=B0=ED=9A=8C=20API=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 --- .../com/xquare/v1servicefeed/feign/client/UserClient.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/feed-infrastructure/src/main/java/com/xquare/v1servicefeed/feign/client/UserClient.java b/feed-infrastructure/src/main/java/com/xquare/v1servicefeed/feign/client/UserClient.java index e19193b2..4ccb2d2d 100644 --- a/feed-infrastructure/src/main/java/com/xquare/v1servicefeed/feign/client/UserClient.java +++ b/feed-infrastructure/src/main/java/com/xquare/v1servicefeed/feign/client/UserClient.java @@ -1,8 +1,10 @@ package com.xquare.v1servicefeed.feign.client; +import com.xquare.v1servicefeed.feign.client.dto.response.UserInfoElement; import com.xquare.v1servicefeed.feign.client.dto.response.UserInfoResponse; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestParam; import java.util.List; @@ -16,4 +18,7 @@ public interface UserClient { @GetMapping("/users/role") UserInfoResponse getStudent(@RequestParam(value = "roleName", required = false) String role); + + @GetMapping("/users/id/{userId}") + UserInfoElement getUserInfoByUserId(@PathVariable("userId") UUID userId); } From 324da7884cfcae754eb7f030d8a9bfbe6e4316a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A0=95=ED=98=B8?= Date: Thu, 7 Sep 2023 13:14:24 +0900 Subject: [PATCH 08/14] =?UTF-8?q?=F0=9F=93=91=20::=20UserNotFoundException?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v1servicefeed/user/error/UserErrorCode.java | 4 +++- .../user/exception/UserNotFoundException.java | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 feed-domain/src/main/java/com/xquare/v1servicefeed/user/exception/UserNotFoundException.java diff --git a/feed-domain/src/main/java/com/xquare/v1servicefeed/user/error/UserErrorCode.java b/feed-domain/src/main/java/com/xquare/v1servicefeed/user/error/UserErrorCode.java index d14fa8f0..1e16a6ba 100644 --- a/feed-domain/src/main/java/com/xquare/v1servicefeed/user/error/UserErrorCode.java +++ b/feed-domain/src/main/java/com/xquare/v1servicefeed/user/error/UserErrorCode.java @@ -11,7 +11,9 @@ public enum UserErrorCode implements ExceptionProperty { FORBIDDEN_USER(403, "Forbidden User"), - INVALID_ROLE(403, "Invalid Role"); + INVALID_ROLE(403, "Invalid Role"), + + USER_NOT_FOUND(404, "User Not Found"); private final int status; private final String message; diff --git a/feed-domain/src/main/java/com/xquare/v1servicefeed/user/exception/UserNotFoundException.java b/feed-domain/src/main/java/com/xquare/v1servicefeed/user/exception/UserNotFoundException.java new file mode 100644 index 00000000..66946f59 --- /dev/null +++ b/feed-domain/src/main/java/com/xquare/v1servicefeed/user/exception/UserNotFoundException.java @@ -0,0 +1,14 @@ +package com.xquare.v1servicefeed.user.exception; + +import com.xquare.v1servicefeed.error.FeedException; +import com.xquare.v1servicefeed.user.error.UserErrorCode; + +public class UserNotFoundException extends FeedException { + + public static final FeedException EXCEPTION = + new UserNotFoundException(); + + private UserNotFoundException() { + super(UserErrorCode.USER_NOT_FOUND); + } +} From ec14fc7c14884d6b44f2ad87da0410ad95531ae8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A0=95=ED=98=B8?= Date: Thu, 7 Sep 2023 13:14:45 +0900 Subject: [PATCH 09/14] =?UTF-8?q?=E2=9A=A1=EF=B8=8F=20::=20=EC=95=84?= =?UTF-8?q?=EC=9D=B4=EB=94=94=EB=A1=9C=20=EC=82=AC=EC=9A=A9=EC=9E=90=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=A1=B0=ED=9A=8C=20API=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 --- .../v1servicefeed/user/spi/FeedUserSpi.java | 3 +++ .../repository/UserRepositoryAdapter.java | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/feed-domain/src/main/java/com/xquare/v1servicefeed/user/spi/FeedUserSpi.java b/feed-domain/src/main/java/com/xquare/v1servicefeed/user/spi/FeedUserSpi.java index e035cee7..9e959b05 100644 --- a/feed-domain/src/main/java/com/xquare/v1servicefeed/user/spi/FeedUserSpi.java +++ b/feed-domain/src/main/java/com/xquare/v1servicefeed/user/spi/FeedUserSpi.java @@ -5,6 +5,7 @@ import com.xquare.v1servicefeed.user.role.UserRole; import java.util.List; +import java.util.Optional; import java.util.UUID; @Spi @@ -12,4 +13,6 @@ public interface FeedUserSpi { List queryUserByIds(List ids); void validateUserId(UUID userId, UUID currentUserId); List queryAllUserByRole(String role); + + Optional queryUserById(UUID id); } diff --git a/feed-infrastructure/src/main/java/com/xquare/v1servicefeed/user/domain/repository/UserRepositoryAdapter.java b/feed-infrastructure/src/main/java/com/xquare/v1servicefeed/user/domain/repository/UserRepositoryAdapter.java index 57a35924..280daa1d 100644 --- a/feed-infrastructure/src/main/java/com/xquare/v1servicefeed/user/domain/repository/UserRepositoryAdapter.java +++ b/feed-infrastructure/src/main/java/com/xquare/v1servicefeed/user/domain/repository/UserRepositoryAdapter.java @@ -10,6 +10,7 @@ import org.springframework.stereotype.Component; import java.util.List; +import java.util.Optional; import java.util.UUID; @RequiredArgsConstructor @@ -69,4 +70,23 @@ public List queryAllUserByRole(String role) { .build()) .toList(); } + + @Override + public Optional queryUserById(UUID id) { + UserInfoElement userInfoElement = userClient.getUserInfoByUserId(id); + + return Optional.of( + User.builder() + .id(userInfoElement.getId()) + .accountId(userInfoElement.getAccountId()) + .name(userInfoElement.getName()) + .password(userInfoElement.getPassword()) + .birthDay(userInfoElement.getBirthDay()) + .grade(userInfoElement.getGrade()) + .classNum(userInfoElement.getClassNum()) + .num(userInfoElement.getNum()) + .profileFileName(userInfoElement.getProfileFileName()) + .build() + ); + } } From 93990a09974ee99724dd64bcc61e71f39808b3c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A0=95=ED=98=B8?= Date: Thu, 7 Sep 2023 13:15:05 +0900 Subject: [PATCH 10/14] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20=EB=8B=A8?= =?UTF-8?q?=EC=9D=BC=20=EC=95=84=EC=9D=B4=EB=94=94=EB=A1=9C=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EC=A1=B0=ED=9A=8C=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v1servicefeed/report/api/impl/ReportApiImpl.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/feed-domain/src/main/java/com/xquare/v1servicefeed/report/api/impl/ReportApiImpl.java b/feed-domain/src/main/java/com/xquare/v1servicefeed/report/api/impl/ReportApiImpl.java index c39e478b..c1d831db 100644 --- a/feed-domain/src/main/java/com/xquare/v1servicefeed/report/api/impl/ReportApiImpl.java +++ b/feed-domain/src/main/java/com/xquare/v1servicefeed/report/api/impl/ReportApiImpl.java @@ -10,14 +10,12 @@ import com.xquare.v1servicefeed.report.exception.CannotReportMyFeedException; import com.xquare.v1servicefeed.report.spi.CommandReportSpi; import com.xquare.v1servicefeed.user.User; +import com.xquare.v1servicefeed.user.exception.UserNotFoundException; import com.xquare.v1servicefeed.user.spi.FeedUserSpi; import com.xquare.v1servicefeed.webhook.SlackReport; import com.xquare.v1servicefeed.webhook.spi.SendWebhookSpi; import lombok.RequiredArgsConstructor; -import java.util.List; -import java.util.UUID; - @RequiredArgsConstructor @DomainService public class ReportApiImpl implements ReportApi { @@ -31,16 +29,16 @@ public class ReportApiImpl implements ReportApi { @Override public void saveReport(CreateReportDomainRequest request) { Feed feed = queryFeedSpi.queryFeedById(request.getFeedId()); - UUID userId = securitySpi.getCurrentUserId(); - User user = feedUserSpi.queryUserByIds(List.of(userId)).get(0); + User user = feedUserSpi.queryUserById(securitySpi.getCurrentUserId()) + .orElseThrow(() -> UserNotFoundException.EXCEPTION); - if (userId.equals(feed.getUserId())) { + if (user.getId().equals(feed.getUserId())) { throw CannotReportMyFeedException.EXCEPTION; } commandReportSpi.saveReport( Report.builder() - .userId(userId) + .userId(user.getId()) .reportUserId(feed.getUserId()) .feedId(feed.getId()) .content(request.getContent()) From c8899c6a8d9d67c71117749bfd0da847b35b4864 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A0=95=ED=98=B8?= Date: Thu, 7 Sep 2023 15:16:17 +0900 Subject: [PATCH 11/14] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20=ED=95=84?= =?UTF-8?q?=EC=9A=94=EC=97=86=EB=8A=94=20=EA=B3=B5=EB=B0=B1=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/xquare/v1servicefeed/user/spi/FeedUserSpi.java | 1 - 1 file changed, 1 deletion(-) diff --git a/feed-domain/src/main/java/com/xquare/v1servicefeed/user/spi/FeedUserSpi.java b/feed-domain/src/main/java/com/xquare/v1servicefeed/user/spi/FeedUserSpi.java index 9e959b05..f2c0ca1b 100644 --- a/feed-domain/src/main/java/com/xquare/v1servicefeed/user/spi/FeedUserSpi.java +++ b/feed-domain/src/main/java/com/xquare/v1servicefeed/user/spi/FeedUserSpi.java @@ -13,6 +13,5 @@ public interface FeedUserSpi { List queryUserByIds(List ids); void validateUserId(UUID userId, UUID currentUserId); List queryAllUserByRole(String role); - Optional queryUserById(UUID id); } From 288f386896b517952ef6484bba0533b952ed1bf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A0=95=ED=98=B8?= Date: Sat, 9 Sep 2023 15:25:46 +0900 Subject: [PATCH 12/14] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20=ED=95=84?= =?UTF-8?q?=EC=9A=94=EC=97=86=EB=8A=94=20=EC=A4=84=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v1servicefeed/report/domain/mapper/ReportMapperImpl.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/feed-infrastructure/src/main/java/com/xquare/v1servicefeed/report/domain/mapper/ReportMapperImpl.java b/feed-infrastructure/src/main/java/com/xquare/v1servicefeed/report/domain/mapper/ReportMapperImpl.java index 0cce8d90..f333c727 100644 --- a/feed-infrastructure/src/main/java/com/xquare/v1servicefeed/report/domain/mapper/ReportMapperImpl.java +++ b/feed-infrastructure/src/main/java/com/xquare/v1servicefeed/report/domain/mapper/ReportMapperImpl.java @@ -5,12 +5,11 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; - @RequiredArgsConstructor @Component public class ReportMapperImpl implements ReportMapper { - public Report entityToDomain(ReportEntity reportEntity) { + public Report entityToDomain(ReportEntity reportEntity) { return Report.builder() .id(reportEntity.getId()) .userId(reportEntity.getUserId()) @@ -21,7 +20,6 @@ public Report entityToDomain(ReportEntity reportEntity) { } public ReportEntity domainToEntity(Report report) { - return ReportEntity.builder() .id(report.getId()) .userId(report.getUserId()) From aa7511d51be466331ddb42094e0347b5ee2e90fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A0=95=ED=98=B8?= Date: Sat, 9 Sep 2023 15:57:43 +0900 Subject: [PATCH 13/14] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20EventListener?= =?UTF-8?q?=20=EA=B5=AC=EC=A1=B0=EB=A1=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...pter.java => SendWebhookEventListener.java} | 12 +++++------- .../webhook/SendWebhookEventPublisher.java | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 7 deletions(-) rename feed-infrastructure/src/main/java/com/xquare/v1servicefeed/webhook/{SendWebhookAdapter.java => SendWebhookEventListener.java} (82%) create mode 100644 feed-infrastructure/src/main/java/com/xquare/v1servicefeed/webhook/SendWebhookEventPublisher.java diff --git a/feed-infrastructure/src/main/java/com/xquare/v1servicefeed/webhook/SendWebhookAdapter.java b/feed-infrastructure/src/main/java/com/xquare/v1servicefeed/webhook/SendWebhookEventListener.java similarity index 82% rename from feed-infrastructure/src/main/java/com/xquare/v1servicefeed/webhook/SendWebhookAdapter.java rename to feed-infrastructure/src/main/java/com/xquare/v1servicefeed/webhook/SendWebhookEventListener.java index d483d3a9..ec1f6999 100644 --- a/feed-infrastructure/src/main/java/com/xquare/v1servicefeed/webhook/SendWebhookAdapter.java +++ b/feed-infrastructure/src/main/java/com/xquare/v1servicefeed/webhook/SendWebhookEventListener.java @@ -1,30 +1,28 @@ package com.xquare.v1servicefeed.webhook; -import com.xquare.v1servicefeed.webhook.spi.SendWebhookSpi; -import lombok.RequiredArgsConstructor; import net.gpedro.integrations.slack.SlackApi; import net.gpedro.integrations.slack.SlackAttachment; import net.gpedro.integrations.slack.SlackMessage; import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.event.EventListener; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; -@RequiredArgsConstructor @Component -public class SendWebhookAdapter implements SendWebhookSpi { +public class SendWebhookEventListener { private static final String REPORT_MESSAGE = "피드 신고 발생"; private static final String REPORT_USER_NAME = "신고자"; private static final String REPORT_CONTENT = "신고 내용"; - private static final String REPORT_FEED_CONTENT = "신고한 게시글 내용"; + private static final String REPORT_FEED_CONTENT = "신고된 게시글 내용"; private static final String MESSAGE_COLOR = "#9650FA"; - private static final String FALLBACK = "Required plain-text summary of the attachment"; + private static final String FALLBACK = "새로운 피드 신고가 도착했습니다."; @Value("${webhook.url}") private String webhookUrl; - @Override @Async + @EventListener public void sendReportToSlack(SlackReport slackReport) { SlackAttachment slackAttachment = createSlackAttachment(slackReport); SlackMessage slackMessage = new SlackMessage("").addAttachments(slackAttachment); diff --git a/feed-infrastructure/src/main/java/com/xquare/v1servicefeed/webhook/SendWebhookEventPublisher.java b/feed-infrastructure/src/main/java/com/xquare/v1servicefeed/webhook/SendWebhookEventPublisher.java new file mode 100644 index 00000000..2fe70812 --- /dev/null +++ b/feed-infrastructure/src/main/java/com/xquare/v1servicefeed/webhook/SendWebhookEventPublisher.java @@ -0,0 +1,18 @@ +package com.xquare.v1servicefeed.webhook; + +import com.xquare.v1servicefeed.webhook.spi.SendWebhookSpi; +import lombok.RequiredArgsConstructor; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.stereotype.Component; + +@RequiredArgsConstructor +@Component +public class SendWebhookEventPublisher implements SendWebhookSpi { + + private final ApplicationEventPublisher applicationEventPublisher; + + @Override + public void sendReportToSlack(SlackReport slackReport) { + applicationEventPublisher.publishEvent(slackReport); + } +} From 0f88bfea9a320d916d6439fa7127fd6c817fe23a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=A0=95=ED=98=B8?= Date: Sat, 9 Sep 2023 15:57:53 +0900 Subject: [PATCH 14/14] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20import=20?= =?UTF-8?q?=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../v1servicefeed/feed/web/WebFeedAdapter.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/feed-infrastructure/src/main/java/com/xquare/v1servicefeed/feed/web/WebFeedAdapter.java b/feed-infrastructure/src/main/java/com/xquare/v1servicefeed/feed/web/WebFeedAdapter.java index 0330c75a..8bbbcd91 100644 --- a/feed-infrastructure/src/main/java/com/xquare/v1servicefeed/feed/web/WebFeedAdapter.java +++ b/feed-infrastructure/src/main/java/com/xquare/v1servicefeed/feed/web/WebFeedAdapter.java @@ -3,7 +3,11 @@ import com.xquare.v1servicefeed.feed.api.FeedApi; import com.xquare.v1servicefeed.feed.api.dto.request.DomainCreateFeedRequest; import com.xquare.v1servicefeed.feed.api.dto.request.DomainUpdateFeedRequest; -import com.xquare.v1servicefeed.feed.api.dto.response.*; +import com.xquare.v1servicefeed.feed.api.dto.response.FeedCategoryListResponse; +import com.xquare.v1servicefeed.feed.api.dto.response.FeedListPageResponse; +import com.xquare.v1servicefeed.feed.api.dto.response.FeedListResponse; +import com.xquare.v1servicefeed.feed.api.dto.response.FeedWeakElement; +import com.xquare.v1servicefeed.feed.api.dto.response.SaveFeedResponse; import com.xquare.v1servicefeed.feed.web.dto.request.WebCreateFeedRequest; import com.xquare.v1servicefeed.feed.web.dto.request.WebUpdateFeedRequest; import com.xquare.v1servicefeed.report.api.ReportApi; @@ -12,7 +16,15 @@ import lombok.RequiredArgsConstructor; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PatchMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; import javax.validation.Valid; import java.time.LocalDateTime;