-
Notifications
You must be signed in to change notification settings - Fork 3
[MEDI-121] refactor: delete all user's info #132
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
base: develop
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -19,4 +19,6 @@ public interface ProposalRepository extends JpaRepository<Proposal, Long> { | |
| where u.id in :userIds | ||
| """) | ||
| List<Proposal> findAllByUserIdInWithUser(@Param("userIds") Set<Long> userIds); | ||
|
|
||
| void deleteByUserId(Long userId); | ||
|
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유저당 Proposal 단건 가정 확인 및 반환형(long)으로 변경 권장 위쪽에 - void deleteByUserId(Long userId);
+ long deleteByUserId(Long userId);또한 유니크 제약(예: 유니크 제약 및 매핑을 점검하려면: 🏁 Script executed: #!/bin/bash
# Proposal ↔ User 매핑과 unique 제약 흔적 검색
rg -nP -C3 '(class\s+Proposal\b|@OneToOne|@ManyToOne|@JoinColumn|unique\s*=\s*true)' --type=java
# 마이그레이션/DDL에서 proposal.user_id 유니크/인덱스 확인
rg -nP -i -C2 '(create\s+unique\s+index|unique\s*\(|add\s+constraint).*proposal.*user_id' -g 'src/**/*.{sql,yml,xml}'Length of output: 14213 Proposal 삭제 메서드 반환 타입 변경 및 유니크 제약 확인/추가 필요 현재 아래 조치를 권장드립니다:
- void deleteByUserId(Long userId);
+ long deleteByUserId(Long userId);
위 개선 사항은 데이터 무결성 강화를 위해 필수적으로 반영하는 것을 권장드립니다. 🤖 Prompt for AI Agents |
||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -39,4 +39,8 @@ SELECT MAX(r3.id) | |||||
| ) | ||||||
| """) | ||||||
| List<UserLatestReportStatusDto> findLatestReportStatusByUserIds(@Param("userIds") Set<Long> userIds); | ||||||
|
|
||||||
| List<Long> findIdsByUserId(Long userId); | ||||||
|
|
||||||
| void deleteAllByUserId(Long userId); | ||||||
|
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 inconclusive벌크 삭제 주의사항 + 삭제 건수 반환(long)으로 변경 권장
- void deleteAllByUserId(Long userId);
+ long deleteAllByUserId(Long userId);성능 관점에서 인덱스/제약을 점검하려면: 🏁 Script executed: #!/bin/bash
# 마이그레이션 파일에서 report.user_id 인덱스/외래키/온딜리트 검색
rg -nPi -C2 '(create\s+index|add\s+constraint|foreign\s+key|on\s+delete\s+cascade).*report.*user_id' -g 'src/**/**/*.{sql,yml,xml}'Length of output: 133 다음 스크립트로 저장소 전체의 SQL/YAML/XML 마이그레이션 파일을 다시 검색하여 🏁 Script executed: #!/bin/bash
# 전역 검색: report.user_id 인덱스/제약/ON DELETE CASCADE 확인
rg -nPi -C2 '(create\s+index|add\s+constraint|foreign\s+key|on\s+delete\s+cascade).*report.*user_id' \
-g '*.sql' -g '*.xml' -g '*.yml' -g '*.yaml'Length of output: 147 리턴 타입 변경 및 인덱스·제약 검토 필요
📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,15 @@ | ||
| package com.my_medi.domain.user.service; | ||
| import com.my_medi.api.member.dto.RegisterMemberDto; | ||
|
|
||
| import com.my_medi.domain.advice.repository.AdviceRepository; | ||
| import com.my_medi.domain.consultationRequest.repository.ConsultationRequestRepository; | ||
| import com.my_medi.domain.member.entity.Role; | ||
| import com.my_medi.api.user.dto.UpdateUserDto; | ||
| import com.my_medi.domain.notification.repository.UserNotificationRepository; | ||
| import com.my_medi.domain.proposal.repository.ProposalRepository; | ||
| import com.my_medi.domain.report.repository.ReportRepository; | ||
| import com.my_medi.domain.reportResult.repository.ReportResultRepository; | ||
| import com.my_medi.domain.schedule.repository.ScheduleRepository; | ||
| import com.my_medi.domain.user.entity.User; | ||
| import com.my_medi.domain.user.repository.UserRepository; | ||
| import com.my_medi.domain.user.exception.UserHandler; | ||
|
|
@@ -11,6 +18,7 @@ | |
| import org.springframework.security.crypto.password.PasswordEncoder; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| import java.util.List; | ||
| import java.util.UUID; | ||
|
|
||
| @Service | ||
|
|
@@ -20,6 +28,13 @@ public class UserCommandServiceImpl implements UserCommandService { | |
|
|
||
| private final UserRepository userRepository; | ||
| private final PasswordEncoder passwordEncoder; | ||
| private final AdviceRepository adviceRepository; | ||
| private final ConsultationRequestRepository consultationRequestRepository; | ||
| private final UserNotificationRepository userNotificationRepository; | ||
| private final ProposalRepository proposalRepository; | ||
| private final ReportRepository reportRepository; | ||
| private final ReportResultRepository reportResultRepository; | ||
| private final ScheduleRepository scheduleRepository; | ||
|
|
||
| @Override | ||
| public Long registerUser(RegisterMemberDto registerMemberDto){ | ||
|
|
@@ -52,9 +67,19 @@ public Long updateUserInformation(Long userId, UpdateUserDto dto) { | |
| public Long deleteUserAccount(Long userId) { | ||
| User user = userRepository.findById(userId) | ||
| .orElseThrow(() -> UserHandler.NOT_FOUND); | ||
|
|
||
| adviceRepository.deleteByUserId(userId); | ||
| consultationRequestRepository.deleteByUserId(userId); | ||
| userNotificationRepository.deleteByUserId(userId); | ||
| proposalRepository.deleteByUserId(userId); | ||
|
|
||
| reportResultRepository.deleteAllByUserId(userId); | ||
|
Contributor
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. 이 method 제대로 실행되는지 테스트 부탁드립니다. reportResult는 리포트와 oneToOne 매핑이라서 이 메서드가 정확한지 불분명하다고 판단됩니다 |
||
| reportRepository.deleteAllByUserId(userId); | ||
|
|
||
| scheduleRepository.deleteAllByUserId(userId); | ||
|
|
||
| userRepository.delete(user); // TODO : Hard delete이나 추후 soft로 변경예정 | ||
| return user.getId(); | ||
| } | ||
|
|
||
| } | ||
|
|
||
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.
💡 Verification agent
🧩 Analysis chain
파생 삭제 쿼리의 프로퍼티 경로 확인 필요 (userId vs user.id)
deleteByUserId(Long userId)가 올바로 동작하려면 Advice 엔티티에 실제 필드명이userId여야 합니다. 연관매핑으로User user만 있고 PK를 통해 접근하는 구조라면deleteByUser_Id(Long userId)가 맞습니다. 아래 스크립트로 엔티티 정의를 확인해 주세요.🏁 Script executed:
Length of output: 110324
AdviceRepository의 삭제 메소드명 수정 필요
Advice 엔티티에 실제로는
userId필드가 없고,@ManyToOne으로 매핑된User user속성만 존재합니다. Spring Data JPA의 파생 쿼리는 엔티티 프로퍼티명을 기준으로 이름을 해석하므로, 현재 정의된는 올바르게 동작하지 않습니다. 대신
user.id경로를 지정하려면 메소드명을deleteByUser_Id로 변경해야 합니다.– 대상 파일
• src/main/java/com/my_medi/domain/advice/repository/AdviceRepository.java line 14
– 변경 전
- void deleteByUserId(Long userId);– 변경 후
+ void deleteByUser_Id(Long userId);이렇게 수정하면
Advice엔티티의user.id값을 기준으로 모든 관련 레코드를 삭제하도록 파생 쿼리가 올바르게 생성됩니다.🤖 Prompt for AI Agents