Skip to content

Commit 1d519e6

Browse files
committed
♻️ refactor: Slack 비동기 처리
1 parent 2f4add2 commit 1d519e6

File tree

3 files changed

+36
-25
lines changed

3 files changed

+36
-25
lines changed

src/main/java/com/example/Veco/domain/external/service/ExternalService.java

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
import com.example.Veco.domain.external.repository.ExternalCustomRepository;
1616
import com.example.Veco.domain.external.repository.ExternalRepository;
1717
import com.example.Veco.domain.github.service.GitHubIssueService;
18-
import com.example.Veco.domain.goal.converter.GoalConverter;
19-
import com.example.Veco.domain.goal.dto.request.GoalReqDTO;
20-
import com.example.Veco.domain.goal.dto.response.GoalResDTO;
2118
import com.example.Veco.domain.goal.entity.Goal;
2219
import com.example.Veco.domain.goal.repository.GoalRepository;
2320
import com.example.Veco.domain.mapping.Assignment;
@@ -28,9 +25,7 @@
2825
import com.example.Veco.domain.member.error.MemberErrorStatus;
2926
import com.example.Veco.domain.member.error.MemberHandler;
3027
import com.example.Veco.domain.member.repository.MemberRepository;
31-
import com.example.Veco.domain.slack.exception.SlackException;
32-
import com.example.Veco.domain.slack.exception.code.SlackErrorCode;
33-
import com.example.Veco.domain.slack.util.SlackUtil;
28+
import com.example.Veco.domain.slack.service.SlackCommandService;
3429
import com.example.Veco.domain.team.dto.NumberSequenceResponseDTO;
3530
import com.example.Veco.domain.team.entity.Team;
3631
import com.example.Veco.domain.team.exception.TeamException;
@@ -51,7 +46,6 @@
5146
import java.time.format.DateTimeParseException;
5247
import java.util.ArrayList;
5348
import java.util.List;
54-
import java.util.Optional;
5549
import java.util.stream.Collectors;
5650

5751
@Slf4j
@@ -72,11 +66,11 @@ public class ExternalService {
7266
private final AssigneeRepository assigneeRepository;
7367

7468
// 유틸
75-
private final SlackUtil slackUtil;
7669
private final CommentRoomRepository commentRoomRepository;
7770
private final GitHubIssueService gitHubIssueService;
7871
private final GitHubInstallationRepository githubInstallationRepository;
7972
private final CommentRepository commentRepository;
73+
private final SlackCommandService slackCommandService;
8074

8175
@Transactional
8276
public ExternalResponseDTO.CreateResponseDTO createExternal(Long teamId,
@@ -124,22 +118,7 @@ public ExternalResponseDTO.CreateResponseDTO createExternal(Long teamId,
124118
if(request.getExtServiceType() == ExtServiceType.GITHUB){
125119
gitHubIssueService.createGitHubIssue(request);
126120
} else if (request.getExtServiceType() == ExtServiceType.SLACK){
127-
// accessToken, DefaultChannelId, message
128-
// 연동 정보 조회
129-
com.example.Veco.domain.external.entity.ExternalService externalService =
130-
linkRepository.findLinkByWorkspaceAndExternalService_ServiceType(
131-
team.getWorkSpace(), ExtServiceType.SLACK)
132-
.orElseThrow(() -> new SlackException(SlackErrorCode.NOT_LINKED))
133-
.getExternalService();
134-
135-
String message = team.getName() + "에서 " +
136-
external.getTitle() + "을(를) 생성했습니다.";
137-
138-
slackUtil.PostSlackMessage(
139-
externalService.getAccessToken(),
140-
externalService.getSlackDefaultChannelId(),
141-
message
142-
);
121+
slackCommandService.sendSlackMessage(team, external);
143122
}
144123

145124
return ExternalConverter.createResponseDTO(external);

src/main/java/com/example/Veco/domain/slack/service/SlackCommandService.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.example.Veco.domain.slack.service;
22

33
import com.example.Veco.domain.external.converter.ExternalServiceConverter;
4+
import com.example.Veco.domain.external.entity.External;
45
import com.example.Veco.domain.external.entity.ExternalService;
56
import com.example.Veco.domain.external.repository.ExternalServiceRepository;
67
import com.example.Veco.domain.mapping.converter.LinkConverter;
@@ -14,6 +15,7 @@
1415
import com.example.Veco.domain.slack.exception.SlackException;
1516
import com.example.Veco.domain.slack.exception.code.SlackErrorCode;
1617
import com.example.Veco.domain.slack.util.SlackUtil;
18+
import com.example.Veco.domain.team.entity.Team;
1719
import com.example.Veco.domain.workspace.entity.WorkSpace;
1820
import com.example.Veco.global.auth.jwt.util.JwtUtil;
1921
import com.example.Veco.global.enums.ExtServiceType;
@@ -163,4 +165,34 @@ public Long installApp(
163165
// 기본 팀 ID로 리다이렉트
164166
return workspace.getTeams().getFirst().getId();
165167
}
168+
169+
// Slack 메시지 전송
170+
public void sendSlackMessage(
171+
Team team,
172+
External external
173+
) {
174+
// accessToken, DefaultChannelId, message
175+
// 연동 정보 조회
176+
com.example.Veco.domain.external.entity.ExternalService externalService =
177+
linkRepository.findLinkByWorkspaceAndExternalService_ServiceType(
178+
team.getWorkSpace(), ExtServiceType.SLACK)
179+
.orElseThrow(() -> new SlackException(SlackErrorCode.NOT_LINKED))
180+
.getExternalService();
181+
182+
String message = team.getName() + "에서 " +
183+
external.getTitle() + "을(를) 생성했습니다.";
184+
185+
SlackResDTO.PostSlackMessage result = slackUtil.PostSlackMessage(
186+
externalService.getAccessToken(),
187+
externalService.getSlackDefaultChannelId(),
188+
message
189+
);
190+
191+
if (!result.ok()){
192+
193+
// 로그
194+
log.error(result.error());
195+
throw new SlackException(SlackErrorCode.MESSAGE_POST_FAILED);
196+
}
197+
}
166198
}

src/main/java/com/example/Veco/domain/slack/util/SlackUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public SlackResDTO.JoinChannel joinChannel(
6464
.block();
6565
}
6666

67-
// 메시지 전송
67+
// 메시지 전송: Service에 따로 지정 -> 비동기
6868
public SlackResDTO.PostSlackMessage PostSlackMessage(
6969
String accessToken, String slackDefaultChannelId, String content
7070
){

0 commit comments

Comments
 (0)