-
Notifications
You must be signed in to change notification settings - Fork 1
refactor: SNS controller, service 계층 리팩토링 #102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Walkthrough이번 변경 사항은 컨트롤러와 서비스 계층에서 SNS(Discord, Slack) 연동 및 메시지 전송 로직을 대폭 리팩토링하여, 컨트롤러의 책임을 단순화하고 서비스 계층에서 외부 API 통신과 SNS 정보 저장을 일원화했습니다. 각 컨트롤러는 더 이상 RestTemplate이나 DTO 변환, 직접적인 SNS 정보 저장을 다루지 않고, 서비스의 고수준 메서드만 호출합니다. 서비스 계층에서는 RestTemplate 호출, 응답 파싱, 예외 처리 등을 SnsService로 위임하여 코드 재사용성과 캡슐화를 높였습니다. 또한, 각종 메서드 시그니처 변경 및 접근제어자 조정이 이뤄졌습니다. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Controller
participant Service
participant SnsService
participant ExternalAPI
User->>Controller: SNS 연동 요청 (코드 등 전달)
Controller->>Service: initialize[Discord|Slack]ChannelAndSaveSnsInfo(user, code)
Service->>SnsService: sendRestTemplateExchange(토큰 요청)
SnsService->>ExternalAPI: OAuth 토큰 요청
ExternalAPI-->>SnsService: 토큰 응답
SnsService-->>Service: 파싱된 토큰/유저ID 등
Service->>SnsService: createSns(Sns)
SnsService-->>Service: 저장 완료
Service->>SnsService: sendRestTemplateExchange(DM 전송)
SnsService->>ExternalAPI: DM 메시지 전송
ExternalAPI-->>SnsService: 전송 결과
SnsService-->>Service: 결과 반환
Service-->>Controller: 완료 응답
Controller-->>User: 결과 반환
Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (5)
🚧 Files skipped from review as they are similar to previous changes (5)
⏰ Context from checks skipped due to timeout of 90000ms (1)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 5
🧹 Nitpick comments (12)
.gitignore (1)
39-41: 추가 macOS 아티팩트 무시 고려 제안
.DS_Store외에도.AppleDouble,.LSOverride같은 macOS 관련 임시 파일을 무시 목록에 포함하면 더 완벽한 무시 설정이 될 수 있습니다.src/main/java/com/Alchive/backend/controller/SlackController.java (1)
3-7: 사용되지 않는 SnsService import 제거
SnsService를 더 이상 사용하지 않으므로 import 를 남겨두면 컴파일 경고가 발생합니다.-import com.Alchive.backend.service.SnsService;src/main/java/com/Alchive/backend/controller/DiscordController.java (1)
3-7: 불필요한 SnsService import 제거SlackController와 동일하게
SnsServiceimport 가 사용되지 않습니다.-import com.Alchive.backend.service.SnsService;src/main/java/com/Alchive/backend/service/SnsService.java (1)
36-40: RestTemplate 직접 생성 대신 Bean 주입 권장
new RestTemplate()를 필드에 직접 생성하면 커스텀 타임아웃, 인터셉터, 로깅 등을 설정하기 어렵고 테스트 시 Mock 주입도 힘듭니다.- private RestTemplate restTemplate = new RestTemplate(); + private final RestTemplate restTemplate; + + public SnsService(SnsReporitory snsReporitory, RestTemplateBuilder builder) { + this.snsReporitory = snsReporitory; + this.restTemplate = builder.build(); + }스프링 빈으로 주입받으면 공통 설정을 중앙에서 관리할 수 있습니다.
src/main/java/com/Alchive/backend/service/SlackService.java (4)
27-31: 중복 애너테이션 제거 권장
@Service와@Configuration을 동시에 선언할 필요가 없습니다.
@Service만으로 빈 등록이 충분하며,@Configuration은 오히려 의미상 혼동을 줄 수 있습니다.
불필요한 애너테이션을 제거하여 의도를 명확히 해 주세요.
44-46: 사용되지 않는 필드 정리
slackBotToken필드는 선언만 되고 실제로 사용되지 않습니다.
불필요한 필드는 삭제하거나 사용 목적이 있다면 코드에 반영해 주세요.
69-82: 제네릭 타입 명시 및 타입 세이프티 개선
ResponseEntity<Map>은 raw Map 사용으로 인해 캐스팅 오류 가능성이 있습니다.
JacksonObjectNode또는Map<String, Object>로 명시하여 타입 안정성을 높여 주세요.
85-88: 변수명-로직 불일치
threeDaysAgo라는 변수명이 실제로는minusDays(1)을 사용합니다.
의도한 기간(1일 vs 3일)을 확인한 뒤 변수명 또는 로직을 맞춰 주세요.src/main/java/com/Alchive/backend/service/DiscordService.java (4)
50-54: 메서드명 오타
initializeDiscordChannleAndSaveSnsInfo→initializeDiscordChannelAndSaveSnsInfo
철자 오류는 IDE 자동 검색·호출에 영향을 주므로 조속히 수정해 주세요.
81-88:HttpEntity제네릭 타입 부적절
HttpEntity<String> request = new HttpEntity<>(accessTokenHeaders);는 body가 없으므로
HttpEntity<Void>또는HttpEntity<Object>가 의미상 더 명확합니다.
작동에는 문제 없지만 가독성 차원에서 타입 수정을 권장합니다.
103-106: 변수명-로직 불일치
threeDaysAgo변수는 실제로minusDays(1)을 사용합니다.
SlackService와 동일한 문제로, 기간 값과 변수명을 일치시켜 주세요.
147-153: JDA 블로킹 호출 주의
retrieveUserById(...).complete()는 REST 요청을 동기 블로킹으로 수행합니다.
대량 호출 시 스레드 점유 및 지연이 발생할 수 있으므로
queue()콜백 사용이나 별도 스케줄러로 비동기 처리를 검토해 주세요.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
.DS_Storeis excluded by!**/.DS_Store
📒 Files selected for processing (8)
.gitignore(1 hunks)src/main/java/com/Alchive/backend/controller/BoardController.java(0 hunks)src/main/java/com/Alchive/backend/controller/DiscordController.java(1 hunks)src/main/java/com/Alchive/backend/controller/SlackController.java(1 hunks)src/main/java/com/Alchive/backend/controller/SnsController.java(2 hunks)src/main/java/com/Alchive/backend/service/DiscordService.java(3 hunks)src/main/java/com/Alchive/backend/service/SlackService.java(4 hunks)src/main/java/com/Alchive/backend/service/SnsService.java(2 hunks)
💤 Files with no reviewable changes (1)
- src/main/java/com/Alchive/backend/controller/BoardController.java
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/main/java/com/Alchive/backend/service/SlackService.java (1)
src/main/java/com/Alchive/backend/config/error/exception/sns/NoSuchSnsIdException.java (1)
NoSuchSnsIdException(6-8)
src/main/java/com/Alchive/backend/service/DiscordService.java (1)
src/main/java/com/Alchive/backend/config/error/exception/sns/NoSuchSnsIdException.java (1)
NoSuchSnsIdException(6-8)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: build
🔇 Additional comments (3)
.gitignore (1)
39-41: Mac OS 메타데이터 파일 무시 추가 – 적절합니다
.DS_Store항목을 추가하여 macOS에서 자동 생성되는 디렉터리 메타데이터 파일을 Git 관리 대상에서 제외한 것은 좋은 관행입니다.src/main/java/com/Alchive/backend/controller/SlackController.java (1)
28-30:Details
✅ Verification successful
모든 예외 상황에서 성공 코드 반환 위험
initializeSlackChannelAndSaveSnsInfo나sendSlackDm과정에서 예외가 발생해도 컨트롤러는 무조건200 OK와SLACK_DM_SEND_SUCCESS코드를 반환합니다. 서비스가 런타임 예외를 던지도록 설계됐다면@ExceptionHandler또는 글로벌 예외 처리기를 통해 HTTP 상태를 전달하도록 하거나, 메서드 내부에서 실패 여부를 체크한 뒤 적절한 응답 코드를 리턴해 주세요.Also applies to: 36-36
예외 처리 핸들러 존재 여부와
SlackService호출 방식 확인을 위해 아래 스크립트를 실행하겠습니다.
🏁 Script executed:
#!/bin/bash # 글로벌 예외 처리 핸들러 확인 rg "@ControllerAdvice" -A3 rg "@ExceptionHandler" -A3 # SlackController 클래스 확인 rg "class SlackController" -A3 src/main/java/com/Alchive/backend/controller/SlackController.java # SlackService 메서드 구현 위치 확인 rg "initializeSlackChannelAndSaveSnsInfo" -A2 src/main/java rg "sendSlackDm" -A2 src/main/javaLength of output: 3926
글로벌 예외 처리기로 SlackController 예외가 처리됨 확인됨
SlackService 호출 중 발생하는RuntimeException과BusinessException은GlobalExceptionHandler(@ControllerAdvice)에 정의된@ExceptionHandler가 적절한 HTTP 상태 코드(500 또는 비즈니스 에러 코드)로 변환하여 응답합니다.
따라서 컨트롤러 내부에 별도의 예외 처리 로직을 추가할 필요가 없습니다.src/main/java/com/Alchive/backend/service/SlackService.java (1)
102-116: DM 전송 방식 검토 필요Slack
chat.postMessageAPI에서channel파라미터에는 DM 채널 ID가 필요합니다.
현재 저장 중인 값이 User ID라면 메시지 전송이 실패할 수 있습니다.
Slack DM용 채널 ID(conversations.openAPI로 획득)를 저장·사용하는지 확인해 주세요.
Summary
Description
공통
controller
service
Screenshot
Test Checklist
@coderabbitai review
Summary by CodeRabbit
.DS_Store파일이 버전 관리에서 제외됩니다.