Skip to content

Commit

Permalink
Merge pull request #224 from PawWithU/feat/222-get-my-info-api
Browse files Browse the repository at this point in the history
[Feature] 모집자, 봉사자 내 정보 관리 및 모집자명 중복 확인 API 구현
  • Loading branch information
kyeong-hyeok authored Jun 2, 2024
2 parents 67a5780 + 85ef869 commit 6615aef
Show file tree
Hide file tree
Showing 15 changed files with 165 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public SecurityFilterChain filterChain(HttpSecurity http, HandlerMappingIntrospe
.authorizeHttpRequests(request ->
request.requestMatchers(mvcMatcherBuilder.pattern("/volunteers/login")).permitAll()
.requestMatchers(mvcMatcherBuilder.pattern("/intermediaries/login")).permitAll()
.requestMatchers(mvcMatcherBuilder.pattern("/intermediaries/name/isDuplicated")).permitAll()
.requestMatchers(mvcMatcherBuilder.pattern("/volunteers/login/social")).permitAll()
.requestMatchers(mvcMatcherBuilder.pattern("/volunteers/sign-up")).permitAll()
.requestMatchers(mvcMatcherBuilder.pattern("/volunteers/sign-up/email")).permitAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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.IntermediaryNameResponse;
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;
Expand Down Expand Up @@ -109,4 +110,16 @@ public ResponseEntity<IntermediaryPhoneResponse> isIntermediaryPhoneDuplicated(@
IntermediaryPhoneResponse response = authService.isIntermediaryPhoneDuplicated(request);
return ResponseEntity.ok(response);
}

@Operation(summary = "모집자명 중복 여부 검사", description = "모집자명 중복 여부를 검사합니다.",
responses = {@ApiResponse(responseCode = "200", description = "모집자명 중복 여부 검사 성공")
, @ApiResponse(responseCode = "400"
, description = "V1, 모집자명은 필수 입력 값입니다. \t\n M2, 해당 이동봉사 중개를 찾을 수 없습니다."
, content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@PostMapping("/intermediaries/name/isDuplicated")
public ResponseEntity<IntermediaryNameResponse> isIntermediaryNameDuplicated(@RequestBody @Valid IntermediaryNameRequest request) {
IntermediaryNameResponse response = authService.isIntermediaryNameDuplicated(request);
return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.pawwithu.connectdog.domain.auth.dto.request;

import jakarta.validation.constraints.NotBlank;

public record IntermediaryNameRequest(@NotBlank(message = "모집자명은 필수 입력 값입니다.")
String name) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.pawwithu.connectdog.domain.auth.dto.response;

public record IntermediaryNameResponse(Boolean isDuplicated) {
public static IntermediaryNameResponse of(Boolean isDuplicated){
return new IntermediaryNameResponse(isDuplicated);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.pawwithu.connectdog.domain.application.entity.Application;
import com.pawwithu.connectdog.domain.application.repository.ApplicationRepository;
import com.pawwithu.connectdog.domain.auth.dto.request.*;
import com.pawwithu.connectdog.domain.auth.dto.response.IntermediaryNameResponse;
import com.pawwithu.connectdog.domain.auth.dto.response.IntermediaryPhoneResponse;
import com.pawwithu.connectdog.domain.auth.dto.response.VolunteerPhoneResponse;
import com.pawwithu.connectdog.domain.badge.repository.VolunteerBadgeRepository;
Expand Down Expand Up @@ -195,4 +196,11 @@ public void volunteersWithdraw(HttpServletRequest request, String email) {
throw new BadRequestException(VOLUNTEER_WITHDRAW_FAILED);
}
}

@Transactional(readOnly = true)
public IntermediaryNameResponse isIntermediaryNameDuplicated(IntermediaryNameRequest request) {
Boolean isDuplicated = intermediaryRepository.existsByName(request.name());
IntermediaryNameResponse response = IntermediaryNameResponse.of(isDuplicated);
return response;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import com.pawwithu.connectdog.domain.intermediary.dto.request.IntermediaryPasswordRequest;
import com.pawwithu.connectdog.domain.intermediary.dto.response.*;
import com.pawwithu.connectdog.domain.intermediary.service.IntermediaryService;
import com.pawwithu.connectdog.domain.volunteer.dto.request.VolunteerPasswordCheckRequest;
import com.pawwithu.connectdog.domain.volunteer.dto.response.VolunteerPasswordCheckResponse;
import com.pawwithu.connectdog.error.dto.ErrorResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
Expand Down Expand Up @@ -203,4 +201,18 @@ public ResponseEntity<IntermediaryGetNotificationResponse> getNotification(@Auth
IntermediaryGetNotificationResponse response = intermediaryService.getNotification(loginUser.getUsername());
return ResponseEntity.ok(response);
}

@Operation(summary = "모집자 - 설정 - 내 정보 관리", description = "모집자 설정에서 자신의 정보를 조회합니다.",
security = { @SecurityRequirement(name = "bearer-key") },
responses = {@ApiResponse(responseCode = "200", description = "모집자 설정 내 정보 관리 조회 성공")
, @ApiResponse(responseCode = "400"
, description = "M2, 해당 이동봉사 중개를 찾을 수 없습니다."
, content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@GetMapping("/intermediaries/setting/my/info")
public ResponseEntity<IntermediaryGetMySettingInfoResponse> getMySettingInfo(@AuthenticationPrincipal UserDetails loginUser) {
IntermediaryGetMySettingInfoResponse response = intermediaryService.getMySettingInfo(loginUser.getUsername());
return ResponseEntity.ok(response);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.pawwithu.connectdog.domain.intermediary.dto.response;

import com.pawwithu.connectdog.domain.intermediary.entity.Intermediary;

public record IntermediaryGetMySettingInfoResponse(String realName, String phone, String email) {
public static IntermediaryGetMySettingInfoResponse from(Intermediary intermediary) {
return new IntermediaryGetMySettingInfoResponse(intermediary.getRealName(), intermediary.getPhone(), intermediary.getEmail());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import com.pawwithu.connectdog.domain.post.entity.PostStatus;
import com.pawwithu.connectdog.domain.post.repository.CustomPostRepository;
import com.pawwithu.connectdog.domain.review.repository.CustomReviewRepository;
import com.pawwithu.connectdog.domain.volunteer.dto.response.VolunteerPasswordCheckResponse;
import com.pawwithu.connectdog.domain.volunteer.entity.Volunteer;
import com.pawwithu.connectdog.error.exception.custom.BadRequestException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -25,7 +23,6 @@
import java.util.Map;

import static com.pawwithu.connectdog.error.ErrorCode.INTERMEDIARY_NOT_FOUND;
import static com.pawwithu.connectdog.error.ErrorCode.VOLUNTEER_NOT_FOUND;

@Slf4j
@Service
Expand Down Expand Up @@ -177,4 +174,10 @@ public IntermediaryGetNotificationResponse getNotification(String email) {
return response;
}

@Transactional(readOnly = true)
public IntermediaryGetMySettingInfoResponse getMySettingInfo(String email) {
Intermediary intermediary = intermediaryRepository.findByEmail(email).orElseThrow(() -> new BadRequestException(INTERMEDIARY_NOT_FOUND));
IntermediaryGetMySettingInfoResponse response = IntermediaryGetMySettingInfoResponse.from(intermediary);
return response;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,18 @@ public ResponseEntity<VolunteerGetNotificationResponse> getNotification(@Authent
VolunteerGetNotificationResponse response = volunteerService.getNotification(loginUser.getUsername());
return ResponseEntity.ok(response);
}

@Operation(summary = "봉사자 - 설정 - 내 정보 관리", description = "봉사자 설정에서 자신의 정보를 조회합니다.",
security = { @SecurityRequirement(name = "bearer-key") },
responses = {@ApiResponse(responseCode = "200", description = "봉사자 설정 내 정보 관리 조회 성공")
, @ApiResponse(responseCode = "400"
, description = "M2, 해당 이동봉사자를 찾을 수 없습니다."
, content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@GetMapping("/setting/my/info")
public ResponseEntity<VolunteerGetMySettingInfoResponse> getMySettingInfo(@AuthenticationPrincipal UserDetails loginUser) {
VolunteerGetMySettingInfoResponse response = volunteerService.getMySettingInfo(loginUser.getUsername());
return ResponseEntity.ok(response);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.pawwithu.connectdog.domain.volunteer.dto.response;

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

public record VolunteerGetMySettingInfoResponse(String name, String phone, SocialType socialType, String email) {
public static VolunteerGetMySettingInfoResponse of(String name, String phone, SocialType socialType, String email){
return new VolunteerGetMySettingInfoResponse(name, phone, socialType, email);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.pawwithu.connectdog.domain.volunteer.dto.request.NicknameRequest;
import com.pawwithu.connectdog.domain.volunteer.dto.request.VolunteerMyProfileRequest;
import com.pawwithu.connectdog.domain.volunteer.dto.response.*;
import com.pawwithu.connectdog.domain.volunteer.entity.SocialType;
import com.pawwithu.connectdog.domain.volunteer.entity.Volunteer;
import com.pawwithu.connectdog.domain.volunteer.repository.VolunteerRepository;
import com.pawwithu.connectdog.error.ErrorCode;
Expand Down Expand Up @@ -143,4 +144,19 @@ public VolunteerGetNotificationResponse getNotification(String email) {
return response;
}

@Transactional(readOnly = true)
public VolunteerGetMySettingInfoResponse getMySettingInfo(String email) {
Volunteer volunteer = volunteerRepository.findByEmail(email).orElseThrow(() -> new BadRequestException(VOLUNTEER_NOT_FOUND));
String volunteerEmail = null;
SocialType socialType = null;

if (volunteer.getSocialType() != null) {
socialType = volunteer.getSocialType();
} else {
volunteerEmail = volunteer.getEmail();
}

VolunteerGetMySettingInfoResponse response = VolunteerGetMySettingInfoResponse.of(volunteer.getName(), volunteer.getPhone(), socialType, volunteerEmail);
return response;
}
}
Loading

0 comments on commit 6615aef

Please sign in to comment.