Skip to content
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

경매 목록 조회 시 인가 기능 추가 #324

Merged
merged 4 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions backend/ddang/src/docs/asciidoc/docs.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ include::{snippets}/auction-controller-test/경매를_등록한다/response-fiel

include::{snippets}/auction-controller-test/첫번째_페이지의_경매_목록을_조회한다/http-request.adoc[]
include::{snippets}/auction-controller-test/첫번째_페이지의_경매_목록을_조회한다/query-parameters.adoc[]
include::{snippets}/auction-controller-test/첫번째_페이지의_경매_목록을_조회한다/request-headers.adoc[]

==== 응답

Expand All @@ -169,6 +170,7 @@ include::{snippets}/auction-controller-test/첫번째_페이지의_경매_목록

include::{snippets}/auction-controller-test/지정한_아이디에_해당하는_경매를_조회한다/http-request.adoc[]
include::{snippets}/auction-controller-test/지정한_아이디에_해당하는_경매를_조회한다/path-parameters.adoc[]
include::{snippets}/auction-controller-test/지정한_아이디에_해당하는_경매를_조회한다/request-headers.adoc[]

==== 응답

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public ResponseEntity<ReadAuctionDetailResponse> read(

@GetMapping
public ResponseEntity<ReadAuctionsResponse> readAllByLastAuctionId(
@AuthenticateUser AuthenticationUserInfo ignored,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

final이.. 필요해요.. 제 눈엔 왜 final 밖에 안 보일까요

현재 사용되지 않는 변수명을 사용하게 될 때 변경하는 게 나을까요? 아니면 주석으로 설명을 달아두는 것이 나을까요?
나중에 잊어버린 상태로 방치된 레거시 코드가 되어버릴까봐 질문 드립니다

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당 파트를 사용을 하지 않는 코드라고 해야 할지 의문이네요...
인가 처리를 위해 있는 코드인 것 같은데 해당 사용자에 대해 추가 처리는 필요 없다 보니..!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

추가적으로 경매 상세 정보의 경우 해당 사용자가 존재하는지 추가적인 검증을 진행하고 목록의 경우 그러지 않고 있습니다.
어느 상황에서는 검증을 하고 어느 상황에서는 안 할지에 대한 기준을 얘기해 볼 필요가 있을 것 같습니다.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ArgumentResolver와 Interceptor는 인증 과정에서 사용하고, 이후 인가 과정이 없으므로 인가에 사용할 AuthenticationUserInfo는 사용하지 않는 코드라고 인식했습니다

경매 상세는 Seller인지 체크할 필요가 있어서 넣은거라 인가 처리를 하고자 하는 의도는 아니었지만 결과적으로는 인가를 수행한 것과 다름이 없어졌네요..이건 확실히 말씀해주신대로 고민을 해 봐야 할 것 같습니다

@RequestParam(required = false) final Long lastAuctionId,
@RequestParam(required = false, defaultValue = "10") final int size
) {
Expand Down
69 changes: 53 additions & 16 deletions backend/ddang/src/main/resources/static/docs/docs.html
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,7 @@ <h4 id="_요청_10"><a class="link" href="#_요청_10">요청</a></h4>
Content-Disposition: form-data; name=request; filename=request
Content-Type: application/json

{"title":"경매 상품 1","description":"이것은 경매 상품 1 입니다.","bidUnit":1000,"startPrice":1000,"closingTime":"2023-08-19T16:30:53.364176","subCategoryId":2,"thirdRegionIds":[3]}
{"title":"경매 상품 1","description":"이것은 경매 상품 1 입니다.","bidUnit":1000,"startPrice":1000,"closingTime":"2023-08-20T09:59:53.172963","subCategoryId":2,"thirdRegionIds":[3]}
--6o2knFse3p53ty9dmcQvWAIx1zInP11uCfbm--</code></pre>
</div>
</div>
Expand Down Expand Up @@ -1335,7 +1335,8 @@ <h4 id="_요청_11"><a class="link" href="#_요청_11">요청</a></h4>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight nowrap"><code class="language-http hljs" data-lang="http">GET /auctions?size=10 HTTP/1.1
Content-Type: application/json</code></pre>
Content-Type: application/json
Authorization: Bearer accessToken</code></pre>
</div>
</div>
<table class="tableblock frame-all grid-all stretch">
Expand All @@ -1360,6 +1361,24 @@ <h4 id="_요청_11"><a class="link" href="#_요청_11">요청</a></h4>
</tr>
</tbody>
</table>
<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 50%;">
<col style="width: 50%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Name</th>
<th class="tableblock halign-left valign-top">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>Authorization</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">회원 Bearer 인증 정보</p></td>
</tr>
</tbody>
</table>
</div>
<div class="sect3">
<h4 id="_응답_11"><a class="link" href="#_응답_11">응답</a></h4>
Expand Down Expand Up @@ -1481,6 +1500,24 @@ <h4 id="_요청_12"><a class="link" href="#_요청_12">요청</a></h4>
</tr>
</tbody>
</table>
<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 50%;">
<col style="width: 50%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Name</th>
<th class="tableblock halign-left valign-top">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>Authorization</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">회원 Bearer 인증 정보</p></td>
</tr>
</tbody>
</table>
</div>
<div class="sect3">
<h4 id="_응답_12"><a class="link" href="#_응답_12">응답</a></h4>
Expand All @@ -1503,8 +1540,8 @@ <h4 id="_응답_12"><a class="link" href="#_응답_12">응답</a></h4>
"lastBidPrice" : null,
"status" : "FAILURE",
"bidUnit" : 1000,
"registerTime" : "2023-08-16T16:30:53",
"closingTime" : "2023-08-16T16:30:53",
"registerTime" : "2023-08-17T09:59:53",
"closingTime" : "2023-08-17T09:59:53",
"directRegions" : [ {
"first" : "서울특별시",
"second" : "강서구",
Expand Down Expand Up @@ -1836,12 +1873,12 @@ <h4 id="_응답_15"><a class="link" href="#_응답_15">응답</a></h4>
"name" : "사용자1",
"profileImage" : "이미지1",
"price" : 10000,
"bidTime" : "2023-08-16T16:30:54"
"bidTime" : "2023-08-17T09:59:54"
}, {
"name" : "사용자2",
"profileImage" : "이미지2",
"price" : 12000,
"bidTime" : "2023-08-16T16:30:54"
"bidTime" : "2023-08-17T09:59:54"
} ]
}</code></pre>
</div>
Expand Down Expand Up @@ -2036,7 +2073,7 @@ <h4 id="_응답_17"><a class="link" href="#_응답_17">응답</a></h4>
"price" : 10000
},
"lastMessage" : {
"createdAt" : "2023-08-16T16:30:55",
"createdAt" : "2023-08-17T09:59:55",
"contents" : "메시지1"
},
"isChatAvailable" : true
Expand All @@ -2054,7 +2091,7 @@ <h4 id="_응답_17"><a class="link" href="#_응답_17">응답</a></h4>
"price" : 20000
},
"lastMessage" : {
"createdAt" : "2023-08-16T16:30:55",
"createdAt" : "2023-08-17T09:59:55",
"contents" : "메시지2"
},
"isChatAvailable" : true
Expand Down Expand Up @@ -2492,7 +2529,7 @@ <h4 id="_응답_20"><a class="link" href="#_응답_20">응답</a></h4>

