Skip to content
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

fix: fcm 토큰 삭제 기능 추가 #185

Merged
merged 15 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.moabam.api.dto.auth.AuthorizationTokenResponse;
import com.moabam.api.dto.auth.LoginResponse;
import com.moabam.api.dto.auth.TokenSaveValue;
import com.moabam.api.infrastructure.fcm.FcmService;
import com.moabam.global.auth.model.AuthMember;
import com.moabam.global.auth.model.PublicClaim;
import com.moabam.global.common.util.GlobalConstant;
Expand All @@ -41,6 +42,7 @@
@RequiredArgsConstructor
public class AuthorizationService {

private final FcmService fcmService;
private final OAuthConfig oAuthConfig;
private final TokenConfig tokenConfig;
private final OAuth2AuthorizationServerRequestService oauth2AuthorizationServerRequestService;
Expand Down Expand Up @@ -105,6 +107,7 @@ public void logout(AuthMember authMember, HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) {
removeToken(httpServletRequest, httpServletResponse);
tokenRepository.delete(authMember.id());
fcmService.deleteTokenByMemberId(authMember.id());
}

public void removeToken(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.moabam.api.dto.member.MemberInfoResponse;
import com.moabam.api.dto.member.MemberInfoSearchResponse;
import com.moabam.api.dto.member.ModifyMemberRequest;
import com.moabam.api.infrastructure.fcm.FcmService;
import com.moabam.global.auth.model.AuthMember;
import com.moabam.global.common.util.BaseDataCode;
import com.moabam.global.common.util.ClockHolder;
Expand All @@ -41,6 +42,7 @@
@RequiredArgsConstructor
public class MemberService {

private final FcmService fcmService;
private final MemberRepository memberRepository;
private final InventoryRepository inventoryRepository;
private final ItemRepository itemRepository;
Expand Down Expand Up @@ -83,6 +85,7 @@ public void delete(Member member) {
member.delete(clockHolder.times());
memberRepository.flush();
memberRepository.delete(member);
fcmService.deleteTokenByMemberId(member.getId());
}

public MemberInfoResponse searchInfo(AuthMember authMember, Long memberId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public void deportParticipant(Long managerId, Long roomId, Long memberId) {

Room room = managerParticipant.getRoom();
memberParticipant.removeRoom();
participantRepository.flush();
participantRepository.delete(memberParticipant);
room.decreaseCurrentUserCount();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
import com.google.firebase.messaging.Notification;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service
@RequiredArgsConstructor
public class FcmService {
Expand All @@ -24,9 +22,7 @@ public void createToken(String fcmToken, Long memberId) {
return;
}

log.info("FCM TOKEN before: " + fcmToken);
fcmRepository.saveToken(fcmToken, memberId);
log.info("FCM TOKEN after: " + findTokenByMemberId(memberId));
}

public void deleteTokenByMemberId(Long memberId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ protected void doFilterInternal(@NotNull HttpServletRequest httpServletRequest,
try {
invoke(httpServletRequest, httpServletResponse);
} catch (UnauthorizedException unauthorizedException) {
log.error("Login Failed");
authorizationService.removeToken(httpServletRequest, httpServletResponse);
handlerExceptionResolver.resolveException(httpServletRequest, httpServletResponse, null,
unauthorizedException);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.moabam.api.dto.auth.AuthorizationTokenRequest;
import com.moabam.api.dto.auth.AuthorizationTokenResponse;
import com.moabam.api.dto.auth.LoginResponse;
import com.moabam.api.infrastructure.fcm.FcmService;
import com.moabam.global.auth.model.AuthMember;
import com.moabam.global.auth.model.PublicClaim;
import com.moabam.global.common.util.cookie.CookieDevUtils;
Expand Down Expand Up @@ -66,6 +67,9 @@ class AuthorizationServiceTest {
@Mock
JwtProviderService jwtProviderService;

@Mock
FcmService fcmService;

@Mock
TokenRepository tokenRepository;

Expand Down Expand Up @@ -93,7 +97,7 @@ public void initParams() {
noOAuthConfig = new OAuthConfig(
new OAuthConfig.Provider(null, null, null, null, null),
new OAuthConfig.Client(null, null, null, null, null, null));
noPropertyService = new AuthorizationService(noOAuthConfig, tokenConfig,
noPropertyService = new AuthorizationService(fcmService, noOAuthConfig, tokenConfig,
oAuth2AuthorizationServerRequestService, memberService, jwtProviderService, tokenRepository, cookieUtils);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.moabam.api.dto.member.MemberInfo;
import com.moabam.api.dto.member.MemberInfoResponse;
import com.moabam.api.dto.member.ModifyMemberRequest;
import com.moabam.api.infrastructure.fcm.FcmService;
import com.moabam.global.auth.model.AuthMember;
import com.moabam.global.common.util.ClockHolder;
import com.moabam.global.error.exception.BadRequestException;
Expand Down Expand Up @@ -68,6 +69,9 @@ class MemberServiceTest {
@Mock
InventoryRepository inventoryRepository;

@Mock
FcmService fcmService;

@Mock
ItemRepository itemRepository;

Expand Down