-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #231 from PawWithU/feat/223-delete-withdraw-api
[Feature] 모집자 회원 탈퇴 API 구현
- Loading branch information
Showing
9 changed files
with
107 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,10 +7,16 @@ | |
import com.pawwithu.connectdog.domain.auth.dto.response.*; | ||
import com.pawwithu.connectdog.domain.badge.repository.VolunteerBadgeRepository; | ||
import com.pawwithu.connectdog.domain.bookmark.repository.BookmarkRepository; | ||
import com.pawwithu.connectdog.domain.dogStatus.repository.DogStatusImageRepository; | ||
import com.pawwithu.connectdog.domain.dogStatus.repository.DogStatusRepository; | ||
import com.pawwithu.connectdog.domain.fcm.repository.IntermediaryFcmRepository; | ||
import com.pawwithu.connectdog.domain.fcm.repository.VolunteerFcmRepository; | ||
import com.pawwithu.connectdog.domain.intermediary.entity.Intermediary; | ||
import com.pawwithu.connectdog.domain.intermediary.repository.IntermediaryRepository; | ||
import com.pawwithu.connectdog.domain.notification.repository.IntermediaryNotificationRepository; | ||
import com.pawwithu.connectdog.domain.notification.repository.VolunteerNotificationRepository; | ||
import com.pawwithu.connectdog.domain.post.entity.Post; | ||
import com.pawwithu.connectdog.domain.post.repository.PostRepository; | ||
import com.pawwithu.connectdog.domain.review.entity.Review; | ||
import com.pawwithu.connectdog.domain.review.repository.ReviewRepository; | ||
import com.pawwithu.connectdog.domain.volunteer.entity.SocialType; | ||
|
@@ -52,6 +58,11 @@ public class AuthService { | |
private final IntermediaryFcmRepository intermediaryFcmRepository; | ||
private final BookmarkRepository bookmarkRepository; | ||
private final VolunteerBadgeRepository volunteerBadgeRepository; | ||
private final PostRepository postRepository; | ||
private final IntermediaryNotificationRepository intermediaryNotificationRepository; | ||
private final VolunteerNotificationRepository volunteerNotificationRepository; | ||
private final DogStatusRepository dogStatusRepository; | ||
private final DogStatusImageRepository dogStatusImageRepository; | ||
|
||
public void volunteerSignUp(VolunteerSignUpRequest request) { | ||
|
||
|
@@ -173,7 +184,7 @@ public void volunteersWithdraw(HttpServletRequest request, String email) { | |
volunteerFcmRepository.deleteByVolunteerId(volunteer.getId()); | ||
redisUtil.setBlackList(accessToken, "accessToken", jwtService.getAccessTokenExpirationPeriod()); | ||
|
||
Volunteer deletedVolunteer = volunteerRepository.findByEmail("deleted@connectdog.com").orElseThrow(() -> new BadRequestException(VOLUNTEER_NOT_FOUND)); | ||
Volunteer deletedVolunteer = volunteerRepository.findByEmail("deletedVolunteer@connectdog.com").orElseThrow(() -> new BadRequestException(VOLUNTEER_NOT_FOUND)); | ||
List<Review> reviews = reviewRepository.findByVolunteer(volunteer); | ||
for (Review review : reviews) { | ||
review.updateDeletedVolunteer(deletedVolunteer); | ||
|
@@ -188,13 +199,48 @@ public void volunteersWithdraw(HttpServletRequest request, String email) { | |
|
||
bookmarkRepository.deleteByVolunteerId(volunteer.getId()); | ||
volunteerBadgeRepository.deleteByVolunteerId(volunteer.getId()); | ||
volunteerNotificationRepository.deleteByVolunteerId(volunteer.getId()); | ||
volunteerFcmRepository.deleteByVolunteerId(volunteer.getId()); | ||
volunteerRepository.delete(volunteer); | ||
} catch (Exception e) { | ||
log.error("봉사자 탈퇴 도중에 에러가 발생했습니다. {}", e.getMessage()); | ||
throw new BadRequestException(VOLUNTEER_WITHDRAW_FAILED); | ||
} | ||
} | ||
|
||
public void intermediariesWithdraw(HttpServletRequest request, String email) { | ||
String accessToken = jwtService.extractAccessToken(request).orElseThrow(() -> new BadRequestException(TOKEN_NOT_EXIST)); | ||
Intermediary intermediary = intermediaryRepository.findByEmail(email).orElseThrow(() -> new BadRequestException(INTERMEDIARY_NOT_FOUND)); | ||
String roleName = jwtService.extractRoleName(accessToken).orElseThrow(() -> new BadRequestException(NOT_FOUND_ROLE_NAME)); | ||
|
||
try { | ||
redisUtil.delete(roleName, intermediary.getId()); | ||
volunteerFcmRepository.deleteByVolunteerId(intermediary.getId()); | ||
redisUtil.setBlackList(accessToken, "accessToken", jwtService.getAccessTokenExpirationPeriod()); | ||
|
||
Intermediary deletedIntermediary = intermediaryRepository.findByEmail("[email protected]").orElseThrow(() -> new BadRequestException(INTERMEDIARY_NOT_FOUND)); | ||
|
||
List<Post> posts = postRepository.findByIntermediary(intermediary); | ||
for (Post post : posts) { | ||
post.updateDeletedIntermediary(deletedIntermediary); | ||
} | ||
|
||
List<Application> applications = applicationRepository.findByIntermediary(intermediary); | ||
for (Application application : applications) { | ||
application.updateDeletedIntermediary(deletedIntermediary); | ||
} | ||
|
||
entityManager.flush(); | ||
|
||
intermediaryNotificationRepository.deleteByIntermediaryId(intermediary.getId()); | ||
intermediaryFcmRepository.deleteByIntermediaryId(intermediary.getId()); | ||
intermediaryRepository.delete(intermediary); | ||
} catch (Exception e) { | ||
log.error("모집자 탈퇴 도중에 에러가 발생했습니다. {}", e.getMessage()); | ||
throw new BadRequestException(INTERMEDIARY_WITHDRAW_FAILED); | ||
} | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public IntermediaryNameResponse isIntermediaryNameDuplicated(IntermediaryNameRequest request) { | ||
Boolean isDuplicated = intermediaryRepository.existsByName(request.name()); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
src/main/java/com/pawwithu/connectdog/domain/post/repository/PostRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
package com.pawwithu.connectdog.domain.post.repository; | ||
|
||
import com.pawwithu.connectdog.domain.intermediary.entity.Intermediary; | ||
import com.pawwithu.connectdog.domain.post.entity.Post; | ||
import com.pawwithu.connectdog.domain.post.entity.PostStatus; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface PostRepository extends JpaRepository<Post, Long> { | ||
|
||
Optional<Post> findByIdAndIntermediaryId(Long id, Long intermediaryId); | ||
Optional<Post> findByIdAndStatus(Long id, PostStatus postStatus); | ||
|
||
List<Post> findByIntermediary(Intermediary intermediary); | ||
} |
Oops, something went wrong.