-
Notifications
You must be signed in to change notification settings - Fork 8
feat: 채팅방 생성 기능 추가 #439
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
feat: 채팅방 생성 기능 추가 #439
Changes from all commits
aa8859a
3b089ea
763e699
0a821ca
f16cddc
1cd2390
cee0914
9cc36c9
c59a314
6648618
49ad525
72a3557
980be9f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package com.example.solidconnection.mentor.dto; | ||
|
|
||
| public record MentoringApprovedEvent( | ||
| long mentoringId, | ||
| long mentorId, | ||
| long menteeId | ||
| ) { | ||
|
|
||
| public static MentoringApprovedEvent of(long mentoringId, long mentorId, long menteeId) { | ||
| return new MentoringApprovedEvent(mentoringId, mentorId, menteeId); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,11 +11,13 @@ | |
| import com.example.solidconnection.mentor.domain.Mentoring; | ||
| import com.example.solidconnection.mentor.dto.MentoringApplyRequest; | ||
| import com.example.solidconnection.mentor.dto.MentoringApplyResponse; | ||
| import com.example.solidconnection.mentor.dto.MentoringApprovedEvent; | ||
| import com.example.solidconnection.mentor.dto.MentoringConfirmRequest; | ||
| import com.example.solidconnection.mentor.dto.MentoringConfirmResponse; | ||
| import com.example.solidconnection.mentor.repository.MentorRepository; | ||
| import com.example.solidconnection.mentor.repository.MentoringRepository; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.context.ApplicationEventPublisher; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
|
|
@@ -25,6 +27,7 @@ public class MentoringCommandService { | |
|
|
||
| private final MentoringRepository mentoringRepository; | ||
| private final MentorRepository mentorRepository; | ||
| private final ApplicationEventPublisher eventPublisher; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chain이벤트 처리의 트랜잭션 격리 의도와 실제 동작 일치 확인(승인 트랜잭션 영향 차단) 요구사항은 “채팅방 생성 실패가 멘토링 승인에 영향 주지 않음”입니다. 아래를 점검해 주세요. 예시(핵심 아이디어): 원하시면 MentoringEventHandler 예시 코드를 제안드리겠습니다. Also applies to: 54-55 아래 스크립트를 실행해 이벤트 핸들러 설정을 검증해 주세요.
🏁 Script executed: #!/bin/bash
rg "class MentoringEventHandler" -n src
rg "@EventListener" -n src
rg "@TransactionalEventListener" -n src
rg "@Async" -n src
rg "ChatService" -n srcLength of output: 1989 추가 검증을 위해 이벤트 핸들러 코드를 확인합니다. 🏁 Script executed: #!/bin/bash
sed -n '1,200p' src/main/java/com/example/solidconnection/mentor/service/MentoringEventHandler.javaLength of output: 1001 이벤트 핸들러 트랜잭션 격리 및 예외 처리 강화하기
🤖 Prompt for AI Agents |
||
|
|
||
| @Transactional | ||
| public MentoringApplyResponse applyMentoring(long siteUserId, MentoringApplyRequest mentoringApplyRequest) { | ||
|
|
@@ -48,6 +51,7 @@ public MentoringConfirmResponse confirmMentoring(long siteUserId, long mentoring | |
|
|
||
| if (mentoringConfirmRequest.status() == VerifyStatus.APPROVED) { | ||
| mentor.increaseMenteeCount(); | ||
| eventPublisher.publishEvent(MentoringApprovedEvent.of(mentoringId, mentor.getSiteUserId(), mentoring.getMenteeId())); | ||
| } | ||
|
|
||
| return MentoringConfirmResponse.from(mentoring); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package com.example.solidconnection.mentor.service; | ||
|
|
||
| import com.example.solidconnection.chat.service.ChatService; | ||
| import com.example.solidconnection.mentor.dto.MentoringApprovedEvent; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.scheduling.annotation.Async; | ||
| import org.springframework.stereotype.Component; | ||
| import org.springframework.transaction.annotation.Propagation; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
| import org.springframework.transaction.event.TransactionalEventListener; | ||
|
|
||
| @Component | ||
| @RequiredArgsConstructor | ||
| public class MentoringEventHandler { | ||
|
|
||
| private final ChatService chatService; | ||
|
|
||
| @Async | ||
| @Transactional(propagation = Propagation.REQUIRES_NEW) | ||
| @TransactionalEventListener | ||
| public void handleMentoringApproved(MentoringApprovedEvent event) { | ||
| chatService.createMentoringChatRoom(event.mentoringId(), event.mentorId(), event.menteeId()); | ||
| } | ||
|
Comment on lines
+18
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chain3) 멱등성/경쟁 상태 대비 여부 확인 부탁드립니다.
아래 스크립트로 구현 확인 가능해요(예외 처리 유무, existsByMentoringId 사용 여부): 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "[Search] createMentoringChatRoom 구현"
rg -n --no-heading "createMentoringChatRoom\\s*\\(" -A 40
echo
echo "[Search] 멘토링 채팅 UQ/예외 처리 흔적"
rg -n --no-heading "DataIntegrityViolationException|ConstraintViolationException|existsByMentoringId"Length of output: 4695 멱등성·경쟁 상태 보강 요청
🤖 Prompt for AI Agents |
||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,5 @@ | ||||||||
| ALTER TABLE chat_room | ||||||||
| ADD COLUMN mentoring_id BIGINT, | ||||||||
| ADD CONSTRAINT uk_chat_room_mentoring_id UNIQUE (mentoring_id), | ||||||||
| ADD CONSTRAINT fk_chat_room_mentoring_id FOREIGN KEY (mentoring_id) REFERENCES mentoring(id); | ||||||||
|
Comment on lines
+1
to
+4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent ❓ Verification inconclusive1) 운영 락/가용성: 온라인 DDL 전략으로 분리해 주세요.
-ALTER TABLE chat_room
- ADD COLUMN mentoring_id BIGINT,
- ADD CONSTRAINT uk_chat_room_mentoring_id UNIQUE (mentoring_id),
- ADD CONSTRAINT fk_chat_room_mentoring_id FOREIGN KEY (mentoring_id) REFERENCES mentoring(id);
+-- 1) 컬럼 추가
+ALTER TABLE chat_room ADD COLUMN mentoring_id BIGINT;
+
+-- 2) NULL 제외 부분 유니크 인덱스(온라인)
+CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS uk_chat_room_mentoring_id_notnull
+ ON chat_room (mentoring_id) WHERE mentoring_id IS NOT NULL;
+
+-- 3) FK는 즉시 검증하지 않고 등록(삭제 정책은 SET NULL 예시)
+ALTER TABLE chat_room
+ ADD CONSTRAINT fk_chat_room_mentoring_id
+ FOREIGN KEY (mentoring_id) REFERENCES mentoring(id) ON DELETE SET NULL
+ NOT VALID;
+
+-- 4) 트래픽 한가한 시점에 검증
+ALTER TABLE chat_room VALIDATE CONSTRAINT fk_chat_room_mentoring_id;-ALTER TABLE chat_room
- ADD COLUMN mentoring_id BIGINT,
- ADD CONSTRAINT uk_chat_room_mentoring_id UNIQUE (mentoring_id),
- ADD CONSTRAINT fk_chat_room_mentoring_id FOREIGN KEY (mentoring_id) REFERENCES mentoring(id);
+ALTER TABLE chat_room
+ ADD COLUMN mentoring_id BIGINT NULL,
+ ALGORITHM=INPLACE, LOCK=NONE;
+
+CREATE UNIQUE INDEX uk_chat_room_mentoring_id ON chat_room (mentoring_id)
+ ALGORITHM=INPLACE, LOCK=NONE;
+
+ALTER TABLE chat_room
+ ADD CONSTRAINT fk_chat_room_mentoring_id
+ FOREIGN KEY (mentoring_id) REFERENCES mentoring(id) ON DELETE SET NULL;
운영 가용성 최적화를 위한 온라인 DDL 단계 분리 제안
🤖 Prompt for AI AgentsThere was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent ❓ Verification inconclusive3) FK 삭제 정책 명시를 권장(도메인 의도에 맞게).
예시(SET NULL): -ADD CONSTRAINT fk_chat_room_mentoring_id FOREIGN KEY (mentoring_id) REFERENCES mentoring(id);
+ADD CONSTRAINT fk_chat_room_mentoring_id
+ FOREIGN KEY (mentoring_id) REFERENCES mentoring(id) ON DELETE SET NULL;외래키 삭제 정책 명시 요청 점검 위치:
워크스루:
-ADD CONSTRAINT fk_chat_room_mentoring_id FOREIGN KEY (mentoring_id) REFERENCES mentoring(id);
+ADD CONSTRAINT fk_chat_room_mentoring_id
+ FOREIGN KEY (mentoring_id) REFERENCES mentoring(id) ON DELETE SET NULL;위 제안 중 도메인 요구사항에 맞는 정책으로 수정 부탁드립니다. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package com.example.solidconnection.chat.repository; | ||
|
|
||
| import com.example.solidconnection.chat.domain.ChatRoom; | ||
| import java.util.Optional; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.data.jpa.repository.Query; | ||
| import org.springframework.data.repository.query.Param; | ||
|
|
||
| public interface ChatRoomRepositoryForTest extends JpaRepository<ChatRoom, Long> { | ||
|
|
||
| @Query(""" | ||
| SELECT DISTINCT cr FROM ChatRoom cr | ||
| LEFT JOIN FETCH cr.chatParticipants cp | ||
| WHERE cr.isGroup = false | ||
| AND EXISTS ( | ||
| SELECT 1 FROM ChatParticipant cp1 | ||
| WHERE cp1.chatRoom = cr AND cp1.siteUserId = :mentorId | ||
| ) | ||
| AND EXISTS ( | ||
| SELECT 1 FROM ChatParticipant cp2 | ||
| WHERE cp2.chatRoom = cr AND cp2.siteUserId = :menteeId | ||
| ) | ||
| AND ( | ||
| SELECT COUNT(cp3) FROM ChatParticipant cp3 | ||
| WHERE cp3.chatRoom = cr | ||
| ) = 2 | ||
| """) | ||
| Optional<ChatRoom> findOneOnOneChatRoomByParticipants(@Param("mentorId") long mentorId, @Param("menteeId") long menteeId); | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.