Skip to content

Commit

Permalink
fix: 변수명 동사를 명사로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
kamser0415 committed Nov 15, 2024
1 parent a492310 commit e12c48c
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ public class BuyerController {
@PostMapping("/buyers")
public ApiResponse<BuyerResponse> signUp(@RequestBody BuyerCreateRequest buyerCreateRequest) {
final LocalDateTime now = LocalDateTime.now();
BuyerResponse buyerResponse = buyerService.signUp(buyerCreateRequest.toServiceRequest(), now);
return ApiResponse.ok(buyerResponse);
return ApiResponse.ok(buyerService.signUp(buyerCreateRequest.toServiceRequest(), now));
}

}
1 change: 0 additions & 1 deletion src/main/java/shop/sendbox/sendbox/buyer/entity/Buyer.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@ToString
public class Buyer {
// @Id 필드는 엔티티의 primary key로 매핑합니다.
// @GeneratedValue는 자동으로 증가하는 값에 대한 옵션을 지정할 수 있습니다
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
@Builder(access = AccessLevel.PRIVATE)
public record BuyerResponse(Long buyerId, String email, String name, String phoneNumber, BuyerStatus buyerStatus) {

public static BuyerResponse of(Buyer buyer, String decryptEmail, String decryptPhoneNumber) {
public static BuyerResponse of(Buyer buyer, String decryptedEmail, String decryptedPhoneNumber) {
return BuyerResponse.builder()
.buyerId(buyer.getBuyerId())
.email(decryptEmail)
.email(decryptedEmail)
.name(buyer.getName())
.phoneNumber(decryptPhoneNumber)
.phoneNumber(decryptedPhoneNumber)
.buyerStatus(buyer.getBuyerStatus())
.build();
}
Expand Down
22 changes: 11 additions & 11 deletions src/main/java/shop/sendbox/sendbox/buyer/service/BuyerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ public class BuyerService implements LoginHandler {
*/
@Transactional
public BuyerResponse signUp(final BuyerRequest buyerRequest, final LocalDateTime createdAt) {
final String encryptEmail = symmetricCryptoService.encrypt(cryptoConfig.getPassword(), cryptoConfig.getSalt(),
final String encryptedEmail = symmetricCryptoService.encrypt(cryptoConfig.getPassword(), cryptoConfig.getSalt(),
buyerRequest.email());
final String encryptPhoneNumber = symmetricCryptoService.encrypt(cryptoConfig.getPassword(),
final String encryptedPhoneNumber = symmetricCryptoService.encrypt(cryptoConfig.getPassword(),
cryptoConfig.getSalt(),
buyerRequest.phoneNumber());
final String salt = generateSalt();
final String encryptPassword = encryptPassword(buyerRequest.password(), salt);
final Buyer buyer = Buyer.create(encryptEmail, encryptPassword, salt, buyerRequest.name(),
encryptPhoneNumber, createdAt, buyerRequest.createdBy());
final String encryptedPassword = encryptPassword(buyerRequest.password(), salt);
final Buyer buyer = Buyer.create(encryptedEmail, encryptedPassword, salt, buyerRequest.name(),
encryptedPhoneNumber, createdAt, buyerRequest.createdBy());
final Buyer savedBuyer = buyerRepository.save(buyer);

final String decryptedEmail = symmetricCryptoService.decrypt(cryptoConfig.getPassword(), cryptoConfig.getSalt(),
Expand All @@ -74,15 +74,15 @@ public boolean supports(final UserType userType) {
public LoginResponse login(final LoginUser user) {
final String encryptedEmail = symmetricCryptoService.encrypt(cryptoConfig.getPassword(), cryptoConfig.getSalt(),
user.email());
final Buyer findBuyer = buyerRepository.findByEmail(encryptedEmail)
final Buyer foundBuyer = buyerRepository.findByEmail(encryptedEmail)
.orElseThrow(() -> new IllegalArgumentException("해당 이메일로 가입된 회원이 없습니다."));
final String encryptPassword = encryptPassword(user.password(), findBuyer.getSalt());
validatePassword(findBuyer, encryptPassword);
return LoginResponse.of(findBuyer, user.email());
final String encryptedPassword = encryptPassword(user.password(), foundBuyer.getSalt());
validatePassword(foundBuyer, encryptedPassword);
return LoginResponse.of(foundBuyer, user.email());
}

private void validatePassword(final Buyer findBuyer, final String encryptPassword) {
if (!findBuyer.isPasswordEquals(encryptPassword)) {
private void validatePassword(final Buyer buyer, final String encryptedPassword) {
if (!buyer.isPasswordEquals(encryptedPassword)) {
throw new IllegalArgumentException("비밀번호가 일치하지 않습니다.");
}
}
Expand Down
19 changes: 19 additions & 0 deletions src/test/java/shop/sendbox/sendbox/login/LoginServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,25 @@ void loginBuyer() {
assertThat(loginResponse.name()).isEqualTo("홍길동");
}

@Test
@DisplayName("회원 가입된 구매자는 틀린 비밀번호를 입력하면 로그인할 수 없다.")
void loginBuyerWithFailLoin() {
// given
String email = "[email protected]";
String password = "password";
String failPassword = "fail_password";
BuyerRequest buyerRequest = new BuyerRequest(email, password, "홍길동", "01012345678", "admin");
buyerService.signUp(buyerRequest, LocalDateTime.of(2024, 10, 22, 11, 28));

UserType userType = UserType.BUYER;
LoginRequest loginRequest = new LoginRequest(email, failPassword, userType);

// when
Assertions.assertThatThrownBy(() -> loginService.login(loginRequest))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("비밀번호가 일치하지 않습니다.");
}

@Test
@DisplayName("회원 정보가 없는 구매자는 로그인을 할 수 없다.")
void loginBuyerWithFail() {
Expand Down

0 comments on commit e12c48c

Please sign in to comment.