Skip to content

Commit

Permalink
Merge pull request #169 from PawWithU/feat/167-phone-isDuplicated-api
Browse files Browse the repository at this point in the history
[Feature] 이동봉사자, 모집자 휴대폰 번호 중복 검사 API 구현
  • Loading branch information
hojeong2747 authored May 2, 2024
2 parents 2e5ccf4 + d2ec10a commit bffa116
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public SecurityFilterChain filterChain(HttpSecurity http, HandlerMappingIntrospe
.requestMatchers(mvcMatcherBuilder.pattern("/volunteers/login/social")).permitAll()
.requestMatchers(mvcMatcherBuilder.pattern("/volunteers/sign-up")).permitAll()
.requestMatchers(mvcMatcherBuilder.pattern("/volunteers/sign-up/email")).permitAll()
.requestMatchers(mvcMatcherBuilder.pattern("/intermediaries/phone/isDuplicated")).permitAll()
.requestMatchers(mvcMatcherBuilder.pattern("/intermediaries/sign-up/**")).permitAll()
.requestMatchers(mvcMatcherBuilder.pattern("/reissue-token")).permitAll()
.requestMatchers(mvcMatcherBuilder.pattern("/h2-console/**")).permitAll()
Expand All @@ -80,6 +81,7 @@ public SecurityFilterChain filterChain(HttpSecurity http, HandlerMappingIntrospe
.requestMatchers(mvcMatcherBuilder.pattern("/fcm-test")).permitAll()
.requestMatchers(mvcMatcherBuilder.pattern("/volunteers/posts/{postId}/applications")).hasRole("AUTH_VOLUNTEER")
.requestMatchers(mvcMatcherBuilder.pattern("/intermediaries/**")).hasRole("AUTH_INTERMEDIARY")
.requestMatchers(mvcMatcherBuilder.pattern("/volunteers/phone/isDuplicated")).permitAll()
.anyRequest().authenticated())
.addFilterAfter(customVolunteerAuthFilter(), LogoutFilter.class)
.addFilterAfter(customIntermediaryAuthFilter(), LogoutFilter.class)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.pawwithu.connectdog.domain.auth.controller;

import com.pawwithu.connectdog.domain.auth.dto.request.EmailRequest;
import com.pawwithu.connectdog.domain.auth.dto.request.IntermediarySignUpRequest;
import com.pawwithu.connectdog.domain.auth.dto.request.SocialSignUpRequest;
import com.pawwithu.connectdog.domain.auth.dto.request.VolunteerSignUpRequest;
import com.pawwithu.connectdog.domain.auth.dto.request.*;
import com.pawwithu.connectdog.domain.auth.dto.response.EmailResponse;
import com.pawwithu.connectdog.domain.auth.dto.response.IntermediaryPhoneResponse;
import com.pawwithu.connectdog.domain.auth.dto.response.VolunteerPhoneResponse;
import com.pawwithu.connectdog.domain.auth.service.AuthService;
import com.pawwithu.connectdog.domain.auth.service.EmailService;
import com.pawwithu.connectdog.error.dto.ErrorResponse;
Expand Down Expand Up @@ -88,4 +87,27 @@ public ResponseEntity<Void> volunteerSocialSignUp(@AuthenticationPrincipal UserD
return ResponseEntity.noContent().build();
}

@Operation(summary = "이동봉사자 - 휴대폰 번호 중복 여부 검사", description = "이동봉사자 휴대폰 번호 중복 여부를 검사합니다.",
responses = {@ApiResponse(responseCode = "200", description = "휴대폰 번호 중복 여부 검사 성공")
, @ApiResponse(responseCode = "400"
, description = "V1, 휴대전화 번호는 필수 입력 값입니다. \t\n V1, 유효하지 않은 휴대전화 번호입니다. \t\n M1, 해당 이동봉사자를 찾을 수 없습니다."
, content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@PostMapping("/volunteers/phone/isDuplicated")
public ResponseEntity<VolunteerPhoneResponse> isVolunteerPhoneDuplicated(@RequestBody @Valid VolunteerPhoneRequest request) {
VolunteerPhoneResponse response = authService.isVolunteerPhoneDuplicated(request);
return ResponseEntity.ok(response);
}

@Operation(summary = "이동봉사 중개 - 휴대폰 번호 중복 여부 검사", description = "이동봉사 중개 휴대폰 번호 중복 여부를 검사합니다.",
responses = {@ApiResponse(responseCode = "200", description = "휴대폰 번호 중복 여부 검사 성공")
, @ApiResponse(responseCode = "400"
, description = "V1, 휴대전화 번호는 필수 입력 값입니다. \t\n V1, 유효하지 않은 휴대전화 번호입니다. \t\n M2, 해당 이동봉사 중개를 찾을 수 없습니다."
, content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@PostMapping("/intermediaries/phone/isDuplicated")
public ResponseEntity<IntermediaryPhoneResponse> isIntermediaryPhoneDuplicated(@RequestBody @Valid IntermediaryPhoneRequest request) {
IntermediaryPhoneResponse response = authService.isIntermediaryPhoneDuplicated(request);
return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.pawwithu.connectdog.domain.auth.dto.request;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;

public record IntermediaryPhoneRequest(@NotBlank(message = "휴대전화 번호는 필수 입력 값입니다.")
@Pattern(regexp = "^010[0-9]{8}$", message = "유효하지 않은 휴대전화 번호입니다.")
String phone) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.pawwithu.connectdog.domain.auth.dto.request;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;

public record VolunteerPhoneRequest (@NotBlank(message = "휴대전화 번호는 필수 입력 값입니다.")
@Pattern(regexp = "^010[0-9]{8}$", message = "유효하지 않은 휴대전화 번호입니다.")
String phone) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.pawwithu.connectdog.domain.auth.dto.response;

public record IntermediaryPhoneResponse(Boolean isDuplicated, String email) {
public static IntermediaryPhoneResponse of(Boolean isDuplicated, String email){
return new IntermediaryPhoneResponse(isDuplicated, email);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.pawwithu.connectdog.domain.auth.dto.response;

import com.pawwithu.connectdog.domain.volunteer.entity.SocialType;

public record VolunteerPhoneResponse(Boolean isDuplicated, SocialType socialType, String email) {
public static VolunteerPhoneResponse of(Boolean isDuplicated, SocialType socialType, String email){
return new VolunteerPhoneResponse(isDuplicated, socialType, email);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.pawwithu.connectdog.domain.auth.service;

import com.pawwithu.connectdog.common.s3.FileService;
import com.pawwithu.connectdog.domain.auth.dto.request.IntermediarySignUpRequest;
import com.pawwithu.connectdog.domain.auth.dto.request.SocialSignUpRequest;
import com.pawwithu.connectdog.domain.auth.dto.request.VolunteerSignUpRequest;
import com.pawwithu.connectdog.domain.auth.dto.request.*;
import com.pawwithu.connectdog.domain.auth.dto.response.IntermediaryPhoneResponse;
import com.pawwithu.connectdog.domain.auth.dto.response.VolunteerPhoneResponse;
import com.pawwithu.connectdog.domain.fcm.repository.IntermediaryFcmRepository;
import com.pawwithu.connectdog.domain.fcm.repository.VolunteerFcmRepository;
import com.pawwithu.connectdog.domain.intermediary.entity.Intermediary;
import com.pawwithu.connectdog.domain.intermediary.repository.IntermediaryRepository;
import com.pawwithu.connectdog.domain.volunteer.entity.SocialType;
import com.pawwithu.connectdog.domain.volunteer.entity.Volunteer;
import com.pawwithu.connectdog.domain.volunteer.entity.VolunteerRole;
import com.pawwithu.connectdog.domain.volunteer.repository.VolunteerRepository;
Expand Down Expand Up @@ -114,4 +115,34 @@ public void intermediariesLogout(HttpServletRequest request, String email) {
intermediaryFcmRepository.deleteByIntermediaryId(intermediary.getId());
redisUtil.setBlackList(accessToken, "accessToken", jwtService.getAccessTokenExpirationPeriod());
}

@Transactional(readOnly = true)
public VolunteerPhoneResponse isVolunteerPhoneDuplicated(VolunteerPhoneRequest request) {
Boolean isDuplicated = volunteerRepository.existsByPhone(request.phone());
String email = null;
SocialType socialType = null;

if (isDuplicated) {
Volunteer volunteer = volunteerRepository.findByPhone(request.phone()).orElseThrow(() -> new BadRequestException(VOLUNTEER_NOT_FOUND));
socialType = volunteer.getSocialType();
email = volunteer.getEmail();
}

VolunteerPhoneResponse response = VolunteerPhoneResponse.of(isDuplicated, socialType, email);
return response;
}

@Transactional(readOnly = true)
public IntermediaryPhoneResponse isIntermediaryPhoneDuplicated(IntermediaryPhoneRequest request) {
Boolean isDuplicated = intermediaryRepository.existsByPhone(request.phone());
String email = null;

if (isDuplicated) {
Intermediary intermediary = intermediaryRepository.findByPhone(request.phone()).orElseThrow(() -> new BadRequestException(INTERMEDIARY_NOT_FOUND));
email = intermediary.getEmail();
}

IntermediaryPhoneResponse response = IntermediaryPhoneResponse.of(isDuplicated, email);
return response;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ public interface IntermediaryRepository extends JpaRepository<Intermediary, Long
Boolean existsByName(String name);
Optional<Intermediary> findByEmail(String email);
Boolean existsByPhone(String phone);
Optional<Intermediary> findByPhone(String phone);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ public interface VolunteerRepository extends JpaRepository<Volunteer, Long> {
Boolean existsByNickname(String nickname);
Optional<Volunteer> findByEmail(String email);
Boolean existsByPhone(String phone);

Optional<Volunteer> findByPhone(String phone);
}
Loading

0 comments on commit bffa116

Please sign in to comment.