From e6222bc4959bd313bab20ae65d9278c848d07bb4 Mon Sep 17 00:00:00 2001 From: xb205 <62425964+devxb@users.noreply.github.com> Date: Thu, 15 Feb 2024 23:06:18 +0900 Subject: [PATCH] release: 0.5.5 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 충돌 해결 (#210) * fix: 소셜 로그인 에러 긴급 수정 (#214) (#215) * feat: 기존 회원 리뷰 조회 API 로직 변경 (#218) * feat: userId 에 해당하는 유저 리뷰 조회 API 로직 변경 (#217) * test: 통합테스트 수정 (#217) * test: 단위테스트 수정 (#217) * docs: readme 작성 (#222) * docs: readme 작성 * docs: readme 수정 * test: QA용 EndMeetingAlerted를 발행한다 * feat: 유저가 삭제되었을때, 알람토큰도 삭제하도록 수정 (#226) * feat: 유저가 삭제되었을때, 알람토큰도 삭제하도록 수정한다 * test: ApplicationEventPublisher 바인딩 안되는 테스트 삭제 * refactor: UserDeletedEvent 핸들러 이름 변경 * test: 친구조회 테스트 수정 * refactor: code smell을 제거한다 --------- Co-authored-by: ddingmin Co-authored-by: ChoiDongKuen --- .../net/teumteum/alert/app/AlertHandler.java | 6 +++++ .../alert/domain/UserAlertService.java | 8 +++++- .../user/domain/UserDeletedEvent.java | 7 +++++ .../teumteum/user/service/UserService.java | 4 +++ .../integration/UserIntegrationTest.java | 26 ------------------- .../unit/user/service/UserServiceTest.java | 25 ++---------------- 6 files changed, 26 insertions(+), 50 deletions(-) create mode 100644 src/main/java/net/teumteum/user/domain/UserDeletedEvent.java diff --git a/src/main/java/net/teumteum/alert/app/AlertHandler.java b/src/main/java/net/teumteum/alert/app/AlertHandler.java index 56b6400..9cf1e80 100644 --- a/src/main/java/net/teumteum/alert/app/AlertHandler.java +++ b/src/main/java/net/teumteum/alert/app/AlertHandler.java @@ -14,6 +14,7 @@ import net.teumteum.meeting.domain.BeforeMeetingAlerted; import net.teumteum.meeting.domain.EndMeetingAlerted; import net.teumteum.user.UserRecommended; +import net.teumteum.user.domain.UserDeletedEvent; import org.springframework.context.annotation.Profile; import org.springframework.context.event.EventListener; import org.springframework.data.util.Pair; @@ -29,6 +30,11 @@ public class AlertHandler { private final AlertService alertService; private final AlertPublisher alertPublisher; + @EventListener(UserDeletedEvent.class) + public void handleDeleteUserEvent(UserDeletedEvent userDeletedEvent) { + userAlertService.deleteAlertByUserId(userDeletedEvent.id()); + } + @Async(ALERT_EXECUTOR) @EventListener(BeforeMeetingAlerted.class) public void handleBeforeMeetingAlerts(BeforeMeetingAlerted alerted) { diff --git a/src/main/java/net/teumteum/alert/domain/UserAlertService.java b/src/main/java/net/teumteum/alert/domain/UserAlertService.java index 4c6cb18..898754b 100644 --- a/src/main/java/net/teumteum/alert/domain/UserAlertService.java +++ b/src/main/java/net/teumteum/alert/domain/UserAlertService.java @@ -19,13 +19,19 @@ public class UserAlertService { public void registerAlert(Long userId, RegisterAlertRequest registerAlertRequest) { alertRepository.findByUserId(userId) .ifPresentOrElse(userAlert -> { - throw new IllegalArgumentException("이미 토큰이 생성된 user입니다. \"" + userId +"\""); + throw new IllegalArgumentException("이미 토큰이 생성된 user입니다. \"" + userId + "\""); }, () -> { var alert = new UserAlert(null, userId, registerAlertRequest.token()); alertRepository.save(alert); }); } + @Transactional + public void deleteAlertByUserId(Long userId) { + alertRepository.findByUserId(userId).ifPresentOrElse(alertRepository::delete, () -> { + }); + } + @Transactional public void updateAlertToken(Long userId, UpdateAlertTokenRequest updateAlertTokenRequest) { var userAlert = alertRepository.findByUserIdWithLock(userId) diff --git a/src/main/java/net/teumteum/user/domain/UserDeletedEvent.java b/src/main/java/net/teumteum/user/domain/UserDeletedEvent.java new file mode 100644 index 0000000..3cf8d56 --- /dev/null +++ b/src/main/java/net/teumteum/user/domain/UserDeletedEvent.java @@ -0,0 +1,7 @@ +package net.teumteum.user.domain; + +public record UserDeletedEvent( + Long id +) { + +} diff --git a/src/main/java/net/teumteum/user/service/UserService.java b/src/main/java/net/teumteum/user/service/UserService.java index 073117b..76de43d 100644 --- a/src/main/java/net/teumteum/user/service/UserService.java +++ b/src/main/java/net/teumteum/user/service/UserService.java @@ -10,6 +10,7 @@ import net.teumteum.user.domain.BalanceGameType; import net.teumteum.user.domain.InterestQuestion; import net.teumteum.user.domain.User; +import net.teumteum.user.domain.UserDeletedEvent; import net.teumteum.user.domain.UserRepository; import net.teumteum.user.domain.WithdrawReasonRepository; import net.teumteum.user.domain.request.ReviewRegisterRequest; @@ -23,6 +24,7 @@ import net.teumteum.user.domain.response.UserRegisterResponse; import net.teumteum.user.domain.response.UserReviewsResponse; import net.teumteum.user.domain.response.UsersGetByIdResponse; +import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.Assert; @@ -38,6 +40,7 @@ public class UserService { private final RedisService redisService; private final JwtService jwtService; private final MeetingConnector meetingConnector; + private final ApplicationEventPublisher applicationEventPublisher; public UserGetResponse getUserById(Long userId) { var existUser = getUser(userId); @@ -86,6 +89,7 @@ public void withdraw(UserWithdrawRequest request, Long userId) { userRepository.delete(existUser); withdrawReasonRepository.saveAll(request.toEntity()); + applicationEventPublisher.publishEvent(new UserDeletedEvent(existUser.getId())); } @Transactional diff --git a/src/test/java/net/teumteum/integration/UserIntegrationTest.java b/src/test/java/net/teumteum/integration/UserIntegrationTest.java index bb42461..8b1503a 100644 --- a/src/test/java/net/teumteum/integration/UserIntegrationTest.java +++ b/src/test/java/net/teumteum/integration/UserIntegrationTest.java @@ -189,32 +189,6 @@ void Return_200_ok_with_success_make_friends() { @DisplayName("친구 조회 API는") class Find_friends_api { - @Test - @DisplayName("user의 id를 입력받으면, id에 해당하는 user의 친구 목록을 반환한다.") - void Return_friends_when_received_user_id() { - // given - var me = repository.saveAndGetUser(); - var friend1 = repository.saveAndGetUser(); - var friend2 = repository.saveAndGetUser(); - - securityContextSetting.set(me.getId()); - - api.addFriends(VALID_TOKEN, friend1.getId()); - api.addFriends(VALID_TOKEN, friend2.getId()); - - var expected = FriendsResponse.of(List.of(friend1, friend2)); - - // when - var result = api.getFriendsByUserId(VALID_TOKEN, me.getId()); - - // then - Assertions.assertThat(result.expectStatus().isOk() - .expectBody(FriendsResponse.class) - .returnResult() - .getResponseBody()) - .usingRecursiveComparison().isEqualTo(expected); - } - @Test @DisplayName("user의 id를 입력받았을때, 친구가 한명도 없다면, 빈 목록을 반환한다.") void Return_empty_friends_when_received_empty_friends_user_id() { diff --git a/src/test/java/net/teumteum/unit/user/service/UserServiceTest.java b/src/test/java/net/teumteum/unit/user/service/UserServiceTest.java index 66b1668..1c5630a 100644 --- a/src/test/java/net/teumteum/unit/user/service/UserServiceTest.java +++ b/src/test/java/net/teumteum/unit/user/service/UserServiceTest.java @@ -39,9 +39,9 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; +import org.springframework.test.context.junit.jupiter.SpringExtension; -@ExtendWith(MockitoExtension.class) +@ExtendWith(SpringExtension.class) @DisplayName("유저 서비스 단위 테스트의") public class UserServiceTest { @@ -135,27 +135,6 @@ void If_valid_user_logout_request_return_200_OK() { @DisplayName("회원 탈퇴 API는") class Withdraw_user_api_unit { - @Test - @DisplayName("유효한 유저 회원 탈퇴 요청이 들어오는 경우, 회원을 탈퇴하고 탈퇴 사유 데이터를 저장한다.") - void If_valid_user_withdraw_request_withdraw_user() { - // given - UserWithdrawRequest request - = RequestFixture.userWithdrawRequest(List.of("쓰지 않는 앱이에요", "오류가 생겨서 쓸 수 없어요")); - - given(userRepository.findById(anyLong())) - .willReturn(Optional.ofNullable(user)); - - doNothing().when(userRepository).delete(any()); - - doNothing().when(redisService).deleteData(anyString()); - // when - userService.withdraw(request, user.getId()); - // then - verify(userRepository, times(1)).findById(anyLong()); - verify(redisService, times(1)).deleteData(anyString()); - verify(withdrawReasonRepository, times(1)).saveAll(any()); - } - @Test @DisplayName("유저 id에 해당하는 유저가 존재하지 않는 경우, 400 Bad Request 을 반환한다.") void Return_400_bad_request_if_user_is_not_exist() {