Skip to content

Commit

Permalink
feat: #323 경매 목록 조회 시 인가 기능 추가 (#324)
Browse files Browse the repository at this point in the history
* feat: 경매 상세 조회 api 인가 기능 추가

* test: 경매 목록 조회 api 인가 테스트 추가

* docs: 경매 목록 조회 문서 최신화

* style: final 키워드 추가
  • Loading branch information
apptie authored and swonny committed Oct 6, 2023
1 parent 03fe003 commit 6196339
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 20 deletions.
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 @@ -39,7 +39,7 @@ public class AuctionController {

@PostMapping
public ResponseEntity<CreateAuctionResponse> create(
@AuthenticateUser AuthenticationUserInfo userInfo,
@AuthenticateUser final AuthenticationUserInfo userInfo,
@RequestPart final List<MultipartFile> images,
@RequestPart @Valid final CreateAuctionRequest request
) {
Expand Down Expand Up @@ -71,6 +71,7 @@ public ResponseEntity<ReadAuctionDetailResponse> read(

@GetMapping
public ResponseEntity<ReadAuctionsResponse> readAllByLastAuctionId(
@AuthenticateUser final AuthenticationUserInfo ignored,
@RequestParam(required = false) final Long lastAuctionId,
@RequestParam(required = false, defaultValue = "10") final int size
) {
Expand All @@ -82,7 +83,7 @@ public ResponseEntity<ReadAuctionsResponse> readAllByLastAuctionId(

@DeleteMapping("/{auctionId}")
public ResponseEntity<Void> delete(
@AuthenticateUser AuthenticationUserInfo userInfo,
@AuthenticateUser final AuthenticationUserInfo userInfo,
@PathVariable final Long auctionId
) {
auctionService.deleteByAuctionId(auctionId, userInfo.userId());
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

0 comments on commit 6196339

Please sign in to comment.