Skip to content

Commit

Permalink
refactor: User 클래스에서 provider 필드 제거 (#165) (#167)
Browse files Browse the repository at this point in the history
* refactor: User에서 provider 제거 (#165)

* refactor: User에서 provider 제거함에 따른 변경 사항 (#165)
  • Loading branch information
hoyun06 authored Oct 10, 2023
1 parent 43605f6 commit df05255
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public ResponseEntity<Void> drop(Authentication authentication,
@PostMapping
public ResponseEntity<Void> signUp(@RequestHeader(value = "oauth-history-id") Long oauthHistoryId,
@Valid @RequestBody UserSignUpRequest request) {
// TODO: 권한 확인 로직 추가해야함. 근데 여기서 굳이 필요한 지는 모르겠음
userService.signUp(oauthHistoryId, request);
return ResponseEntity
.status(CREATED)
Expand Down
23 changes: 2 additions & 21 deletions src/main/java/com/newfit/reservation/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -50,12 +49,6 @@ public class User extends BaseTimeEntity {
@Column(nullable = false, unique = true)
private String nickname;

// 사용자가 Oauth 2.0 로그인할 때 이용한 OAuth 제공자를 나타냅니다.
// Provider 라는 Enum 타입을 새로 정의했습니다.
@Enumerated(EnumType.STRING)
@Column(nullable = false)
private Provider provider;

// 사용자의 크레딧 잔여량을 나타냅니다.
@Column(nullable = false)
private Long balance;
Expand All @@ -82,33 +75,23 @@ public class User extends BaseTimeEntity {
/* =========== update method =========== */

public void updateEmail(String email) {

this.email = email;

}

public void updateTel(String tel) {

this.tel = tel;

}

public void updateNickname(String nickname) {

this.nickname = nickname;

}

public void updateFilePath(String filePath) {

this.filePath = filePath;

}

public void addBalance(Long balance) {

this.balance += balance;

}

public Long getTermCredit(LocalDateTime term) {
Expand All @@ -120,21 +103,19 @@ public Long getTermCredit(LocalDateTime term) {
}

@Builder
private User(UserSignUpRequest userInfo, Provider provider) {
private User(UserSignUpRequest userInfo) {
this.username = userInfo.getUsername();
this.nickname = userInfo.getNickname();
this.email = userInfo.getEmail();
this.tel = userInfo.getTel();
this.provider = provider;
this.balance = 0L;
this.lastLoginAt = LocalDateTime.now();
this.filePath = "https://newfit-image.s3.ap-northeast-2.amazonaws.com/newfitIcon.png";
}

public static User userSignUp(UserSignUpRequest request, Provider provider) {
public static User userSignUp(UserSignUpRequest request) {
return User.builder()
.userInfo(request)
.provider(provider)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.List;

import static com.newfit.reservation.exception.ErrorCode.*;

@Service
@RequiredArgsConstructor
@Transactional
Expand Down Expand Up @@ -86,7 +87,7 @@ public void signUp(Long oauthHistoryId, UserSignUpRequest request) {
OAuthHistory oAuthHistory = oAuthHistoryRepository
.findById(oauthHistoryId)
.orElseThrow(() -> new CustomException(OAUTH_HISTORY_NOT_FOUND));
User user = User.userSignUp(request, oAuthHistory.getProvider());
User user = User.userSignUp(request);
userRepository.save(user);
oAuthHistory.signUp(user);
}
Expand Down

0 comments on commit df05255

Please sign in to comment.