Skip to content

Commit

Permalink
Merge pull request #272 from Hous-Release/fix/#271
Browse files Browse the repository at this point in the history
#271 [fix] 탈퇴 유저 알림 슬랙에 의견 추가
  • Loading branch information
hyejungg authored Dec 16, 2022
2 parents dd367b7 + 0918a42 commit 6d56bab
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/main/java/hous/server/controller/user/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ public ResponseEntity<SuccessResponse<String>> updateRepresentBadge(@ApiIgnore @
@Auth
@DeleteMapping("/user")
public ResponseEntity<SuccessResponse<String>> deleteUser(@ApiIgnore @UserId Long userId,
@RequestBody DeleteUserRequestDto request) {
@Valid @RequestBody DeleteUserRequestDto request) {
userService.deleteUser(request, userId);
slackService.sendSlackMessageDeleteUser(userRetrieveService.getFeedback());
slackService.sendSlackMessageDeleteUser(userRetrieveService.getFeedback(request.getComment()));
return SuccessResponse.OK;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hous/server/service/slack/SlackService.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class SlackService {
private static final String ATTACHMENTS_NOTIFICATION_COLOR = "#36a64f";

public void sendSlackMessageDeleteUser(UserDeleteResponse userDeleteResponse) {
if (!profile.equals(LOCAL) && userDeleteResponse.getTotalDeleteUserList().isEmpty()) {
if (!profile.equals(LOCAL) && !userDeleteResponse.getTotalDeleteUserList().isEmpty()) {
try {
Slack slack = Slack.getInstance();
List<LayoutBlock> layoutBlocks = SlackServiceUtils.createUserDeleteMessage(userDeleteResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class SlackServiceUtils {
private static final String FILTER_STRING = "hous.server";
private static final String PROD_USER_DELETE_TOTAL_COUNT_MESSAGE = "*피드백을 남긴 총 탈퇴 인원:* ";
private static final String PROD_USER_DELETE_MESSAGE = "*피드백 유형별 탈퇴 인원:*\n";
private static final String PROD_NOW_USER_DELETE_COMMENT = "*지금 탈퇴한 유저의 의견:*\n";

public static List<Attachment> createAttachments(String color, List<LayoutBlock> data) {
List<Attachment> attachments = new ArrayList<>();
Expand All @@ -42,6 +43,12 @@ public static List<LayoutBlock> createUserDeleteMessage(UserDeleteResponse userD
}
layoutBlockList.add(section(section ->
section.text(markdownText(PROD_USER_DELETE_MESSAGE + stringBuilder.toString()))));

if (userDeleteResponse.getComment() != null) {
layoutBlockList.add(section(section ->
section.text(markdownText(PROD_NOW_USER_DELETE_COMMENT + userDeleteResponse.getComment()))));
}

return layoutBlockList;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,27 @@ public class UserDeleteResponse {

private long totalDeleteUserCount;
private List<UserDelete> totalDeleteUserList;
private String comment;

public static UserDeleteResponse of(long totalDeleteUserCount, List<UserDelete> users) {
public static UserDeleteResponse of(long totalDeleteUserCount, List<UserDelete> users, String comment) {
if (comment == null) {
return UserDeleteResponse.builder()
.totalDeleteUserCount(totalDeleteUserCount)
.totalDeleteUserList(users.stream()
.map(user -> UserDelete.of(user.getCount(), user.getFeedbackType()))
.sorted(Comparator.comparing(userDelete -> userDelete.getFeedbackType().length()))
.collect(Collectors.toList())
)
.build();
}
return UserDeleteResponse.builder()
.totalDeleteUserCount(totalDeleteUserCount)
.totalDeleteUserList(users.stream()
.map(user -> UserDelete.of(user.getCount(), user.getFeedbackType()))
.sorted(Comparator.comparing(userDelete -> userDelete.getFeedbackType().length()))
.collect(Collectors.toList())
)
.comment(comment)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public MyBadgeInfoResponse getMyBadgeList(Long userId) {
return MyBadgeInfoResponse.of(represent, badges, myBadges, newBadges);
}

public UserDeleteResponse getFeedback() {
public UserDeleteResponse getFeedback(String comment) {
Map<FeedbackType, List<Feedback>> users = feedbackRepository.findAll().stream()
.collect(Collectors.groupingBy(Feedback::getFeedbackType));
List<UserDelete> userDeletes = new ArrayList<>();
Expand All @@ -109,7 +109,7 @@ public UserDeleteResponse getFeedback() {
totalCount += users.get(feedbackType).size();
userDeletes.add(UserDelete.of(users.get(feedbackType).size(), feedbackType.getValue()));
}
return UserDeleteResponse.of(totalCount, userDeletes);
return UserDeleteResponse.of(totalCount, userDeletes, comment);
}

private UserInfoResponse getProfileInfoByUser(User user) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/hous/server/service/user/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public void deleteUser(DeleteUserRequestDto request, Long userId) {
RoomServiceUtils.deleteParticipateUser(participateRepository, roomRepository, me, room, participate);
}

if (!request.getFeedbackType().equals(FeedbackType.NO) && request.getComment() != null) {
if (!(request.getFeedbackType().equals(FeedbackType.NO) && request.getComment() == null)) {
feedbackRepository.save(Feedback.newInstance(request.getFeedbackType(), request.getComment()));
}
userRepository.delete(user);
Expand Down

0 comments on commit 6d56bab

Please sign in to comment.