-
Notifications
You must be signed in to change notification settings - Fork 0
[Feat] 방 나가기 api 개발 #267
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] 방 나가기 api 개발 #267
Changes from all commits
4f22def
83a97a8
7914706
a9c968c
300098a
cbb1f5f
e96fb5d
472ad2f
f493c75
ec231b5
24c5d2e
aada109
ddb1cc3
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,5 @@ | ||
| package konkuk.thip.room.application.port.in; | ||
|
|
||
| public interface RoomParticipantDeleteUseCase { | ||
| Void leaveRoom(Long userId, Long roomId); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package konkuk.thip.room.application.service; | ||
|
|
||
| import konkuk.thip.room.application.port.in.RoomParticipantDeleteUseCase; | ||
| import konkuk.thip.room.application.port.out.RoomCommandPort; | ||
| import konkuk.thip.room.application.port.out.RoomParticipantCommandPort; | ||
| import konkuk.thip.room.domain.Room; | ||
| import konkuk.thip.room.domain.RoomParticipant; | ||
| import konkuk.thip.roompost.application.service.manager.RoomProgressManager; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class RoomParticipantDeleteService implements RoomParticipantDeleteUseCase { | ||
|
|
||
| private final RoomCommandPort roomCommandPort; | ||
| private final RoomParticipantCommandPort roomParticipantCommandPort; | ||
|
|
||
| private final RoomProgressManager roomProgressManager; | ||
|
|
||
| @Override | ||
| @Transactional | ||
| public Void leaveRoom(Long userId, Long roomId) { | ||
|
|
||
| // 1. 방 조회 및 검증 | ||
| Room room = roomCommandPort.getByIdOrThrow(roomId); | ||
|
|
||
| // 2. 사용자가 방 참여자인지 확인 | ||
| RoomParticipant roomParticipant = roomParticipantCommandPort.getByUserIdAndRoomIdOrThrow(userId, room.getId()); | ||
| // 2-1. 방 나가기 권한 검증 | ||
| roomParticipant.validateRoomLeavable(); | ||
|
|
||
| // 3. 방 멤버수 감소 / 방 진행률 업데이트 | ||
| roomProgressManager.removeUserProgressAndUpdateRoomProgress(roomParticipant.getId(), room); | ||
|
|
||
| // 4. 방나가기 | ||
| roomParticipantCommandPort.deleteByUserIdAndRoomId(userId, room.getId()); | ||
| return null; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,6 +41,7 @@ public Long deleteVote(VoteDeleteCommand command) { | |
| // 3-3. 투표 삭제 | ||
| voteCommandPort.delete(vote); | ||
|
|
||
| //TODO// 4. 유저 방 진행도 업데이트 | ||
| return command.roomId(); | ||
|
Comment on lines
+44
to
45
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투표 삭제 시 진행도 누락: TODO를 실제 로직으로 연결해 주세요 투표 삭제가 사용자/방 진행도 산정에 영향이 있다면, 현재 상태에서는 진행도가 갱신되지 않아 불일치가 발생할 수 있습니다. 본 PR의 목표(방 나가기)와 직접적 연관이 적더라도, 최소한 TODO를 추적 가능한 이슈로 전환하거나 실제 RoomProgressManager 연동을 추가하는 편이 안전합니다. 원하시면 RoomProgressManager 연동 패턴(주입, 트랜잭션 전후 위치, 예외 전파 기준)에 맞춰 구체 구현 스케치를 드리겠습니다. 다음 스크립트로 현재 코드베이스에 진행도 관련 매니저/메서드가 어떤 것이 있는지 빠르게 확인할 수 있습니다: 🏁 Script executed: #!/bin/bash
# 진행도 매니저 및 관련 메서드 탐색
rg -n -C3 'class\s+RoomProgressManager\b|RoomProgressManager|progress' --type=java
# 삭제/감소류 메서드 단서 탐색
rg -n -C2 -e 'remove.*Progress|update.*Progress|decrease.*Progress' --type=javaLength of output: 43585 🏁 Script executed: #!/bin/bash
# Locate VoteDeleteService and display context around TODO
rg -n -C3 'class\s\+VoteDeleteService' --type=java
# Show lines 1–80 of VoteDeleteService for full context
sed -n '1,80p' src/main/java/konkuk/thip/roompost/application/service/VoteDeleteService.javaLength of output: 1872 투표 삭제 후 진행도 업데이트 로직 누락 – RoomProgressManager 연결 필요
위 변경을 통해 “TODO”를 추적 가능한 실제 이슈로 전환하거나 즉시 반영하여 방 진행도 일관성을 보장해 주세요. 🤖 Prompt for AI Agents |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,5 @@ | ||
| package konkuk.thip.roompost.application.service.manager; | ||
|
|
||
| import konkuk.thip.book.application.port.out.BookCommandPort; | ||
| import konkuk.thip.book.domain.Book; | ||
| import konkuk.thip.common.annotation.HelperService; | ||
| import konkuk.thip.room.application.port.out.RoomCommandPort; | ||
|
|
@@ -17,19 +16,14 @@ public class RoomProgressManager { | |
|
|
||
| private final RoomParticipantCommandPort roomParticipantCommandPort; | ||
| private final RoomCommandPort roomCommandPort; | ||
| private final BookCommandPort bookCommandPort; | ||
|
|
||
| public void updateUserAndRoomProgress(Long userId, Long roomId, int currentPage) { | ||
| RoomParticipant roomParticipant = roomParticipantCommandPort.getByUserIdAndRoomIdOrThrow(userId, roomId); | ||
| Room room = roomCommandPort.getByIdOrThrow(roomId); | ||
| Book book = bookCommandPort.findById(room.getBookId()); | ||
|
|
||
| public void updateUserAndRoomProgress(RoomParticipant roomParticipant, Room room, Book book, int currentPage) { | ||
| // 1. 유저 진행률 update | ||
| boolean updated = roomParticipant.updateUserProgress(currentPage, book.getPageCount()); | ||
| if (!updated) return; // update 되지 않았으면 종료 | ||
|
|
||
| // 2. 방 평균 진행률 update | ||
| List<RoomParticipant> all = roomParticipantCommandPort.findAllByRoomId(roomId); | ||
| List<RoomParticipant> all = roomParticipantCommandPort.findAllByRoomId(room.getId()); | ||
| double total = all.stream() | ||
| .filter(p -> !roomParticipant.getId().equals(p.getId())) // 현재 유저 제외 | ||
| .mapToDouble(RoomParticipant::getUserPercentage) | ||
|
|
@@ -41,4 +35,21 @@ public void updateUserAndRoomProgress(Long userId, Long roomId, int currentPage) | |
| roomCommandPort.update(room); | ||
| roomParticipantCommandPort.update(roomParticipant); | ||
| } | ||
|
|
||
| public void removeUserProgressAndUpdateRoomProgress(Long removeRoomParticipantId, Room room) { | ||
|
|
||
| // 나간 유저를 제외한 방 평균 진행률 update | ||
| List<RoomParticipant> remainingParticipants = roomParticipantCommandPort.findAllByRoomId(room.getId()); | ||
| double total = remainingParticipants.stream() | ||
| .filter(p -> !p.getId().equals(removeRoomParticipantId)) // 나간 유저 제외 | ||
| .mapToDouble(RoomParticipant::getUserPercentage) | ||
| .sum(); | ||
| room.updateRoomPercentage(total / (remainingParticipants.size() - 1)); | ||
|
|
||
| // 방 멤버 수 감소 | ||
| room.decreaseMemberCount(); | ||
| // 영속화 | ||
| roomCommandPort.update(room); | ||
|
Comment on lines
+49
to
+52
Collaborator
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. 굳굳 |
||
| } | ||
|
|
||
| } | ||
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.
LGTM