Skip to content

Commit

Permalink
Merge pull request #55 from Kakaotech-18-Ecommerce/SCRUM-84-Authentic…
Browse files Browse the repository at this point in the history
…ationPrincipal-refactoring

SCRUM-84 feat: 상세주소 나누기 수정
  • Loading branch information
softwareyong authored Sep 9, 2024
2 parents 8a860de + 6f8c3bc commit a548c5e
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public class AuthController {
@Operation(summary = "회원가입 추가정보 진행", description = "(nickname, gender, role) 저장")
@PostMapping("/join")
public ApiResponse<String> join(@RequestBody AuthRequest authRequest, @AuthenticationPrincipal CustomOAuth2User customUser) {
// String username = customUser.getUsername();

// 1. UserEntity 가져오기
UserEntity userEntity = customUser.getUserEntity();
Expand All @@ -42,7 +41,6 @@ public ApiResponse<String> join(@RequestBody AuthRequest authRequest, @Authentic
userEntity.setPhoneNum(authRequest.phoneNumber());
userEntity.setRole(authRequest.role());

// 5. SecurityContextHolder에 새로운 Authentication 객체로 업데이트
UserDTO updatedUserDTO = customUser.getUserDTO();
updatedUserDTO.setNickname(authRequest.nickName());
updatedUserDTO.setGender(authRequest.gender());
Expand All @@ -52,13 +50,17 @@ public ApiResponse<String> join(@RequestBody AuthRequest authRequest, @Authentic

Buyer buyer = Buyer.builder()
.user(userEntity)
.address(authRequest.address())
.roadAddress(authRequest.roadAddress())
.zipCode(authRequest.zipCode())
.detailAdress(authRequest.detailAdress())
.build();
userEntity.setBuyer(buyer); // UserEntity에 Buyer 설정
} else if (Role.SELLER == authRequest.role()) {
Seller seller = Seller.builder()
.user(userEntity)
.address(authRequest.address())
.roadAddress(authRequest.roadAddress())
.zipCode(authRequest.zipCode())
.detailAdress(authRequest.detailAdress())
.build();
userEntity.setSeller(seller); // UserEntity에 Seller 설정
} else {
Expand All @@ -68,10 +70,6 @@ public ApiResponse<String> join(@RequestBody AuthRequest authRequest, @Authentic
// 4. 업데이트된 UserEntity 저장 (Cascade 옵션으로 인해 Buyer/Seller도 저장됨)
authService.saveUser(userEntity);

// CustomOAuth2User updatedCustomOAuth2User = new CustomOAuth2User(updatedUserDTO, userEntity);
// Authentication newAuth = new UsernamePasswordAuthenticationToken(updatedCustomOAuth2User, null, updatedCustomOAuth2User.getAuthorities());
// SecurityContextHolder.getContext().setAuthentication(newAuth);

return ApiResponse.onSuccess("회원가입 성공");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ public record AuthRequest(
String nickName,
Gender gender,
String phoneNumber,
String address,
String roadAddress,
String zipCode,
String detailAdress,
Role role
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ public record BuyerRequest(

@Builder
public record MyPagePutDto(
String roadAddress,
String zipCode,
String detailAdress,
String nickname,
String address,
String phoneNum
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
public record BuyerResponse(
String email,
Role role,
String address,
String roadAddress, // 도로명 주소
String zipCode, // 우편 번호
String detailAdress, // 세부주소
String realName,
Gender gender,
String phoneNum,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@ public class Buyer extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long buyerId;
private String address; // @Column(nullable = false)
private String roadAddress; // 도로명 주소
private String zipCode; // 우편 번호
private String detailAdress; // 세부주소


@OneToOne // Buyer는 하나의 UserEntity와만 연결됩니다.
@JoinColumn(name = "user_id", nullable = false)
private UserEntity user;


// @Enumerated(EnumType.STRING)
// @Column(nullable = false)
// private Role role = Role.valueOf("BUYER");
Expand All @@ -52,7 +56,9 @@ public class Buyer extends BaseEntity {
private List<Order> orderList;

public void updateProfile(BuyerRequest.MyPagePutDto request) {
this.address = request.address();
this.roadAddress = request.roadAddress();
this.zipCode = request.zipCode();
this.detailAdress = request.detailAdress();
this.user.setNickname(request.nickname()); // 참조entity에서 UserEntity에 업데이트
this.user.setPhoneNum(request.phoneNum()); // 참조entity에서 UserEntity에 업데이트
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public static BuyerResponse getMyPage(Buyer buyer) {
return BuyerResponse.builder()
.email(buyer.getUser().getEmail())
.role(buyer.getUser().getRole())
.address(buyer.getAddress())
.roadAddress(buyer.getRoadAddress())
.zipCode(buyer.getZipCode())
.detailAdress(buyer.getDetailAdress())
.realName(buyer.getUser().getName())
.gender(buyer.getUser().getGender())
.phoneNum(buyer.getUser().getPhoneNum())
Expand All @@ -43,7 +45,9 @@ public BuyerResponse updateMyPage(Buyer buyer, BuyerRequest.MyPagePutDto request
return BuyerResponse.builder()
.email(savedBuyer.getUser().getEmail())
.role(savedBuyer.getUser().getRole())
.address(savedBuyer.getAddress())
.roadAddress(savedBuyer.getRoadAddress())
.zipCode(savedBuyer.getZipCode())
.detailAdress(savedBuyer.getDetailAdress())
.realName(savedBuyer.getUser().getName())
.gender(savedBuyer.getUser().getGender())
.phoneNum(savedBuyer.getUser().getPhoneNum())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ public record SellerRequest(
) {
@Builder
public record MyPagePutDto(
String roadAddress,
String zipCode,
String detailAdress,
String nickname,
String address,
String phoneNum
) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ public record SellerResponse(
String realName,
Gender gender,
String email,
String address,
String roadAddress, // 도로명 주소
String zipCode, // 우편 번호
String detailAdress, // 세부주소
String phoneNum,
Role role,
LocalDate registerDate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public class Seller extends BaseEntity{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long sellerId;
private String address; // @Column(nullable = false)
private String roadAddress; // 도로명 주소
private String zipCode; // 우편 번호
private String detailAdress; // 세부주소

@OneToOne // Seller는 하나의 UserEntity와만 연결됩니다.
@JoinColumn(name = "user_id", nullable = false)
Expand All @@ -51,7 +53,9 @@ public class Seller extends BaseEntity{
private List<Order> orderList = new ArrayList<>();

public void updateProfile(SellerRequest.MyPagePutDto request) {
this.address = request.address();
this.roadAddress = request.roadAddress();
this.zipCode = request.zipCode();
this.detailAdress = request.detailAdress();
this.user.setNickname(request.nickname()); // 참조entity에서 UserEntity에 업데이트
this.user.setPhoneNum(request.phoneNum()); // 참조entity에서 UserEntity에 업데이트
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public SellerResponse getMyPage(Seller seller) {
return SellerResponse.builder()
.email(seller.getUser().getEmail())
.role(seller.getUser().getRole())
.address(seller.getAddress())
.roadAddress(seller.getRoadAddress())
.zipCode(seller.getZipCode())
.detailAdress(seller.getDetailAdress())
.realName(seller.getUser().getName())
.gender(seller.getUser().getGender())
.phoneNum(seller.getUser().getPhoneNum())
Expand All @@ -42,7 +44,9 @@ public SellerResponse updateMyPage(Seller seller, SellerRequest.MyPagePutDto req
return SellerResponse.builder()
.email(savedSeller.getUser().getEmail())
.role(savedSeller.getUser().getRole())
.address(savedSeller.getAddress())
.roadAddress(savedSeller.getRoadAddress())
.zipCode(savedSeller.getZipCode())
.detailAdress(savedSeller.getDetailAdress())
.realName(savedSeller.getUser().getName())
.gender(savedSeller.getUser().getGender())
.phoneNum(savedSeller.getUser().getPhoneNum())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ else if (userEntity.getRole() == Role.SELLER){
authToken = new UsernamePasswordAuthenticationToken(seller, null, customOAuth2User.getAuthoritiesForRole(Role.SELLER)); // Seller에 맞는 권한 설정
}
else{
System.out.println("여기 걸리냐/?!!!!!!");
authToken = new UsernamePasswordAuthenticationToken(customOAuth2User, null, customOAuth2User.getAuthorities()); // 스프링 시큐리티 인증 토큰 생성, 스프링 시큐리티에서 세션을 생성해가지고 토큰을 등록하고 있음.
}
SecurityContextHolder.getContext().setAuthentication(authToken); // 세션에 사용자 등록
Expand Down

0 comments on commit a548c5e

Please sign in to comment.