Skip to content

Commit

Permalink
#5 #24 feat: 애플 로그인 요청(ServicesResponse) 응답(TokenResponse) 필드값 추가, Us…
Browse files Browse the repository at this point in the history
…er엔티티에 UserType 필드 추가
  • Loading branch information
xhaktmchl committed Nov 24, 2022
1 parent 1d96f31 commit fe39399
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public TokenResponse signUpApple(@RequestBody ServicesResponse servicesResponse)
@PostMapping(value = "/apps/to/endpoint")
@ResponseBody
public void appsToEndpoint(@RequestBody AppsResponse appsResponse) {
System.out.println("애플 계정 탈퇴했습니다.");
logger.debug("[/path/to/endpoint] RequestBody ‣ " + appsResponse.getPayload());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.yogit.server.applelogin.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import net.minidev.json.JSONObject;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Account {

private String state;
private String code; // authorization_token
private String id_token; // identity_token
private JSONObject user; // 애플에서 제공하는 유저 정보
private String identifier;
private Boolean hasRequirementInfo; // 유저 필수정보 입력 여부
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
public class ServicesResponse {

private String state;
private String code;
private String id_token;
private JSONObject user;
private String code; // authorization_token
private String id_token; // identity_token
private JSONObject user; // 애플에서 제공하는 유저 정보
private String identifier;
private Boolean hasRequirementInfo; // 유저 필수정보 입력 여부
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ public class TokenResponse {
// 유저 엔티티 생성 후 res
private String name;
private String email;

//추가적인 응답 필드
private String userType; // ex)apple
private Account account;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.yogit.server.applelogin.service;

import com.yogit.server.applelogin.model.Account;
import com.yogit.server.applelogin.model.ServicesResponse;
import com.yogit.server.applelogin.model.TokenResponse;
import com.yogit.server.applelogin.util.AppleUtils;
import com.yogit.server.user.dto.request.CreateUserAppleReq;
import com.yogit.server.user.entity.UserType;
import com.yogit.server.user.service.UserService;
import lombok.RequiredArgsConstructor;
import net.minidev.json.JSONObject;
Expand Down Expand Up @@ -69,7 +71,7 @@ public TokenResponse requestCodeValidations(ServicesResponse serviceResponse, St
tokenResponse = appleUtils.validateAuthorizationGrantCode(client_secret, code);

// 유저 생성
CreateUserAppleReq createUserAppleReq = new CreateUserAppleReq(email, tokenResponse.getRefresh_token(),fullName);
CreateUserAppleReq createUserAppleReq = new CreateUserAppleReq(email, tokenResponse.getRefresh_token(),fullName, UserType.APPLE);
userService.createUserApple(createUserAppleReq);

tokenResponse.setName(fullName);
Expand All @@ -80,6 +82,9 @@ else if (client_secret != null && code == null && refresh_token != null) {
tokenResponse = appleUtils.validateAnExistingRefreshToken(client_secret, refresh_token);
}

tokenResponse.setAccount(new Account(serviceResponse.getState(), code, serviceResponse.getId_token(), user, serviceResponse.getIdentifier(), serviceResponse.getHasRequirementInfo()));
tokenResponse.setUserType(UserType.APPLE.toString());

return tokenResponse;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.yogit.server.user.dto.request;

import com.yogit.server.user.entity.User;
import com.yogit.server.user.entity.UserType;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
Expand All @@ -13,9 +14,10 @@ public class CreateUserAppleReq {
String loginId;
String refresh_token;
String name;
UserType userType;

public static User toEntityUserApple(CreateUserAppleReq createUserAppleReq){
User user = new User(createUserAppleReq.loginId, createUserAppleReq.refresh_token, createUserAppleReq.name);
User user = new User(createUserAppleReq.loginId, createUserAppleReq.refresh_token, createUserAppleReq.name, createUserAppleReq.userType);
return user;
}
}
10 changes: 10 additions & 0 deletions server/src/main/java/com/yogit/server/user/entity/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ public class User extends BaseEntity {
@OneToMany(mappedBy = "user")
private List<UserImage> userImages = new ArrayList<>();

@Enumerated(EnumType.STRING)
private UserType userType;

@Builder
public User (String loginId, String phoneNum){
this.loginId = loginId;
Expand All @@ -84,6 +87,13 @@ public User (String loginId, String refresh_token, String name){
this.name = name;
}

public User (String loginId, String refresh_token, String name, UserType userType){
this.loginId = loginId;
this.refresh_token = refresh_token;
this.name = name;
this.userType = userType;
}

public void addLanguage(Language language){
this.languages.add(language);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.yogit.server.user.entity;
// 가입 경로
public enum UserType {
APPLE
}

0 comments on commit fe39399

Please sign in to comment.