Skip to content

Commit

Permalink
Merge pull request #99 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 081071f + ec8e112 commit bbd9a3e
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 1 deletion.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ dependencies {

// Social Login
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign:4.1.0'

// Slack
implementation 'com.slack.api:slack-api-client:1.29.0'
}

tasks.named('bootBuildImage') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.extern.slf4j.Slf4j;
import org.pingle.pingleserver.dto.common.ApiResponse;
import org.pingle.pingleserver.dto.type.ErrorMessage;
import org.pingle.pingleserver.utils.SlackUtil;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.HttpMessageNotReadableException;
Expand Down Expand Up @@ -86,6 +87,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);
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 @@ -15,6 +15,7 @@
import org.pingle.pingleserver.oauth.service.KakaoLoginService;
import org.pingle.pingleserver.repository.UserRepository;
import org.pingle.pingleserver.utils.JwtUtil;
import org.pingle.pingleserver.utils.SlackUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand Down Expand Up @@ -78,6 +79,7 @@ private User loadOrCreateUser(Provider provider, SocialInfoDto socialInfo){
.role(URole.USER)
.build();
userRepository.save(newUser);
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 @@ -12,6 +12,7 @@
import org.pingle.pingleserver.exception.CustomException;
import org.pingle.pingleserver.repository.MeetingRepository;
import org.pingle.pingleserver.repository.UserMeetingRepository;
import org.pingle.pingleserver.utils.SlackUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -30,7 +31,7 @@ public class MeetingService {

@Transactional
public Meeting createMeeting(MeetingRequest request, Pin pin) {
return meetingRepository.save(
Meeting savedMeeting = meetingRepository.save(
Meeting.builder()
.pin(pin)
.category(request.category())
Expand All @@ -40,6 +41,8 @@ public Meeting createMeeting(MeetingRequest request, Pin pin) {
.startAt(request.startAt())
.endAt(request.endAt())
.build());
SlackUtil.alertCreateMeeting(request.location(), request.name());
return savedMeeting;
}

public ParticipantsResponse getParticipants(Long meetingId) {
Expand Down
72 changes: 72 additions & 0 deletions src/main/java/org/pingle/pingleserver/utils/SlackUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package org.pingle.pingleserver.utils;

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 java.io.IOException;
import java.util.Arrays;

public class SlackUtil {

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

public static WebhookResponse 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;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static WebhookResponse 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;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static WebhookResponse 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;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public static WebhookResponse 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;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

0 comments on commit bbd9a3e

Please sign in to comment.