diff --git a/src/main/java/com/umc/dream/controller/UserController.java b/src/main/java/com/umc/dream/controller/UserController.java new file mode 100644 index 0000000..7bf403a --- /dev/null +++ b/src/main/java/com/umc/dream/controller/UserController.java @@ -0,0 +1,29 @@ +package com.umc.dream.controller; + +import com.umc.dream.apiPayload.ApiResponse; +import com.umc.dream.domain.User; +import com.umc.dream.dto.UserRequestDTO; +import com.umc.dream.dto.UserResponseDTO; +import com.umc.dream.service.UserService.UserService; +import com.umc.dream.converter.UserConverter; +import io.swagger.v3.oas.annotations.Operation; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/user") +public class UserController { + + private final UserService userService; + + @Operation(summary = "회원가입 API") + @PostMapping("/join") + public ApiResponse join(@RequestBody UserRequestDTO.JoinDto request){ + User user = userService.join(request); + return ApiResponse.onSuccess(UserConverter.toJoinResultDTO(user)); + } +} diff --git a/src/main/java/com/umc/dream/converter/UserConverter.java b/src/main/java/com/umc/dream/converter/UserConverter.java new file mode 100644 index 0000000..82b4037 --- /dev/null +++ b/src/main/java/com/umc/dream/converter/UserConverter.java @@ -0,0 +1,27 @@ +package com.umc.dream.converter; + +import com.umc.dream.domain.User; +import com.umc.dream.domain.enums.Role; +import com.umc.dream.dto.UserRequestDTO; +import com.umc.dream.dto.UserResponseDTO; + +import java.time.LocalDateTime; + +public class UserConverter { + public static UserResponseDTO.JoinResultDTO toJoinResultDTO(User user) { + return UserResponseDTO.JoinResultDTO.builder() + .userId(user.getId()) + .createdAt(LocalDateTime.now()) + .build(); + } + + + public static User toUser(UserRequestDTO.JoinDto joinDto) { + return User.builder() + .name(joinDto.getName()) + .account(joinDto.getAccount()) + .password(joinDto.getPassword()) + .role(Role.NORMAL) + .build(); + } +} diff --git a/src/main/java/com/umc/dream/domain/Dream.java b/src/main/java/com/umc/dream/domain/Dream.java index f954481..ac1e8ff 100644 --- a/src/main/java/com/umc/dream/domain/Dream.java +++ b/src/main/java/com/umc/dream/domain/Dream.java @@ -21,7 +21,7 @@ public class Dream extends BaseEntity { private Long id; @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "users_id", nullable = false) + @JoinColumn(name = "user_id", nullable = false) private User user; private LocalDate date; diff --git a/src/main/java/com/umc/dream/domain/Character.java b/src/main/java/com/umc/dream/domain/People.java similarity index 92% rename from src/main/java/com/umc/dream/domain/Character.java rename to src/main/java/com/umc/dream/domain/People.java index 7e3ed9c..cf498f9 100644 --- a/src/main/java/com/umc/dream/domain/Character.java +++ b/src/main/java/com/umc/dream/domain/People.java @@ -9,7 +9,7 @@ @Entity @Getter @NoArgsConstructor(access = AccessLevel.PROTECTED) -public class Character extends BaseEntity { +public class People extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/src/main/java/com/umc/dream/dto/UserRequestDTO.java b/src/main/java/com/umc/dream/dto/UserRequestDTO.java new file mode 100644 index 0000000..aad4773 --- /dev/null +++ b/src/main/java/com/umc/dream/dto/UserRequestDTO.java @@ -0,0 +1,21 @@ +package com.umc.dream.dto; + +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.NotNull; +import lombok.Getter; + +public class UserRequestDTO { + + @Getter + public static class JoinDto { + @NotBlank + String name; + @NotNull + String account; + @NotNull + String password; + @NotNull + String passwordConfirm; + } + +} diff --git a/src/main/java/com/umc/dream/dto/UserResponseDTO.java b/src/main/java/com/umc/dream/dto/UserResponseDTO.java new file mode 100644 index 0000000..f513d85 --- /dev/null +++ b/src/main/java/com/umc/dream/dto/UserResponseDTO.java @@ -0,0 +1,21 @@ +package com.umc.dream.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; + +public class UserResponseDTO { + + @Builder + @Getter + @NoArgsConstructor + @AllArgsConstructor + public static class JoinResultDTO{ + Long userId; + LocalDateTime createdAt; + } + +} diff --git a/src/main/java/com/umc/dream/repository/UserRepository.java b/src/main/java/com/umc/dream/repository/UserRepository.java new file mode 100644 index 0000000..a48b292 --- /dev/null +++ b/src/main/java/com/umc/dream/repository/UserRepository.java @@ -0,0 +1,7 @@ +package com.umc.dream.repository; + +import com.umc.dream.domain.User; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface UserRepository extends JpaRepository { +} diff --git a/src/main/java/com/umc/dream/service/UserService/UserService.java b/src/main/java/com/umc/dream/service/UserService/UserService.java new file mode 100644 index 0000000..708fc2e --- /dev/null +++ b/src/main/java/com/umc/dream/service/UserService/UserService.java @@ -0,0 +1,8 @@ +package com.umc.dream.service.UserService; + +import com.umc.dream.domain.User; +import com.umc.dream.dto.UserRequestDTO; + +public interface UserService { + User join(UserRequestDTO.JoinDto request); +} diff --git a/src/main/java/com/umc/dream/service/UserService/UserServiceImpl.java b/src/main/java/com/umc/dream/service/UserService/UserServiceImpl.java new file mode 100644 index 0000000..0b41621 --- /dev/null +++ b/src/main/java/com/umc/dream/service/UserService/UserServiceImpl.java @@ -0,0 +1,22 @@ +package com.umc.dream.service.UserService; + +import com.umc.dream.converter.UserConverter; +import com.umc.dream.domain.User; +import com.umc.dream.dto.UserRequestDTO; +import com.umc.dream.repository.UserRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class UserServiceImpl implements UserService { + + private final UserRepository userRepository; + + @Override + public User join(UserRequestDTO.JoinDto request) { + User user = UserConverter.toUser(request); + return userRepository.save(user); + } + +}