-
Notifications
You must be signed in to change notification settings - Fork 1
[FEAT] 하트비트 및 인증로직 추가 #246
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a840625
chore: 웹소켓 하트비트 설정 추가
coli-geonwoo c4a088f
chore: sharing 컨트롤러 리네이밍
coli-geonwoo 53dfa1a
feat: 사회자 토큰 발급 로직 개발
coli-geonwoo 0a75ec1
test: 레포지토리 쿼리 검증
coli-geonwoo a12dd91
test: 토큰 발행 로직 검증
coli-geonwoo 9ab2d02
test: 문서화 테스트 코드 작성
coli-geonwoo 2eca3d8
test: 사회자 검증 테스트 코드 작성
coli-geonwoo 0821655
fix: 토큰 resolve 로직 변경
coli-geonwoo 2fee23e
feat: coalesce를 통한 null 방어로직 추가
coli-geonwoo a93ab77
style: 공백 제거
coli-geonwoo b32d635
refactor: 토큰발급 로직을 컨트롤러 계층으로 이전
coli-geonwoo d6cfeef
test: 서비스 테스트 추가
coli-geonwoo 76b54b3
style: 불필요한 공백 제거
coli-geonwoo 5232baf
style: 불필요한 공백 제거
coli-geonwoo 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
29 changes: 29 additions & 0 deletions
29
src/main/java/com/debatetimer/controller/sharing/SharingRestController.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,29 @@ | ||
| package com.debatetimer.controller.sharing; | ||
|
|
||
| import com.debatetimer.controller.auth.AuthMember; | ||
| import com.debatetimer.controller.tool.jwt.AuthManager; | ||
| import com.debatetimer.domain.member.Member; | ||
| import com.debatetimer.dto.sharing.response.ChairmanTokenResponse; | ||
| import com.debatetimer.service.customize.CustomizeService; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| public class SharingRestController { | ||
|
|
||
| private final CustomizeService customizeService; | ||
| private final AuthManager authManager; | ||
|
|
||
| @GetMapping("/api/share/{tableId}/chairman-token") | ||
| public ChairmanTokenResponse issueChairmanToken( | ||
| @AuthMember Member member, | ||
| @PathVariable("tableId") long tableId | ||
| ) { | ||
| long debateTime = customizeService.findDebateTime(tableId, member); | ||
| String chairmanToken = authManager.issueChairmanToken(member, debateTime * 2); | ||
| return new ChairmanTokenResponse(chairmanToken); | ||
| } | ||
| } | ||
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
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
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
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
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 |
|---|---|---|
|
|
@@ -3,5 +3,6 @@ | |
| public enum TokenType { | ||
|
|
||
| ACCESS_TOKEN, | ||
| REFRESH_TOKEN | ||
| REFRESH_TOKEN, | ||
| CHAIRMAN_TOKEN | ||
| } | ||
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
7 changes: 7 additions & 0 deletions
7
src/main/java/com/debatetimer/dto/sharing/response/ChairmanTokenResponse.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,7 @@ | ||
| package com.debatetimer.dto.sharing.response; | ||
|
|
||
| public record ChairmanTokenResponse( | ||
| String chairmanToken | ||
| ) { | ||
|
|
||
| } |
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
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
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
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
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
59 changes: 59 additions & 0 deletions
59
src/test/java/com/debatetimer/controller/sharing/SharingDocumentTest.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,59 @@ | ||
| package com.debatetimer.controller.sharing; | ||
|
|
||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.ArgumentMatchers.eq; | ||
| import static org.mockito.Mockito.doReturn; | ||
| import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName; | ||
| import static org.springframework.restdocs.payload.JsonFieldType.STRING; | ||
| import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; | ||
| import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; | ||
|
|
||
| import com.debatetimer.controller.BaseDocumentTest; | ||
| import com.debatetimer.controller.RestDocumentationRequest; | ||
| import com.debatetimer.controller.RestDocumentationResponse; | ||
| import com.debatetimer.controller.Tag; | ||
| import com.debatetimer.domain.member.Member; | ||
| import io.restassured.http.ContentType; | ||
| import org.junit.jupiter.api.Nested; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.http.HttpHeaders; | ||
|
|
||
| public class SharingDocumentTest extends BaseDocumentTest { | ||
|
|
||
| @Nested | ||
|
coli-geonwoo marked this conversation as resolved.
|
||
| class IssueChairmanToken { | ||
|
|
||
| private final RestDocumentationRequest requestDocument = request() | ||
| .tag(Tag.SHARING_API) | ||
| .summary("사회자용 토큰 발급") | ||
| .requestHeader(headerWithName(HttpHeaders.AUTHORIZATION).description("액세스 토큰")) | ||
| .pathParameter(parameterWithName("tableId").description("테이블 id")); | ||
|
|
||
| private final RestDocumentationResponse responseDocument = response() | ||
| .responseBodyField( | ||
| fieldWithPath("chairmanToken").type(STRING).description("사회자용 토큰") | ||
| ); | ||
|
|
||
| @Test | ||
| void 사회자_용_토큰_생성_성공() { | ||
| long requestTableId = 1L; | ||
| long debateTime = 500L; | ||
| doReturn(debateTime).when(customizeService) | ||
| .findDebateTime(eq(requestTableId), any(Member.class)); | ||
| doReturn("testToken").when(authManager) | ||
| .issueChairmanToken(any(Member.class), eq(debateTime * 2)); | ||
|
|
||
| var document = document("sharing/get", 200) | ||
| .request(requestDocument) | ||
| .response(responseDocument) | ||
| .build(); | ||
|
|
||
| given(document) | ||
| .contentType(ContentType.JSON) | ||
| .headers(EXIST_MEMBER_HEADER) | ||
| .pathParam("tableId", String.valueOf(requestTableId)) | ||
| .when().get("/api/share/{tableId}/chairman-token") | ||
| .then().statusCode(200); | ||
| } | ||
| } | ||
| } | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.
🧩 Analysis chain
🏁 Script executed:
Repository: debate-timer/debate-timer-be
Length of output: 50385
debateTime * 2곱셈 오버플로우 방어 추가 권장line 26의
long타입 곱셈은 오버플로우 시 조용히 음수 또는 비정상 값을 발생시킵니다.debateTime이 매우 큰 값이면 곱셈 결과가 음수가 되어issueChairmanToken에 부정확한 TTL이 전달될 수 있으므로Math.multiplyExact()를 사용한 방어가 좋습니다.제안 코드
📝 Committable suggestion
🤖 Prompt for AI Agents