-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
137 additions
and
2 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
src/main/java/com/umc/dream/controller/UserController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<UserResponseDTO.JoinResultDTO> join(@RequestBody UserRequestDTO.JoinDto request){ | ||
User user = userService.join(request); | ||
return ApiResponse.onSuccess(UserConverter.toJoinResultDTO(user)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<User, Long> { | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/umc/dream/service/UserService/UserService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/umc/dream/service/UserService/UserServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
} |