Skip to content

Commit

Permalink
Revert "[feat] : 회원가입 api 구현 & use 엔티티 추가 구현 (#41)" (#49)
Browse files Browse the repository at this point in the history
This reverts commit d438902.
  • Loading branch information
ParkJuhan94 authored Jan 2, 2024
1 parent d438902 commit 5ab90d7
Show file tree
Hide file tree
Showing 16 changed files with 4 additions and 360 deletions.
28 changes: 0 additions & 28 deletions api/src/main/java/dev/hooon/user/UserApiController.java

This file was deleted.

50 changes: 0 additions & 50 deletions api/src/test/java/dev/hooon/user/UserApiControllerTest.java

This file was deleted.

2 changes: 0 additions & 2 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ dependencies {
testFixturesImplementation 'org.springframework.boot:spring-boot-starter-test'
testFixturesImplementation "org.testcontainers:testcontainers:1.19.3"
testFixturesImplementation "org.testcontainers:postgresql:1.19.3"
// 패스워드 암호화
implementation group: 'org.mindrot', name: 'jbcrypt', version: '0.3m'
}

bootJar { enabled = false }
Expand Down
18 changes: 0 additions & 18 deletions core/src/main/java/dev/hooon/auth/entity/BcryptImpl.java

This file was deleted.

6 changes: 0 additions & 6 deletions core/src/main/java/dev/hooon/auth/entity/EncryptHelper.java

This file was deleted.

27 changes: 0 additions & 27 deletions core/src/main/java/dev/hooon/user/application/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,20 @@
import static dev.hooon.user.exception.UserErrorCode.*;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import dev.hooon.auth.entity.EncryptHelper;
import dev.hooon.common.exception.NotFoundException;
import dev.hooon.user.domain.entity.User;
import dev.hooon.user.domain.repository.UserRepository;
import dev.hooon.user.dto.request.UserJoinRequest;
import dev.hooon.common.exception.ValidationException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Service
@RequiredArgsConstructor
public class UserService {

private final UserRepository userRepository;
private final EncryptHelper encryptHelper;

private void validateDuplicateEmail(String email) {
if (userRepository.findByEmail(email).isPresent()) {
throw new ValidationException(DUPLICATED_EMAIL);
}
}

public User getUserById(Long userId) {
return userRepository.findById(userId)
.orElseThrow(() -> new NotFoundException(NOT_FOUND_BY_ID));
}

@Transactional
public Long join(UserJoinRequest userJoinRequest) {
validateDuplicateEmail(userJoinRequest.email());
String password = userJoinRequest.password();
String encryptedPassword = encryptHelper.encrypt(password);

User user = User.ofBuyer(
userJoinRequest.email(),
userJoinRequest.name(),
encryptedPassword
);
return userRepository.save(user);
}

}
36 changes: 3 additions & 33 deletions core/src/main/java/dev/hooon/user/domain/entity/User.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package dev.hooon.user.domain.entity;

import static dev.hooon.common.exception.CommonValidationError.*;
import static dev.hooon.user.domain.entity.UserRole.*;
import static jakarta.persistence.EnumType.*;
import static jakarta.persistence.GenerationType.*;

import org.springframework.util.Assert;

import dev.hooon.common.entity.TimeBaseEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand All @@ -19,8 +15,8 @@

@Entity
@Getter
@NoArgsConstructor
@Table(name = "user_table")
@NoArgsConstructor
public class User extends TimeBaseEntity {

@Id
Expand All @@ -34,40 +30,14 @@ public class User extends TimeBaseEntity {
@Column(name = "user_name", nullable = false)
private String name;

@Column(name = "user_password", nullable = false)
private String password;

@Enumerated(STRING)
@Column(name = "user_role", nullable = false)
private UserRole userRole;

private User(
String email,
String name,
String password,
UserRole userRole
) {
validateUser(email, name, password, userRole);
// 테스트용 AllArgsConstructor
public User(String email, String name, UserRole userRole) {
this.email = email;
this.name = name;
this.password = password;
this.userRole = userRole;
}

private void validateUser(String email, String name, String password, UserRole userRole) {
Assert.hasText(email, getNotEmptyPostfix("User", "email"));
Assert.hasText(name, getNotEmptyPostfix("User", "name"));
Assert.hasText(password, getNotEmptyPostfix("User", "password"));
Assert.hasText(String.valueOf(userRole), getNotEmptyPostfix("User", "userRole"));
Assert.notNull(userRole, getNotNullMessage("User", "userRole"));
}

public static User ofBuyer(
String email,
String name,
String password
) {
return new User(email, name, password, BUYER);
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.hooon.user.domain.repository;

import java.util.List;
import java.util.Optional;

import dev.hooon.user.domain.entity.User;
Expand All @@ -10,9 +9,4 @@ public interface UserRepository {
User save(User user);

Optional<User> findById(Long id);

Optional<User> findByName(String name);
Long save(User user);

Optional<User> findByEmail(String email);
}
17 changes: 0 additions & 17 deletions core/src/main/java/dev/hooon/user/dto/UserMapper.java

This file was deleted.

14 changes: 0 additions & 14 deletions core/src/main/java/dev/hooon/user/dto/request/UserJoinRequest.java

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
@RequiredArgsConstructor
public enum UserErrorCode implements ErrorCode {

NOT_FOUND_BY_ID("ID 에 해당하는 사용자가 존재하지 않습니다", "U_001"),
DUPLICATED_EMAIL("이미 존재하는 이메일입니다. 회원가입을 다시 진행해주세요.", "U_002");
NOT_FOUND_BY_ID("ID 에 해당하는 사용자가 존재하지 않습니다", "U_001");

private final String message;
private final String code;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.hooon.user.infrastructure.adaptor;

import java.util.List;
import java.util.Optional;

import org.springframework.stereotype.Repository;
Expand All @@ -25,19 +24,4 @@ public User save(User user) {
public Optional<User> findById(Long id) {
return userJpaRepository.findById(id);
}

@Override
public Optional<User> findByName(String name) {
return userJpaRepository.findByName(name);
}

@Override
public Long save(User user) {
return userJpaRepository.save(user).getId();
}

@Override
public Optional<User> findByEmail(String email) {
return userJpaRepository.findByEmail(email);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
package dev.hooon.user.infrastructure.repository;

import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;

import dev.hooon.user.domain.entity.User;

public interface UserJpaRepository extends JpaRepository<User, Long> {
Optional<User> findByName(String name);

Optional<User> findByEmail(String email);
}
Loading

0 comments on commit 5ab90d7

Please sign in to comment.