[ {
"id" : 1,
"createdAt" : "2023-08-16T16:30:55",
"createdAt" : "2023-08-17T09:59:55",
"isMyMessage" : true,
"contents" : "메시지내용"
} ]</code></pre>
Expand Down Expand Up @@ -2642,7 +2679,7 @@ <h4 id="_응답_22"><a class="link" href="#_응답_22">응답</a></h4>
"id" : 1,
"name" : "회원1"
},
"createdTime" : "2023-08-16T16:30:57",
"createdTime" : "2023-08-17T09:59:57",
"auction" : {
"id" : 1,
"title" : "제목"
Expand All @@ -2654,7 +2691,7 @@ <h4 id="_응답_22"><a class="link" href="#_응답_22">응답</a></h4>
"id" : 2,
"name" : "회원2"
},
"createdTime" : "2023-08-16T16:30:57",
"createdTime" : "2023-08-17T09:59:57",
"auction" : {
"id" : 1,
"title" : "제목"
Expand All @@ -2666,7 +2703,7 @@ <h4 id="_응답_22"><a class="link" href="#_응답_22">응답</a></h4>
"id" : 3,
"name" : "회원3"
},
"createdTime" : "2023-08-16T16:30:57",
"createdTime" : "2023-08-17T09:59:57",
"auction" : {
"id" : 1,
"title" : "제목"
Expand Down Expand Up @@ -2830,7 +2867,7 @@ <h4 id="_응답_24"><a class="link" href="#_응답_24">응답</a></h4>
"id" : 1,
"name" : "회원1"
},
"createdTime" : "2023-08-16T16:30:57",
"createdTime" : "2023-08-17T09:59:57",
"chatRoom" : {
"id" : 1
},
Expand All @@ -2841,7 +2878,7 @@ <h4 id="_응답_24"><a class="link" href="#_응답_24">응답</a></h4>
"id" : 1,
"name" : "회원1"
},
"createdTime" : "2023-08-16T16:30:57",
"createdTime" : "2023-08-17T09:59:57",
"chatRoom" : {
"id" : 1
},
Expand All @@ -2852,7 +2889,7 @@ <h4 id="_응답_24"><a class="link" href="#_응답_24">응답</a></h4>
"id" : 1,
"name" : "회원1"
},
"createdTime" : "2023-08-16T16:30:57",
"createdTime" : "2023-08-17T09:59:57",
"chatRoom" : {
"id" : 1
},
Expand Down Expand Up @@ -2920,7 +2957,7 @@ <h4 id="_응답_24"><a class="link" href="#_응답_24">응답</a></h4>
<div id="footer">
<div id="footer-text">
Version 0.0.1-SNAPSHOT<br>
Last updated 2023-08-16 16:29:20 +0900
Last updated 2023-08-17 09:59:27 +0900
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.18.3/highlight.min.js"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,6 @@ void setUp(@Autowired RestDocumentationContextProvider provider) {

