Skip to content

Commit

Permalink
Merge pull request #103 from TeamPINGLE/develop
Browse files Browse the repository at this point in the history
DEPLOY
  • Loading branch information
tkdwns414 authored Jan 18, 2024
2 parents 261d6b5 + 627d054 commit 1243921
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.pingle.pingleserver.exception;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.pingle.pingleserver.dto.common.ApiResponse;
import org.pingle.pingleserver.dto.type.ErrorMessage;
Expand All @@ -19,8 +20,11 @@

@Slf4j
@RestControllerAdvice
@RequiredArgsConstructor
public class GlobalExceptionHandler {

private final SlackUtil slackUtil;

@ExceptionHandler(value = {MethodArgumentNotValidException.class})
public ResponseEntity<ApiResponse<?>> handlerMethodArgumentNotValidException(Exception e) {
log.error("handlerMethodArgumentNotValidException() in GlobalExceptionHandler throw MethodArgumentNotValidException : {}", e.getMessage());
Expand Down Expand Up @@ -87,7 +91,7 @@ public ResponseEntity<ApiResponse<?>> handleCustomException(CustomException e) {
@ExceptionHandler(Exception.class)
public ResponseEntity<ApiResponse<?>> handlerException(Exception e) {
log.error("handlerException() in GlobalExceptionHandler throw Exception : {} {}", e.getClass(), e.getMessage());
SlackUtil.alertError(e);
slackUtil.alertError(e);
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(ApiResponse.fail(ErrorMessage.INTERNAL_SERVER_ERROR));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
public class AuthService {

private final JwtUtil jwtUtil;
private final SlackUtil slackUtil;
private final AppleLoginService appleLoginService;
private final KakaoLoginService kakaoLoginService;
private final UserRepository userRepository;
Expand Down Expand Up @@ -79,7 +80,7 @@ private User loadOrCreateUser(Provider provider, SocialInfoDto socialInfo){
.role(URole.USER)
.build();
userRepository.save(newUser);
SlackUtil.alertUserSignUp(newUser.getName(), newUser.getEmail());
slackUtil.alertUserSignUp(newUser.getName(), newUser.getEmail());
}

return userRepository.findByProviderAndSerialIdAndIsDeleted(provider, socialInfo.serialId(), false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
@Transactional(readOnly = true)
public class MeetingService {

private final SlackUtil slackUtil;
private final MeetingRepository meetingRepository;
private final UserMeetingRepository userMeetingRepository;

Expand All @@ -41,7 +42,7 @@ public Meeting createMeeting(MeetingRequest request, Pin pin) {
.startAt(request.startAt())
.endAt(request.endAt())
.build());
SlackUtil.alertCreateMeeting(request.location(), request.name());
slackUtil.alertCreateMeeting(request.location(), request.name());
return savedMeeting;
}

Expand Down
33 changes: 12 additions & 21 deletions src/main/java/org/pingle/pingleserver/utils/SlackUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.slack.api.Slack;
import com.slack.api.webhook.Payload;
import com.slack.api.webhook.WebhookResponse;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

Expand All @@ -13,60 +12,52 @@
public class SlackUtil {

@Value("${slack.webhook.team-created}")
private static String teamCreatedWebhookUrl;
private String teamCreatedWebhookUrl;
@Value("${slack.webhook.user-join}")
private static String userJoinWebhookUrl;
private String userJoinWebhookUrl;
@Value("${slack.webhook.meeting-created}")
private static String meetingCreatedWebhookUrl;
private String meetingCreatedWebhookUrl;
@Value("${slack.webhook.server-error}")
private static String serverErrorWebhookUrl;
private String serverErrorWebhookUrl;

public static WebhookResponse alertUserSignUp (String name, String email) {
public void alertUserSignUp (String name, String email) {
try {
String text = name + "(" + email + ")" +"님이 가입했습니다.";
WebhookResponse response;
Slack slack = Slack.getInstance();
Payload payload = Payload.builder().text(text).build();
response = slack.send(userJoinWebhookUrl, payload);
return response;
slack.send(userJoinWebhookUrl, payload);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static WebhookResponse alertCreateTeam(String teamName) {
public void alertCreateTeam(String teamName) {
try {
String text = "팀 : " + teamName + "이 생성되었습니다.";
WebhookResponse response;
Slack slack = Slack.getInstance();
Payload payload = Payload.builder().text(text).build();
response = slack.send(teamCreatedWebhookUrl, payload);
return response;
slack.send(teamCreatedWebhookUrl, payload);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static WebhookResponse alertCreateMeeting(String location, String meetingName) {
public void alertCreateMeeting(String location, String meetingName) {
try {
String text = location + "에서" + meetingName + "번개가 생성되었습니다.";
WebhookResponse response;
Slack slack = Slack.getInstance();
Payload payload = Payload.builder().text(text).build();
response = slack.send(meetingCreatedWebhookUrl, payload);
return response;
slack.send(meetingCreatedWebhookUrl, payload);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static WebhookResponse alertError(Exception exception) {
public void alertError(Exception exception) {
try {
String text = exception.getClass().getName() + " "
+ exception.getMessage() + "\n"
+ Arrays.toString(exception.getStackTrace());
WebhookResponse response;
Slack slack = Slack.getInstance();
Payload payload = Payload.builder().text(text).build();
response = slack.send(serverErrorWebhookUrl, payload);
return response;
slack.send(serverErrorWebhookUrl, payload);
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down

0 comments on commit 1243921

Please sign in to comment.