Skip to content

Commit

Permalink
Feat: 전화번호를 이용한 유저 상태 확인 API
Browse files Browse the repository at this point in the history
  • Loading branch information
koojun99 committed May 27, 2024
1 parent a657434 commit f5067ec
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ public List<Invitation> findAllByPhone(String phone) {
return invitationRepository.findAllByPhone(phone);
}

public Boolean existByPhoneNumber(String phoneNumber) {
return invitationRepository.existsByPhone(phoneNumber);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public interface InvitationRepository extends JpaRepository<Invitation, Long> {
List<Invitation> findAllByPhone(String phone);

Invitation findByPhoneAndTreeHouse(String phone, TreeHouse treeHouse);

Boolean existsByPhone(String phoneNumber);
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,11 @@ public static UserResponseDTO.reissue toReissue(String accessToken, String refre
.refreshToken(refreshToken)
.build();
}

public static UserResponseDTO.checkUserStatus toCheckUserStatus(Boolean isNewUser, Boolean isInvited){
return UserResponseDTO.checkUserStatus.builder()
.isNewUser(isNewUser)
.isInvited(isInvited)
.build();
}
}
10 changes: 10 additions & 0 deletions src/main/java/treehouse/server/api/user/business/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import treehouse.server.api.invitation.implement.InvitationQueryAdapter;
import treehouse.server.api.user.implement.UserCommandAdapter;
import treehouse.server.api.user.implement.UserQueryAdapter;
import treehouse.server.api.user.presentation.dto.UserRequestDTO;
Expand All @@ -30,6 +31,8 @@ public class UserService {

private final RedisService redisService;

private final InvitationQueryAdapter invitationQueryAdapter;

@Transactional(readOnly = true)
public UserResponseDTO.checkName checkName(UserRequestDTO.checkName request){
return UserMapper.toCheckNameDTO(userQueryAdapter.checkName(request));
Expand Down Expand Up @@ -69,4 +72,11 @@ public UserResponseDTO.reissue reissue(UserRequestDTO.reissue request){
}


public UserResponseDTO.checkUserStatus checkUserStatus(UserRequestDTO.checkUserStatus request) {

Boolean isNewUser = !userQueryAdapter.existByPhoneNumber(request.getPhoneNumber());
Boolean isInvited = invitationQueryAdapter.existByPhoneNumber(request.getPhoneNumber());

return UserMapper.toCheckUserStatus(isNewUser, isInvited);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ public User findById(Long id){
public Optional<User> optionalUserFindById(Long id){
return userRepository.findById(id);
}

public Boolean existByPhoneNumber(String phoneNumber) {
return userRepository.existsByPhone(phoneNumber);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,12 @@ public CommonResponse<UserResponseDTO.registerUser> loginTemp(
){
return CommonResponse.onSuccess((userService.login(request)));
}

@PostMapping("/phone")
@Operation(summary = "휴대폰으로 상태 확인", description = "휴대폰 번호로 유저의 상태(신규 유저인지, 초대를 하나라도 받았는지)를 조회합니다.")
public CommonResponse<UserResponseDTO.checkUserStatus> checkPhoneAuth(
@RequestBody final UserRequestDTO.checkUserStatus request
){
return CommonResponse.onSuccess(userService.checkUserStatus(request));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,9 @@ public String toString() {
private String phoneNum;
private Integer authNum;
}

@Getter
public static class checkUserStatus {
private String phoneNumber;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,14 @@ public static class checkPhoneAuth{
public static class checkSentSms{
boolean messageSent;
}

@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class checkUserStatus{

Boolean isNewUser;
Boolean isInvited;
}
}

0 comments on commit f5067ec

Please sign in to comment.