-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
회원가입 API 구현, SQL문 실행 안됨 Related to: #5
- Loading branch information
crayon
committed
Mar 13, 2022
1 parent
10caaed
commit ddf2c96
Showing
7 changed files
with
123 additions
and
3 deletions.
There are no files selected for viewing
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
32 changes: 32 additions & 0 deletions
32
src/main/java/com/moodstation/springboot/dto/UserCreateRequestDto.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,32 @@ | ||
package com.moodstation.springboot.dto; | ||
|
||
import com.moodstation.springboot.entity.User; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class UserCreateRequestDto { | ||
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(); | ||
|
||
private String email; | ||
private String nickname; | ||
private String password; | ||
|
||
@Builder | ||
public UserCreateRequestDto(String email, String nickname, String password) { | ||
this.email = email; | ||
this.nickname = nickname; | ||
this.password = encoder.encode(password); | ||
} | ||
|
||
public User toEntity() { | ||
return User.builder() | ||
.email(email) | ||
.nickname(nickname) | ||
.password(password) | ||
.build(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/moodstation/springboot/dto/UserCreateResponseDto.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,18 @@ | ||
package com.moodstation.springboot.dto; | ||
|
||
import com.moodstation.springboot.entity.User; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class UserCreateResponseDto { | ||
|
||
private Long id; | ||
private String email; | ||
private String nickname; | ||
|
||
public UserCreateResponseDto(User entity) { | ||
this.id = entity.getId(); | ||
this.email = entity.getEmail(); | ||
this.nickname = entity.getNickname(); | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
src/main/java/com/moodstation/springboot/service/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,21 @@ | ||
package com.moodstation.springboot.service; | ||
|
||
import com.moodstation.springboot.dto.UserCreateRequestDto; | ||
import com.moodstation.springboot.repository.UserRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import javax.transaction.Transactional; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class UserService { | ||
|
||
private final UserRepository userRepository; | ||
|
||
// 회원가입 | ||
@Transactional | ||
public Long save(UserCreateRequestDto requestDto) { | ||
return userRepository.save(requestDto.toEntity()).getId(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/moodstation/springboot/web/UserApiController.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,23 @@ | ||
package com.moodstation.springboot.web; | ||
|
||
import com.moodstation.springboot.dto.UserCreateRequestDto; | ||
import com.moodstation.springboot.dto.UserCreateResponseDto; | ||
import com.moodstation.springboot.entity.User; | ||
import com.moodstation.springboot.service.UserService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
public class UserApiController { | ||
|
||
private final UserService userService; | ||
|
||
@PostMapping("/api/v1/signup") | ||
public Long signup(@RequestBody UserCreateRequestDto requestDto) { | ||
return userService.save(requestDto); | ||
} | ||
|
||
} |