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

[Hotfix]: 푸시알림 전송 로직 변경 #132

Merged
merged 1 commit into from
May 1, 2024
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
@@ -1,6 +1,5 @@
package io.sobok.SobokSobok.auth.application;

import io.sobok.SobokSobok.auth.domain.Platform;
import io.sobok.SobokSobok.auth.domain.Role;
import io.sobok.SobokSobok.auth.domain.SocialInfo;
import io.sobok.SobokSobok.auth.domain.User;
Expand Down Expand Up @@ -29,7 +28,7 @@ public class SocialService {
private final JwtProvider jwtProvider;

@Transactional
public SocialSignupResponse signup(SocialSignupRequest request, Platform platform) {
public SocialSignupResponse signup(SocialSignupRequest request) {
if (userRepository.existsBySocialInfoSocialId(request.socialId())) {
throw new ConflictException(ErrorCode.ALREADY_EXISTS_USER);
}
Expand All @@ -45,7 +44,6 @@ public SocialSignupResponse signup(SocialSignupRequest request, Platform platfor
.build())
.deviceToken(request.deviceToken())
.roles(Role.USER.name())
.platform(platform)
.build());

Jwt jwt = jwtProvider.getUserJwt(signupUser.getSocialInfo().getSocialId());
Expand All @@ -60,7 +58,7 @@ public SocialSignupResponse signup(SocialSignupRequest request, Platform platfor
}

@Transactional
public SocialLoginResponse login(SocialLoginRequest request, Platform platform) {
public SocialLoginResponse login(SocialLoginRequest request) {
Optional<User> optionalLoginUser = userRepository.findBySocialInfoSocialId(
request.socialId());

Expand All @@ -71,10 +69,6 @@ public SocialLoginResponse login(SocialLoginRequest request, Platform platform)
loginUser.updateDeviceToken(request.deviceToken());
}

if (!platform.equals(loginUser.getPlatform())) {
loginUser.updatePlatform(platform);
}

Jwt jwt = jwtProvider.getUserJwt(loginUser.getSocialInfo().getSocialId());

return SocialLoginResponse.builder()
Expand Down
10 changes: 0 additions & 10 deletions src/main/java/io/sobok/SobokSobok/auth/domain/Platform.java

This file was deleted.

11 changes: 1 addition & 10 deletions src/main/java/io/sobok/SobokSobok/auth/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,18 @@ public class User extends BaseEntity implements UserDetails {
@Column
private String leaveReason;

@Column(nullable = false)
@Enumerated(EnumType.STRING)
private Platform platform;

@Builder
public User(String username, SocialInfo socialInfo, String deviceToken, String roles, Platform platform) {
public User(String username, SocialInfo socialInfo, String deviceToken, String roles) {
this.username = username;
this.socialInfo = socialInfo;
this.deviceToken = deviceToken;
this.roles = roles;
this.platform = platform;
}

public void updateDeviceToken(String newDeviceToken) {
this.deviceToken = newDeviceToken;
}

public void updatePlatform(Platform newPlatform) {
this.platform = newPlatform;
}

public void changeUsername(String username) {
this.username = username;
}
Expand Down
19 changes: 2 additions & 17 deletions src/main/java/io/sobok/SobokSobok/auth/ui/AuthController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

import io.sobok.SobokSobok.auth.application.AuthService;
import io.sobok.SobokSobok.auth.application.SocialService;
import io.sobok.SobokSobok.auth.domain.Platform;
import io.sobok.SobokSobok.auth.domain.User;
import io.sobok.SobokSobok.auth.ui.dto.*;
import io.sobok.SobokSobok.common.dto.ApiResponse;
import io.sobok.SobokSobok.exception.ErrorCode;
import io.sobok.SobokSobok.exception.SuccessCode;
import io.sobok.SobokSobok.exception.model.BadRequestException;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
Expand All @@ -33,16 +30,14 @@ public class AuthController {
description = "사용자의 소셜 정보로 소복소복에 회원가입하는 API 입니다."
)
public ResponseEntity<ApiResponse<SocialSignupResponse>> signup(
@RequestHeader(name = "User-Agent") String userAgent,
@RequestBody @Valid final SocialSignupRequest request
) {

Platform platform = getDevicePlatform(userAgent);
return ResponseEntity
.status(HttpStatus.CREATED)
.body(ApiResponse.success(
SuccessCode.SOCIAL_SIGNUP_SUCCESS,
socialService.signup(request, platform)
socialService.signup(request)
));
}

Expand All @@ -52,20 +47,18 @@ public ResponseEntity<ApiResponse<SocialSignupResponse>> signup(
description = "사용자의 소셜 정보로 소복소복에 로그인하는 API 입니다."
)
public ResponseEntity<ApiResponse<SocialLoginResponse>> login(
@RequestHeader(name = "User-Agent") String userAgent,
@RequestParam final String socialId,
@RequestParam final String deviceToken
) {

Platform platform = getDevicePlatform(userAgent);
return ResponseEntity
.status(HttpStatus.OK)
.body(ApiResponse.success(
SuccessCode.SOCIAL_LOGIN_SUCCESS,
socialService.login(SocialLoginRequest.builder()
.socialId(socialId)
.deviceToken(deviceToken)
.build(), platform)
.build())
));
}

Expand Down Expand Up @@ -118,12 +111,4 @@ public ResponseEntity<ApiResponse<Void>> leave(
SuccessCode.USER_LEAVE_SUCCESS
));
}

private Platform getDevicePlatform(String userAgent) {
if (userAgent.toLowerCase().contains("android")) {
return Platform.Android;
} else {
return Platform.iOS;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,30 +55,6 @@ public void sendNotificationByToken(PushNotificationRequest request) {
sendMessageToFirebase(message, user.getId());
}

private void sendNotification(User user, PushNotificationRequest request) {
Notification notification = Notification.builder()
.setTitle(request.title())
.setBody(request.body())
.build();

Message message = Message.builder()
.setToken(user.getDeviceToken())
.setNotification(notification)
.build();

sendMessageToFirebase(message, request.userId());
}

private void sendDataMessage(User user, PushNotificationRequest request) {
Message message = Message.builder()
.putData("title", request.title())
.putData("body", request.body())
.setToken(user.getDeviceToken())
.build();

sendMessageToFirebase(message, request.userId());
}

private void sendMessageToFirebase(Message message, Long userId) {
try {
firebaseMessaging.send(message);
Expand Down
Loading