-
Notifications
You must be signed in to change notification settings - Fork 1
[feat] 어드민 로그인 기능 구현 #38
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
Open
jinny-l
wants to merge
3
commits into
dev
Choose a base branch
from
feat/#26-admin-sigin
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 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
19 changes: 19 additions & 0 deletions
19
src/main/java/com/flytrap/venusplanner/api/admin/domain/AdminProperties.java
This file contains hidden or 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,19 @@ | ||
| package com.flytrap.venusplanner.api.admin.domain; | ||
|
|
||
| import com.flytrap.venusplanner.global.auth.dto.SessionMember; | ||
| import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
|
||
| @ConfigurationProperties(prefix = "admin") | ||
| public record AdminProperties( | ||
| String code, | ||
| Long id | ||
| ) { | ||
|
|
||
| public boolean isAdminCode(String code) { | ||
| return this.code.equals(code); | ||
| } | ||
|
|
||
| public SessionMember toSessionMember() { | ||
| return new SessionMember(id); | ||
| } | ||
| } |
31 changes: 31 additions & 0 deletions
31
...main/java/com/flytrap/venusplanner/api/admin/presentation/controller/AdminController.java
This file contains hidden or 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,31 @@ | ||
| package com.flytrap.venusplanner.api.admin.presentation.controller; | ||
|
|
||
| import com.flytrap.venusplanner.api.admin.domain.AdminProperties; | ||
| import com.flytrap.venusplanner.api.admin.presentation.dto.request.AdminSignInRequest; | ||
| import jakarta.servlet.http.HttpSession; | ||
| 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; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| public class AdminController { | ||
|
|
||
| private final AdminProperties adminProperties; | ||
|
|
||
| @PostMapping("/api/v1/admin/sign-in") | ||
| public ResponseEntity<Void> signIn( | ||
| @RequestBody AdminSignInRequest request, | ||
| HttpSession httpSession | ||
| ) { | ||
| if (adminProperties.isAdminCode(request.code())) { | ||
| httpSession.setAttribute("admin", adminProperties.toSessionMember()); | ||
|
|
||
| return ResponseEntity.ok().build(); | ||
| } | ||
| return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build(); | ||
| } | ||
| } |
6 changes: 6 additions & 0 deletions
6
.../java/com/flytrap/venusplanner/api/admin/presentation/dto/request/AdminSignInRequest.java
This file contains hidden or 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 com.flytrap.venusplanner.api.admin.presentation.dto.request; | ||
|
|
||
| public record AdminSignInRequest( | ||
| String code | ||
| ) { | ||
| } |
File renamed without changes.
This file contains hidden or 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
32 changes: 32 additions & 0 deletions
32
src/test/java/com/flytrap/venusplanner/acceptance/admin/AdminTest.java
This file contains hidden or 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,32 @@ | ||
| package com.flytrap.venusplanner.acceptance.admin; | ||
|
|
||
| import com.flytrap.venusplanner.api.admin.presentation.dto.request.AdminSignInRequest; | ||
| import com.flytrap.venusplanner.global.AcceptanceTest; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.http.HttpStatus; | ||
|
|
||
| @DisplayName("[인수테스트] Admin 로그인 성공/실패 케이스") | ||
| public class AdminTest extends AcceptanceTest { | ||
|
|
||
| @Test | ||
| void 어드민_로그인_시_성공한다() { | ||
| // when | ||
| var response = 어드민_로그인_요청(); | ||
|
|
||
| // then | ||
| 응답_상태코드_검증(response, HttpStatus.OK); | ||
| } | ||
|
|
||
| @Test | ||
| void 어드민_로그인_시_잘못된_코드로_요청하면_실패한다() { | ||
| // when | ||
| var response = givenJsonRequest() | ||
| .body(new AdminSignInRequest("code")) | ||
| .when().post("/api/v1/admin/sign-in") | ||
| .then().log().all().extract(); | ||
|
|
||
| // then | ||
| 응답_상태코드_검증(response, HttpStatus.UNAUTHORIZED); | ||
| } | ||
| } |
This file contains hidden or 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
Submodule submodule
updated
from ca9c9a to 7ff88e
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.
admin 로그인도 auth 부분이라 auth_member에 있어도 될 것 같아요.