-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: 회원가입 및 로그인 구현 #16
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0bde105
Fix | #4 | @lcomment | device token 관련 컬럼 추가
lcomment 4c08aa4
Feature | #4 | @lcomment | 회원가입 및 로그인 구현
lcomment b08834f
Chore | #4 | @lcomment | TestContainer 및 테스트 환경 구축
lcomment e0af814
Test | #4 | @lcomment | 회원가입 및 로그인 관련 테스트 작성
lcomment e427cad
Chore | #4 | @lcomment | 테스트 환경 및 환경변수 설정
lcomment 25b2b05
Refactor | #4 | @lcomment | checkstyle 적용
lcomment 643be42
Chore | #4 | @lcomment | gitignore에 항목 추가
lcomment b483b1a
Refactor | #4 | @lcomment | api prefix 설정 방식 변경
lcomment 9d30bd4
Fix | #4 | @lcomment | 통합 테스트 추상 클래스 수정
lcomment File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
cakk-api/src/main/java/com/cakk/api/controller/user/SignController.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.cakk.api.controller.user; | ||
|
||
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; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
import com.cakk.api.dto.request.user.UserSignInRequest; | ||
import com.cakk.api.dto.request.user.UserSignUpRequest; | ||
import com.cakk.api.dto.response.user.JwtResponse; | ||
import com.cakk.api.service.user.UserService; | ||
import com.cakk.common.response.ApiResponse; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1") | ||
public class SignController { | ||
|
||
private final UserService userService; | ||
|
||
@PostMapping("/sign-up") | ||
public ApiResponse<JwtResponse> signUp(@RequestBody UserSignUpRequest request) { | ||
return ApiResponse.success(userService.signUp(request)); | ||
} | ||
|
||
@PostMapping("/sign-in") | ||
public ApiResponse<JwtResponse> signIn(@RequestBody UserSignInRequest request) { | ||
return ApiResponse.success(userService.signIn(request)); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
cakk-api/src/main/java/com/cakk/api/dto/request/user/UserSignInRequest.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,14 @@ | ||
package com.cakk.api.dto.request.user; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotNull; | ||
|
||
import com.cakk.common.enums.Provider; | ||
|
||
public record UserSignInRequest( | ||
@NotNull | ||
Provider provider, | ||
@NotBlank | ||
String idToken | ||
) { | ||
} |
27 changes: 27 additions & 0 deletions
27
cakk-api/src/main/java/com/cakk/api/dto/request/user/UserSignUpRequest.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,27 @@ | ||
package com.cakk.api.dto.request.user; | ||
|
||
import java.time.LocalDate; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotNull; | ||
|
||
import com.cakk.common.enums.Gender; | ||
import com.cakk.common.enums.Provider; | ||
|
||
public record UserSignUpRequest( | ||
@NotNull | ||
Provider provider, | ||
@NotBlank | ||
String idToken, | ||
String deviceOs, | ||
String deviceToken, | ||
@NotBlank | ||
String nickname, | ||
@NotBlank | ||
String email, | ||
@NotNull | ||
LocalDate birthday, | ||
@NotNull | ||
Gender gender | ||
) { | ||
} |
14 changes: 14 additions & 0 deletions
14
cakk-api/src/main/java/com/cakk/api/dto/response/user/JwtResponse.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,14 @@ | ||
package com.cakk.api.dto.response.user; | ||
|
||
import com.cakk.api.vo.JsonWebToken; | ||
|
||
public record JwtResponse( | ||
String accessToken, | ||
String refreshToken, | ||
String grantType | ||
) { | ||
|
||
public static JwtResponse from(JsonWebToken jwt) { | ||
return new JwtResponse(jwt.accessToken(), jwt.refreshToken(), jwt.grantType()); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
cakk-api/src/main/java/com/cakk/api/mapper/UserMapper.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,25 @@ | ||
package com.cakk.api.mapper; | ||
|
||
import com.cakk.api.dto.request.user.UserSignUpRequest; | ||
import com.cakk.common.enums.Role; | ||
import com.cakk.domain.entity.user.User; | ||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class UserMapper { | ||
|
||
public static User supplyUserBy(UserSignUpRequest dto, String providerId) { | ||
return User.builder() | ||
.provider(dto.provider()) | ||
.providerId(providerId) | ||
.nickname(dto.nickname()) | ||
.email(dto.email()) | ||
.gender(dto.gender()) | ||
.birthday(dto.birthday()) | ||
.deviceOs(dto.deviceOs()) | ||
.deviceToken(dto.deviceToken()) | ||
.role(Role.USER) | ||
.build(); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
cakk-api/src/main/java/com/cakk/api/service/user/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 |
---|---|---|
@@ -1,10 +1,42 @@ | ||
package com.cakk.api.service.user; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import com.cakk.api.dto.request.user.UserSignInRequest; | ||
import com.cakk.api.dto.request.user.UserSignUpRequest; | ||
import com.cakk.api.dto.response.user.JwtResponse; | ||
import com.cakk.api.factory.OidcProviderFactory; | ||
import com.cakk.api.mapper.UserMapper; | ||
import com.cakk.api.provider.jwt.JwtProvider; | ||
import com.cakk.domain.entity.user.User; | ||
import com.cakk.domain.repository.reader.UserReader; | ||
import com.cakk.domain.repository.writer.UserWriter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class UserService { | ||
|
||
private final OidcProviderFactory oidcProviderFactory; | ||
private final JwtProvider jwtProvider; | ||
|
||
private final UserReader userReader; | ||
private final UserWriter userWriter; | ||
|
||
@Transactional | ||
public JwtResponse signUp(UserSignUpRequest dto) { | ||
final String providerId = oidcProviderFactory.getProviderId(dto.provider(), dto.idToken()); | ||
final User user = userWriter.create(UserMapper.supplyUserBy(dto, providerId)); | ||
|
||
return JwtResponse.from(jwtProvider.generateToken(user)); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public JwtResponse signIn(UserSignInRequest dto) { | ||
final String providerId = oidcProviderFactory.getProviderId(dto.provider(), dto.idToken()); | ||
final User user = userReader.findByProviderId(providerId); | ||
|
||
return JwtResponse.from(jwtProvider.generateToken(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
6 changes: 5 additions & 1 deletion
6
cakk-domain/src/main/java/com/cakk/domain/repository/jpa/UserJpaRepository.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 |
---|---|---|
@@ -1,7 +1,11 @@ | ||
package com.cakk.domain.repository.jpa; | ||
|
||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.cakk.domain.entity.user.User; | ||
|
||
public interface UserJpaRepository extends JpaRepository<User, Long> { } | ||
public interface UserJpaRepository extends JpaRepository<User, Long> { | ||
|
||
Optional<User> findByProviderId(String providerId); | ||
} |
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
17 changes: 17 additions & 0 deletions
17
cakk-domain/src/main/java/com/cakk/domain/repository/writer/UserWriter.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,17 @@ | ||
package com.cakk.domain.repository.writer; | ||
|
||
import com.cakk.domain.annotation.Writer; | ||
import com.cakk.domain.entity.user.User; | ||
import com.cakk.domain.repository.jpa.UserJpaRepository; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Writer | ||
@RequiredArgsConstructor | ||
public class UserWriter { | ||
|
||
private final UserJpaRepository userJpaRepository; | ||
|
||
public User create(User user) { | ||
return userJpaRepository.save(user); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
혹시 api/v1 앞에 붙는건 환경 변수로 컨트롤하는건 어떤가요??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
수정하겠습니다