-
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 pull request #37 from Likelion12/5-be-회원가입구현
Feat : 회원가입 구현
- Loading branch information
Showing
33 changed files
with
214 additions
and
16 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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Empty file.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Empty file.
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
20 changes: 20 additions & 0 deletions
20
src/main/java/com/example/likelion12/common/exception/ExerciseException.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,20 @@ | ||
package com.example.likelion12.common.exception; | ||
|
||
import com.example.likelion12.common.response.status.ResponseStatus; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class ExerciseException extends RuntimeException{ | ||
|
||
private final ResponseStatus exceptionStatus; | ||
|
||
public ExerciseException(ResponseStatus exceptionStatus) { | ||
super(exceptionStatus.getMessage()); | ||
this.exceptionStatus = exceptionStatus; | ||
} | ||
|
||
public ExerciseException(ResponseStatus exceptionStatus, String message) { | ||
super(message); | ||
this.exceptionStatus = exceptionStatus; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...va/com/example/likelion12/common/exception_handler/ExerciseExceptionControllerAdvice.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,22 @@ | ||
package com.example.likelion12.common.exception_handler; | ||
|
||
import com.example.likelion12.common.exception.ExerciseException; | ||
import com.example.likelion12.common.response.BaseErrorResponse; | ||
import jakarta.annotation.Priority; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
|
||
@Slf4j | ||
@Priority(0) | ||
@RestControllerAdvice | ||
public class ExerciseExceptionControllerAdvice { | ||
@ResponseStatus(HttpStatus.BAD_REQUEST) | ||
@ExceptionHandler(ExerciseException.class) | ||
public BaseErrorResponse handle_ExerciseException(ExerciseException e) { | ||
log.error("[handle_ExerciseException]", e); | ||
return new BaseErrorResponse(e.getExceptionStatus(), e.getMessage()); | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
src/main/java/com/example/likelion12/controller/MemberController.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.example.likelion12.controller; | ||
|
||
import com.example.likelion12.common.response.BaseResponse; | ||
import com.example.likelion12.dto.PostSignupRequest; | ||
import com.example.likelion12.dto.PostSignupResponse; | ||
import com.example.likelion12.service.MemberService; | ||
import lombok.AllArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Slf4j | ||
@RestController | ||
@AllArgsConstructor | ||
@RequestMapping("/user") | ||
public class MemberController { | ||
|
||
private final MemberService memberService; | ||
|
||
@PostMapping("/signup") | ||
public BaseResponse<PostSignupResponse> signUp(@RequestBody PostSignupRequest postSignupRequest){ | ||
log.info("[MemberController.signUp]"); | ||
return new BaseResponse<>(memberService.signUp(postSignupRequest)); | ||
} | ||
} |
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
18 changes: 18 additions & 0 deletions
18
src/main/java/com/example/likelion12/dto/PostSignupRequest.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,18 @@ | ||
package com.example.likelion12.dto; | ||
|
||
import com.example.likelion12.domain.base.BaseGender; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class PostSignupRequest { | ||
/** | ||
* 회원가입 request dto | ||
*/ | ||
private String nickname; | ||
private String profileImage; | ||
private String email; | ||
private BaseGender gender; | ||
private String exercise; | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/example/likelion12/dto/PostSignupResponse.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,14 @@ | ||
package com.example.likelion12.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class PostSignupResponse { | ||
/** | ||
* 회원가입 response dto | ||
*/ | ||
private Long memberId; | ||
private String accessToken; | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/example/likelion12/repository/ExerciseRepository.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,14 @@ | ||
package com.example.likelion12.repository; | ||
|
||
import com.example.likelion12.domain.Exercise; | ||
import com.example.likelion12.domain.base.BaseStatus; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.Optional; | ||
|
||
@Repository | ||
public interface ExerciseRepository extends JpaRepository<Exercise, Long> { | ||
|
||
Optional<Exercise> findByExerciseNameAndStatus(String exerciseName, BaseStatus status); | ||
} |
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/example/likelion12/service/MemberService.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.example.likelion12.service; | ||
|
||
import com.example.likelion12.common.exception.ExerciseException; | ||
import com.example.likelion12.common.exception.MemberException; | ||
import com.example.likelion12.domain.Exercise; | ||
import com.example.likelion12.domain.Member; | ||
import com.example.likelion12.domain.base.BaseGender; | ||
import com.example.likelion12.domain.base.BaseStatus; | ||
import com.example.likelion12.dto.PostSignupRequest; | ||
import com.example.likelion12.dto.PostSignupResponse; | ||
import com.example.likelion12.repository.ExerciseRepository; | ||
import com.example.likelion12.repository.MemberRepository; | ||
import com.example.likelion12.util.JwtProvider; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import static com.example.likelion12.common.response.status.BaseExceptionResponseStatus.ALREADY_EXIST_EMAIL; | ||
import static com.example.likelion12.common.response.status.BaseExceptionResponseStatus.CANNOT_FOUND_EXERCISE; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class MemberService { | ||
|
||
private final MemberRepository memberRepository; | ||
private final ExerciseRepository exerciseRepository; | ||
private final JwtProvider jwtProvider; | ||
private final TokenService tokenService; | ||
|
||
/** | ||
* 회원가입 | ||
*/ | ||
@Transactional | ||
public PostSignupResponse signUp(PostSignupRequest postSignupRequest){ | ||
log.info("[MemberService.signUp]"); | ||
String nickname = postSignupRequest.getNickname(); | ||
String profileImage = postSignupRequest.getProfileImage(); | ||
String email = postSignupRequest.getEmail(); | ||
BaseGender gender = postSignupRequest.getGender(); | ||
String exerciseName = postSignupRequest.getExercise(); | ||
|
||
//동일한 이메일을 가지고 있는 회원이 있는지 확인 | ||
if(memberRepository.existsByEmailAndStatus(email, BaseStatus.ACTIVE)){ | ||
throw new MemberException(ALREADY_EXIST_EMAIL); | ||
}else{ | ||
log.info("[MemberService.signUp] email 검증 완료"); | ||
// 운동명을 가지고 exercise 객체 찾기 | ||
Exercise exercise = exerciseRepository.findByExerciseNameAndStatus(exerciseName, BaseStatus.ACTIVE) | ||
.orElseThrow(()-> new ExerciseException(CANNOT_FOUND_EXERCISE)); | ||
|
||
// 데이터베이스에 저장하기 | ||
Member member = new Member(nickname, email, profileImage, gender, BaseStatus.ACTIVE, exercise); | ||
memberRepository.save(member); | ||
|
||
// 토큰 발급, 레디스에 저장하기 | ||
String accessToken = jwtProvider.createAccessToken(email,member.getMemberId()); | ||
// 반환하기 | ||
tokenService.storeToken(accessToken,member.getMemberId()); | ||
return new PostSignupResponse(member.getMemberId(), accessToken); | ||
} | ||
} | ||
} |
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
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