Skip to content

Commit

Permalink
feat: 이동봉사자, 이동봉사 중개 Entity 변경 적용 (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyeong-hyeok committed Oct 27, 2023
1 parent 436e758 commit b9781d1
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.pawwithu.connectdog.domain.auth.controller;

import com.pawwithu.connectdog.domain.auth.dto.request.SignUpRequest;
import com.pawwithu.connectdog.domain.auth.dto.request.VolunteerSignUpRequest;
import com.pawwithu.connectdog.domain.auth.service.AuthService;
import com.pawwithu.connectdog.error.dto.ErrorResponse;
import io.swagger.v3.oas.annotations.Operation;
Expand All @@ -9,7 +9,6 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand All @@ -31,8 +30,8 @@ public class SignUpController {
, content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@PostMapping
public ResponseEntity<Void> signUp(@RequestBody SignUpRequest signUpRequest) {
authService.signUp(signUpRequest);
public ResponseEntity<Void> signUp(@RequestBody VolunteerSignUpRequest volunteerSignUpRequest) {
authService.signUp(volunteerSignUpRequest);
return ResponseEntity.noContent().build();
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.pawwithu.connectdog.domain.auth.dto.request;

import com.pawwithu.connectdog.domain.volunteer.entity.Volunteer;
import com.pawwithu.connectdog.domain.volunteer.entity.VolunteerRole;

public record VolunteerSignUpRequest(String email, String password, String nickname, Boolean isOptionAgr) {

public Volunteer toEntity() {
return Volunteer.builder()
.email(email)
.password(password)
.nickname(nickname)
.isOptionAgr(isOptionAgr)
.role(VolunteerRole.USER)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.pawwithu.connectdog.domain.auth.service;

import com.pawwithu.connectdog.domain.auth.dto.request.SignUpRequest;
import com.pawwithu.connectdog.domain.member.entity.Member;
import com.pawwithu.connectdog.domain.member.repository.MemberRepository;
import com.pawwithu.connectdog.domain.auth.dto.request.VolunteerSignUpRequest;
import com.pawwithu.connectdog.domain.volunteer.entity.Volunteer;
import com.pawwithu.connectdog.domain.volunteer.repository.VolunteerRepository;
import com.pawwithu.connectdog.error.exception.custom.BadRequestException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -19,21 +19,21 @@
@RequiredArgsConstructor
public class AuthService {

private final MemberRepository memberRepository;
private final VolunteerRepository volunteerRepository;
private final PasswordEncoder passwordEncoder;

public void signUp(SignUpRequest signUpRequest) {
public void signUp(VolunteerSignUpRequest volunteerSignUpRequest) {

if (memberRepository.existsByEmail(signUpRequest.email())) {
if (volunteerRepository.existsByEmail(volunteerSignUpRequest.email())) {
throw new BadRequestException(ALREADY_EXIST_EMAIL);
}
if (memberRepository.existsByNickname(signUpRequest.nickname())) {
if (volunteerRepository.existsByNickname(volunteerSignUpRequest.nickname())) {
throw new BadRequestException(ALREADY_EXIST_NICKNAME);
}

Member member = signUpRequest.toEntity();
member.passwordEncode(passwordEncoder);
memberRepository.save(member);
Volunteer volunteer = volunteerSignUpRequest.toEntity();
volunteer.passwordEncode(passwordEncoder);
volunteerRepository.save(volunteer);
}

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

import com.pawwithu.connectdog.domain.intermediary.entity.Intermediary;
import org.springframework.data.jpa.repository.JpaRepository;

public interface IntermediaryRepository extends JpaRepository<Intermediary, Long> {

Boolean existsByEmail(String email);
Boolean existsByName(String name);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.pawwithu.connectdog.domain.volunteer.repository;

import com.pawwithu.connectdog.domain.volunteer.entity.Volunteer;
import com.pawwithu.connectdog.domain.volunteer.entity.SocialType;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;

public interface VolunteerRepository extends JpaRepository<Volunteer, Long> {

// 소셜 타입과 소셜의 식별값으로 회원 찾는 메소드 -> 추가 정보를 입력받아 회원가입 진행 시 이용
Optional<Volunteer> findBySocialTypeAndSocialId(SocialType socialType, String socialId);
Boolean existsByEmail(String email);
Boolean existsByNickname(String nickname);

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.pawwithu.connectdog.domain.member.entity.Member;
import com.pawwithu.connectdog.domain.member.repository.MemberRepository;
import com.pawwithu.connectdog.domain.volunteer.entity.Volunteer;
import com.pawwithu.connectdog.domain.volunteer.repository.VolunteerRepository;
import com.pawwithu.connectdog.error.exception.custom.TokenException;
import com.pawwithu.connectdog.jwt.util.PasswordUtil;
import com.pawwithu.connectdog.util.RedisUtil;
Expand Down Expand Up @@ -53,7 +53,7 @@ public class JwtService {
private static final String REFRESH_TOKEN_SUBJECT = "RefreshToken";
private static final String ID_CLAIM = "id";
private static final String BEARER = "Bearer ";
private final MemberRepository memberRepository;
private final VolunteerRepository volunteerRepository;
// private final RedisTemplate<String, String> redisTemplate; // 빈 주입 충돌 -> 명시적으로 주입하면 되지만 여기선 쓰이지 않으므로 주석
private final RedisUtil redisUtil;
private GrantedAuthoritiesMapper authoritiesMapper = new NullAuthoritiesMapper();
Expand Down Expand Up @@ -213,25 +213,25 @@ public boolean isRefreshTokenMatch(Long id, String refreshToken) {
public void getAuthentication(String accessToken) {
log.info("인증 처리 메소드 getAuthentication() 호출");
extractId(accessToken)
.ifPresent(id -> memberRepository.findById(id)
.ifPresent(id -> volunteerRepository.findById(id)
.ifPresent(this::saveAuthentication));
}

/**
* [인증 허가 메소드]
* 파라미터의 유저 : 우리가 만든 회원 객체 / 빌더의 유저 : UserDetails의 User 객체
*/
public void saveAuthentication(Member member) {
public void saveAuthentication(Volunteer volunteer) {
log.info("인증 허가 메소드 saveAuthentication() 호출");
String password = member.getPassword();
String password = volunteer.getPassword();
if (password == null) { // 소셜 로그인 유저의 비밀번호 임의로 설정 하여 소셜 로그인 유저도 인증 되도록 설정
password = PasswordUtil.generateRandomPassword();
}

UserDetails userDetailsUser = org.springframework.security.core.userdetails.User.builder()
.username(member.getEmail())
.username(volunteer.getEmail())
.password(password)
.roles(member.getRole().name())
.roles(volunteer.getRole().name())
.build();

Authentication authentication =
Expand Down

0 comments on commit b9781d1

Please sign in to comment.