forked from Kernel360/f1-KernelSquare-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
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 Kernel360#54 from fingersdanny/feat-login
[feat] : 로그인 기능
- Loading branch information
Showing
49 changed files
with
1,735 additions
and
863 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
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
64 changes: 64 additions & 0 deletions
64
src/main/java/com/kernel360/kernelsquare/domain/auth/controller/AuthController.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,64 @@ | ||
package com.kernel360.kernelsquare.domain.auth.controller; | ||
|
||
import static com.kernel360.kernelsquare.global.common_response.response.code.AuthResponseCode.*; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
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; | ||
|
||
import com.kernel360.kernelsquare.domain.auth.dto.LoginRequest; | ||
import com.kernel360.kernelsquare.domain.auth.dto.LoginResponse; | ||
import com.kernel360.kernelsquare.domain.auth.dto.SignUpRequest; | ||
import com.kernel360.kernelsquare.domain.auth.dto.SignUpResponse; | ||
import com.kernel360.kernelsquare.domain.auth.dto.TokenDto; | ||
import com.kernel360.kernelsquare.domain.auth.service.AuthService; | ||
import com.kernel360.kernelsquare.global.common_response.ApiResponse; | ||
import com.kernel360.kernelsquare.global.common_response.ResponseEntityFactory; | ||
|
||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1") | ||
@RequiredArgsConstructor | ||
public class AuthController { | ||
private final AuthService authService; | ||
|
||
@PostMapping("/auth/login") | ||
public ResponseEntity<ApiResponse<LoginResponse>> login(final @RequestBody @Valid LoginRequest loginRequest) { | ||
LoginResponse loginResponse = authService.login(loginRequest); | ||
return ResponseEntityFactory.toResponseEntity(LOGIN_SUCCESS, loginResponse); | ||
} | ||
|
||
@PostMapping("/auth/signup") | ||
public ResponseEntity<ApiResponse<SignUpResponse>> signUp(final @RequestBody @Valid SignUpRequest signUpRequest) { | ||
SignUpResponse signUpResponse = authService.signUp(signUpRequest); | ||
return ResponseEntityFactory.toResponseEntity(SIGN_UP_SUCCESS, signUpResponse); | ||
} | ||
|
||
@PostMapping("/auth/reissue") | ||
public ResponseEntity<ApiResponse<TokenDto>> reissueAccessToken(final @RequestBody TokenDto requestTokenDto) { | ||
TokenDto tokenDto = authService.reissueAccessToken(requestTokenDto); | ||
return ResponseEntityFactory.toResponseEntity(ACCESS_TOKEN_REISSUED, tokenDto); | ||
} | ||
|
||
@PostMapping("/auth/check/email") | ||
public ResponseEntity<ApiResponse> isEmailUnique(final @RequestBody SignUpRequest signUpRequest) { | ||
authService.isEmailUnique(signUpRequest.email()); | ||
return ResponseEntityFactory.toResponseEntity(EMAIL_UNIQUE_VALIDATED); | ||
} | ||
|
||
@PostMapping("/auth/check/nickname") | ||
public ResponseEntity<ApiResponse> isNicknameUnique(final @RequestBody SignUpRequest signUpRequest) { | ||
authService.isNicknameUnique(signUpRequest.nickname()); | ||
return ResponseEntityFactory.toResponseEntity(NICKNAME_UNIQUE_VALIDATED); | ||
} | ||
|
||
@PostMapping("/auth/logout") | ||
public ResponseEntity<ApiResponse> logout(final @RequestBody TokenDto tokenDto) { | ||
authService.logout(tokenDto); | ||
return ResponseEntityFactory.toResponseEntity(LOGOUT_SUCCESS); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/kernel360/kernelsquare/domain/auth/dto/LoginRequest.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,17 @@ | ||
package com.kernel360.kernelsquare.domain.auth.dto; | ||
|
||
import jakarta.validation.constraints.Email; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.Size; | ||
|
||
public record LoginRequest( | ||
@NotBlank(message = "이메일은 필수 입력 항목입니다.") | ||
@Email(message = "이메일 형식을 확인해 주세요") | ||
@Size(min = 5, max = 40, message = "이메일 길이를 확인해 주세요") | ||
String email, | ||
|
||
@NotBlank(message = "비밀번호는 필수 입력 항목입니다.") | ||
@Size(min = 8, max = 16, message = "비밀번호 길이를 확인해 주세요") | ||
String password | ||
) { | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/com/kernel360/kernelsquare/domain/auth/dto/LoginResponse.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,41 @@ | ||
package com.kernel360.kernelsquare.domain.auth.dto; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
import org.springframework.security.core.GrantedAuthority; | ||
|
||
import com.kernel360.kernelsquare.domain.member.entity.Member; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public record LoginResponse( | ||
Long memberId, | ||
String nickname, | ||
Long experience, | ||
String introduction, | ||
String imageUrl, | ||
Long level, | ||
List<String> roles, | ||
TokenDto tokenDto | ||
) { | ||
|
||
public static LoginResponse of(Member member, Collection<? extends GrantedAuthority> authorities, | ||
TokenDto tokenDto) { | ||
List<String> roles = authorities.stream() | ||
.map(String::valueOf) | ||
.toList(); | ||
|
||
return LoginResponse.builder() | ||
.memberId(member.getId()) | ||
.nickname(member.getNickname()) | ||
.experience(member.getExperience()) | ||
.introduction(member.getIntroduction()) | ||
.imageUrl(member.getImageUrl()) | ||
.level(member.getLevel().getName()) | ||
.roles(roles) | ||
.tokenDto(tokenDto) | ||
.build(); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/kernel360/kernelsquare/domain/auth/dto/SignUpRequest.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,37 @@ | ||
package com.kernel360.kernelsquare.domain.auth.dto; | ||
|
||
import com.kernel360.kernelsquare.domain.level.entity.Level; | ||
import com.kernel360.kernelsquare.domain.member.entity.Member; | ||
|
||
import jakarta.validation.constraints.Email; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.Size; | ||
|
||
public record SignUpRequest( | ||
@NotBlank(message = "이메일은 필수 입력 항목입니다.") | ||
@Email(message = "이메일 형식을 확인해 주세요") | ||
@Size(min = 5, max = 40, message = "이메일 길이를 확인해 주세요") | ||
String email, | ||
|
||
@NotBlank(message = "닉네임은 필수 입력 항목입니다.") | ||
@Size(min = 2, max = 8, message = "닉네임 길이를 확인해 주세요") | ||
String nickname, | ||
|
||
@NotBlank(message = "비밀번호는 필수 입력 항목입니다.") | ||
@Size(min = 8, max = 16, message = "비밀번호 길이를 확인해 주세요") | ||
String password | ||
) { | ||
|
||
public static Member toEntity(SignUpRequest signUpRequest, String password, Level | ||
level) { | ||
return Member.builder() | ||
.email(signUpRequest.email()) | ||
.nickname(signUpRequest.nickname()) | ||
.password(password) | ||
.experience(0L) | ||
.imageUrl(null) | ||
.introduction(null) | ||
.level(level) | ||
.build(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/kernel360/kernelsquare/domain/auth/dto/SignUpResponse.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,12 @@ | ||
package com.kernel360.kernelsquare.domain.auth.dto; | ||
|
||
import com.kernel360.kernelsquare.domain.member.entity.Member; | ||
|
||
public record SignUpResponse( | ||
Long memberId | ||
) { | ||
|
||
public static SignUpResponse of(Member member) { | ||
return new SignUpResponse(member.getId()); | ||
} | ||
} |
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
Oops, something went wrong.