-
Notifications
You must be signed in to change notification settings - Fork 0
[FEAT] 유저 즉시 삭제 API 구현 (#365) #367
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
Changes from all commits
3da2ce5
64217bd
4609b6f
7309419
586c877
95b1e5c
76851ed
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,69 @@ | ||
| package com.example.RealMatch.user.application.service; | ||
|
|
||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import com.example.RealMatch.brand.domain.repository.BrandLikeRepository; | ||
| import com.example.RealMatch.brand.domain.repository.BrandRepository; | ||
| import com.example.RealMatch.business.domain.repository.CampaignApplyRepository; | ||
| import com.example.RealMatch.business.domain.repository.CampaignProposalRepository; | ||
| import com.example.RealMatch.campaign.domain.repository.CampaignLikeRepository; | ||
| import com.example.RealMatch.global.exception.CustomException; | ||
| import com.example.RealMatch.match.domain.repository.MatchBrandHistoryRepository; | ||
| import com.example.RealMatch.match.domain.repository.MatchCampaignHistoryRepository; | ||
| import com.example.RealMatch.tag.domain.repository.TagUserRepository; | ||
| import com.example.RealMatch.user.domain.entity.User; | ||
| import com.example.RealMatch.user.domain.repository.AuthenticationMethodRepository; | ||
| import com.example.RealMatch.user.domain.repository.NotificationSettingRepository; | ||
| import com.example.RealMatch.user.domain.repository.UserContentCategoryRepository; | ||
| import com.example.RealMatch.user.domain.repository.UserRepository; | ||
| import com.example.RealMatch.user.domain.repository.UserSignupPurposeRepository; | ||
| import com.example.RealMatch.user.domain.repository.UserTermRepository; | ||
| import com.example.RealMatch.user.presentation.code.UserErrorCode; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class UserDeleteService { | ||
|
|
||
| private final UserRepository userRepository; | ||
| private final AuthenticationMethodRepository authenticationMethodRepository; | ||
| private final BrandRepository brandRepository; | ||
| private final BrandLikeRepository brandLikeRepository; | ||
| private final CampaignApplyRepository campaignApplyRepository; | ||
| private final CampaignLikeRepository campaignLikeRepository; | ||
| private final CampaignProposalRepository campaignProposalRepository; | ||
| private final MatchBrandHistoryRepository matchBrandHistoryRepository; | ||
| private final MatchCampaignHistoryRepository matchCampaignHistoryRepository; | ||
| private final NotificationSettingRepository notificationSettingRepository; | ||
| private final TagUserRepository tagUserRepository; | ||
| private final UserContentCategoryRepository userContentCategoryRepository; | ||
| private final UserSignupPurposeRepository userSignupPurposeRepository; | ||
| private final UserTermRepository userTermRepository; | ||
|
|
||
| @Transactional | ||
| public void deleteUserImmediately(Long userId) { | ||
| User user = userRepository.findById(userId) | ||
| .orElseThrow(() -> new CustomException(UserErrorCode.USER_NOT_FOUND)); | ||
|
|
||
| deleteRelatedData(userId); | ||
| userRepository.delete(user); | ||
| } | ||
|
|
||
| private void deleteRelatedData(Long userId) { | ||
| tagUserRepository.deleteByUserId(userId); | ||
| userContentCategoryRepository.deleteByUserId(userId); | ||
| userSignupPurposeRepository.deleteByUserId(userId); | ||
| userTermRepository.deleteByUserId(userId); | ||
| notificationSettingRepository.deleteByUserId(userId); | ||
| matchBrandHistoryRepository.deleteByUserId(userId); | ||
| matchCampaignHistoryRepository.deleteByUserId(userId); | ||
| brandLikeRepository.deleteByUserId(userId); | ||
| campaignLikeRepository.deleteByUserId(userId); | ||
| campaignApplyRepository.deleteByUserId(userId); | ||
| campaignProposalRepository.deleteByUserId(userId); | ||
| brandRepository.deleteByUserId(userId); | ||
| authenticationMethodRepository.deleteByUserId(userId); | ||
| } | ||
|
Comment on lines
+54
to
+68
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. 현재 유저 관련 데이터 삭제 구현이 불완전합니다. 특히, 유저가 'Brand'의 소유주일 경우, 해당 브랜드에 'Campaign'과 같은 다른 엔티티가 연결되어 있다면 66라인의 Swagger 문서에 이 가능성을 언급하셨지만, 애플리케이션 레벨에서 이 경우를 더 안정적으로 처리하는 것이 바람직합니다. 브랜드에 종속된 데이터를 먼저 삭제하거나, 삭제가 불가능한 경우 명확한 에러 메시지(예: 409 Conflict)를 반환하여 유저가 상황을 인지할 수 있도록 해야 합니다.
Contributor
Author
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. "이 API는 개발/테스트용 헬퍼로 실제 프로덕션에서는 사용되지 않습니다. 실제 서비스에서는 soft delete를 사용합니다." |
||
| } | ||
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.
리포지토리 메서드에 있는
@Transactional어노테이션은 중복되므로 제거하는 것이 좋습니다. 이 메서드를 호출하는UserDeleteService.deleteUserImmediately서비스 메서드에 이미@Transactional이 선언되어 있어, 해당 트랜잭션에 자동으로 참여하게 됩니다.트랜잭션 경계는 서비스 계층에서 관리하는 것으로 일관성을 유지하면 코드의 트랜잭션 동작을 더 명확하게 파악하고 관리할 수 있습니다.