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

[Feat]: 회원가입 및 로그인 시 platform 필드 추가 #144

Merged
merged 1 commit into from
Jul 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
Expand Up @@ -44,6 +44,7 @@ public SocialSignupResponse signup(SocialSignupRequest request) {
.build())
.deviceToken(request.deviceToken())
.roles(Role.USER.name())
.platform(request.platform())
.build());

Jwt jwt = jwtProvider.getUserJwt(signupUser.getSocialInfo().getSocialId());
Expand All @@ -69,6 +70,10 @@ public SocialLoginResponse login(SocialLoginRequest request) {
loginUser.updateDeviceToken(request.deviceToken());
}

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

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

return SocialLoginResponse.builder()
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/io/sobok/SobokSobok/auth/domain/Platform.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.sobok.SobokSobok.auth.domain;

import lombok.Getter;

@Getter
public enum Platform {

iOS,
ANDROID,
;
}
11 changes: 10 additions & 1 deletion src/main/java/io/sobok/SobokSobok/auth/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,17 @@ public class User extends BaseEntity implements UserDetails {
@Column
private String leaveReason;

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

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

public void updateDeviceToken(String newDeviceToken) {
Expand All @@ -65,6 +70,10 @@ public void changeUsername(String username) {
this.username = username;
}

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

public void deleteUser(String leaveReason) {
this.deviceToken = null;
this.username = null;
Expand Down
8 changes: 6 additions & 2 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,15 @@

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.SuccessCode;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -48,8 +50,9 @@ public ResponseEntity<ApiResponse<SocialSignupResponse>> signup(
)
public ResponseEntity<ApiResponse<SocialLoginResponse>> login(
@RequestParam final String socialId,
@RequestParam final String deviceToken
) {
@RequestParam final String deviceToken,
@RequestParam final Platform platform
) {

return ResponseEntity
.status(HttpStatus.OK)
Expand All @@ -58,6 +61,7 @@ public ResponseEntity<ApiResponse<SocialLoginResponse>> login(
socialService.login(SocialLoginRequest.builder()
.socialId(socialId)
.deviceToken(deviceToken)
.platform(platform)
.build())
));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.sobok.SobokSobok.auth.ui.dto;

import io.sobok.SobokSobok.auth.domain.Platform;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Builder;

@Builder
Expand All @@ -10,6 +12,10 @@ public record SocialLoginRequest(
String socialId,

@Schema(requiredMode = Schema.RequiredMode.REQUIRED)
String deviceToken
String deviceToken,

@Schema(requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull
Platform platform
) {
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package io.sobok.SobokSobok.auth.ui.dto;

import io.sobok.SobokSobok.auth.domain.Platform;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;

public record SocialSignupRequest(

Expand All @@ -15,6 +17,10 @@ public record SocialSignupRequest(

@Schema(requiredMode = Schema.RequiredMode.REQUIRED)
@NotBlank
String deviceToken
String deviceToken,

@Schema(requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull
Platform platform
) {
}
Loading