-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/develop' into develop
# Conflicts: # .github/workflows/deploy.yml
- Loading branch information
Showing
9 changed files
with
141 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,7 @@ on: | |
|
||
jobs: | ||
build: | ||
environment: aws | ||
# if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'develop' | ||
if: github.event_name == 'push' | ||
runs-on: ubuntu-latest | ||
|
||
permissions: | ||
|
@@ -22,6 +21,11 @@ jobs: | |
java-version: '17' | ||
distribution: 'oracle' | ||
|
||
- name: echo test | ||
run: | | ||
echo "EC2_PUBLIC_IP: ${{ secrets.EC2_PUBLIC_IP }}" | ||
echo "DB_USERNAME: ${{ secrets.DB_USERNAME }}" | ||
- name: Setup SSH | ||
uses: webfactory/[email protected] | ||
with: | ||
|
@@ -107,4 +111,4 @@ jobs: | |
--deployment-config-name CodeDeployDefault.AllAtOnce | ||
--deployment-group-name ${{ secrets.AWS_CODE_DEPLOY_GROUP }} | ||
--s3-location bucket=${{ secrets.AWS_S3_BUCKET }},key=cicd/$GITHUB_SHA.zip,bundleType=zip | ||
--debug | ||
--debug |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/softeer/backend/fo_domain/user/controller/LoginController.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.softeer.backend.fo_domain.user.controller; | ||
|
||
import com.softeer.backend.fo_domain.user.dto.LoginRequest; | ||
import com.softeer.backend.fo_domain.user.dto.UserTokenResponse; | ||
import com.softeer.backend.fo_domain.user.service.LoginService; | ||
import com.softeer.backend.global.common.code.status.SuccessStatus; | ||
import com.softeer.backend.global.common.response.ResponseDto; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.ModelAttribute; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class LoginController { | ||
|
||
private final LoginService loginService; | ||
|
||
@PostMapping("/login") | ||
ResponseDto<UserTokenResponse> handleLogin(@Valid @ModelAttribute LoginRequest loginRequest){ | ||
UserTokenResponse userTokenResponse = loginService.handleLogin(loginRequest); | ||
|
||
return ResponseDto.onSuccess(SuccessStatus._LOGIN_SUCCESS, userTokenResponse); | ||
} | ||
|
||
} |
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
27 changes: 27 additions & 0 deletions
27
src/main/java/com/softeer/backend/fo_domain/user/dto/LoginRequest.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.softeer.backend.fo_domain.user.dto; | ||
|
||
import com.softeer.backend.global.common.constant.ValidationConstant; | ||
import jakarta.validation.constraints.Pattern; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@Builder | ||
@AllArgsConstructor | ||
public class LoginRequest { | ||
|
||
private String name; | ||
|
||
@Pattern(regexp = ValidationConstant.PHONE_NUMBER_REGEX, | ||
message = ValidationConstant.PHONE_NUMBER_MSG) | ||
private String phoneNumber; | ||
|
||
private boolean isCodeVerified; | ||
|
||
private boolean privacyConsent; | ||
|
||
private boolean marketingConsent; | ||
} |
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
65 changes: 65 additions & 0 deletions
65
src/main/java/com/softeer/backend/fo_domain/user/service/LoginService.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,65 @@ | ||
package com.softeer.backend.fo_domain.user.service; | ||
|
||
import com.softeer.backend.fo_domain.user.domain.User; | ||
import com.softeer.backend.fo_domain.user.dto.LoginRequest; | ||
import com.softeer.backend.fo_domain.user.dto.UserTokenResponse; | ||
import com.softeer.backend.fo_domain.user.exception.UserException; | ||
import com.softeer.backend.fo_domain.user.repository.UserRepository; | ||
import com.softeer.backend.global.common.code.status.ErrorStatus; | ||
import com.softeer.backend.global.common.constant.RoleType; | ||
import com.softeer.backend.global.common.entity.JwtClaimsDto; | ||
import com.softeer.backend.global.util.JwtUtil; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class LoginService { | ||
|
||
private final UserRepository userRepository; | ||
private final JwtUtil jwtUtil; | ||
|
||
/** | ||
* 1. Login 정보애서 인증 번호가 인증되지 않은 경우, 예외가 발생한다. | ||
* 2. 전화번호가 User DB에 등록되어 있지 않은 경우, DB에 User를 등록한다. | ||
* 3. 전화번호가 이미 User DB에 등록되어 있는 경우, 전화번호로 User 객체를 조회한다. | ||
* 4. User 객체의 id를 얻은 후에, access & refresh token을 client에게 전달한다. | ||
*/ | ||
@Transactional | ||
public UserTokenResponse handleLogin(LoginRequest loginRequest) { | ||
|
||
// 인증번호가 인증 되지 않은 경우, 예외 발생 | ||
if(!loginRequest.isCodeVerified()) | ||
throw new UserException(ErrorStatus._AUTH_CODE_NOT_VERIFIED); | ||
|
||
int userId; | ||
|
||
// 전화번호가 User DB에 등록되어 있지 않은 경우 | ||
// User를 DB에 등록 | ||
if(!userRepository.existsByPhoneNumber(loginRequest.getPhoneNumber())){ | ||
User user = User.builder() | ||
.name(loginRequest.getName()) | ||
.phoneNumber(loginRequest.getPhoneNumber()) | ||
.privacyConsent(loginRequest.isPrivacyConsent()) | ||
.marketingConsent(loginRequest.isMarketingConsent()) | ||
.build(); | ||
|
||
User registeredUser = userRepository.save(user); | ||
userId = registeredUser.getId(); | ||
} | ||
// 전화번호가 이미 User DB에 등록되어 있는 경우 | ||
// 전화번호로 User 객체 조회 | ||
else{ | ||
User user = userRepository.findByPhoneNumber(loginRequest.getPhoneNumber()); | ||
userId = user.getId(); | ||
} | ||
|
||
return jwtUtil.createServiceToken(JwtClaimsDto.builder() | ||
.id(userId) | ||
.roleType(RoleType.ROLE_USER) | ||
.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 |
---|---|---|
|
@@ -9,5 +9,4 @@ class BackendApplicationTests { | |
@Test | ||
void contextLoads() { | ||
} | ||
|
||
} |