final ReadAuctionWithChatRoomIdDto auctionWithChatRoomIdDto =
new ReadAuctionWithChatRoomIdDto(auction, chatRoomDto);

final PrivateClaims privateClaims = new PrivateClaims(1L);

given(mockTokenDecoder.decode(eq(TokenType.ACCESS), anyString())).willReturn(Optional.of(privateClaims));
Expand All @@ -526,6 +525,9 @@ void setUp(@Autowired RestDocumentationContextProvider provider) {
)
.andDo(
restDocs.document(
requestHeaders(
headerWithName("Authorization").description("회원 Bearer 인증 정보")
),
pathParameters(
parameterWithName("auctionId").description("조회하고자 하는 경매 ID")
),
Expand Down Expand Up @@ -630,14 +632,17 @@ void setUp(@Autowired RestDocumentationContextProvider provider) {
"판매자",
3.5d
);

final PrivateClaims privateClaims = new PrivateClaims(1L);
final ReadAuctionsDto readAuctionsDto = new ReadAuctionsDto(List.of(auction2, auction1), true);

given(mockTokenDecoder.decode(eq(TokenType.ACCESS), anyString())).willReturn(Optional.of(privateClaims));
given(auctionService.readAllByLastAuctionId(any(), anyInt())).willReturn(readAuctionsDto);

// when & then
mockMvc.perform(get("/auctions")
.contentType(MediaType.APPLICATION_JSON)
.queryParam("size", "10")
.header(HttpHeaders.AUTHORIZATION, "Bearer accessToken")
)
.andExpectAll(
status().isOk(),
Expand All @@ -656,6 +661,9 @@ void setUp(@Autowired RestDocumentationContextProvider provider) {
)
.andDo(
restDocs.document(
requestHeaders(
headerWithName("Authorization").description("회원 Bearer 인증 정보")
),
queryParameters(
parameterWithName("lastAuctionId").description("마지막으로 조회한 경매 ID").optional(),
parameterWithName("size").description("페이지 크기").optional()
Expand Down
Loading