-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PC-379] 어드민 모듈 로그인 기능 #34
Merged
Lujaec
merged 5 commits into
feature/PC-382-admin-update-member-status
from
feature/PC-379-admin-sign-in
Jan 25, 2025
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.yapp.auth.application; | ||
|
||
public enum AdminRole { | ||
ADMIN, | ||
ROLE_ADMIN; | ||
} |
40 changes: 40 additions & 0 deletions
40
admin/src/main/java/org/yapp/auth/application/AuthService.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,40 @@ | ||
package org.yapp.auth.application; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Service; | ||
import org.yapp.auth.AuthToken; | ||
import org.yapp.auth.AuthTokenGenerator; | ||
import org.yapp.auth.application.dto.LoginDto; | ||
import org.yapp.domain.user.User; | ||
import org.yapp.error.code.auth.AuthErrorCode; | ||
import org.yapp.error.exception.ApplicationException; | ||
import org.yapp.user.application.UserService; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class AuthService { | ||
|
||
private final UserService userService; | ||
|
||
private final AuthTokenGenerator authTokenGenerator; | ||
|
||
@Value("${admin.password}") | ||
private String PWD; | ||
|
||
public AuthToken login(LoginDto loginDto) { | ||
String oauthId = loginDto.oauthId(); | ||
String password = loginDto.password(); | ||
|
||
User loginUser = userService.getUserByOauthId(oauthId); | ||
|
||
if (password.equals(PWD) && loginUser.getRole().equals(AdminRole.ADMIN.toString())) { | ||
return authTokenGenerator.generate(loginUser.getId(), null, | ||
AdminRole.ROLE_ADMIN.toString()); | ||
} else { | ||
throw new ApplicationException(AuthErrorCode.ACCESS_DENIED); | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
admin/src/main/java/org/yapp/auth/application/dto/LoginDto.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,5 @@ | ||
package org.yapp.auth.application.dto; | ||
|
||
public record LoginDto(String oauthId, String password) { | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
admin/src/main/java/org/yapp/auth/presentation/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,28 @@ | ||
package org.yapp.auth.presentation; | ||
|
||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
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 org.yapp.auth.AuthToken; | ||
import org.yapp.auth.application.AuthService; | ||
import org.yapp.auth.presentation.request.LoginRequest; | ||
import org.yapp.util.CommonResponse; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/admin/v1/auth/") | ||
public class AuthController { | ||
|
||
private final AuthService authService; | ||
|
||
@PostMapping("/login") | ||
public ResponseEntity<CommonResponse<AuthToken>> login( | ||
@RequestBody @Valid LoginRequest loginRequest) { | ||
AuthToken authToken = authService.login(loginRequest.toDto()); | ||
return ResponseEntity.ok(CommonResponse.createSuccess(authToken)); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
admin/src/main/java/org/yapp/auth/presentation/request/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,11 @@ | ||
package org.yapp.auth.presentation.request; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import org.yapp.auth.application.dto.LoginDto; | ||
|
||
public record LoginRequest(@NotNull String loginId, @NotNull String password) { | ||
|
||
public LoginDto toDto() { | ||
return new LoginDto(loginId, password); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
spring: | ||
profiles: | ||
include: db | ||
include: db, secret |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
에러 메시지 한글로 하는 거 좋은 것 같습니다!
앞으로는 에러메시지 한글로 할까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
에러 메시지가 한글인게 더 명확한 것 같습니다 !
그리고, 에러가 발생한 응답이 전달될때 클라이언트 분들은 저희 서비스만의 에러 코드(ex. 1404, 1402 ...)가 같이 전달되었으면 하는 바람이 있으신 것 같습니다. 한글로 변환하는 김에 저희 서비스 에러코드도 지정하는 것이 어떨까요 ?