-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[KAN-123] feat(functionaltest): 상품 조회 테스트 완료
- Loading branch information
Showing
14 changed files
with
711 additions
and
144 deletions.
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
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 @@ | ||
org.gradle.jvmargs=-Dfile.encoding=UTF-8 |
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,21 +1,16 @@ | ||
= REST DOC EXAMPLE | ||
Rest Documentation 실습 | ||
ifndef::snippets[] | ||
:snippets:build/generated-snippets | ||
endif::[] | ||
|
||
= CMS+ Application API Document | ||
made by Sanghun.Kim | ||
:doctype: book | ||
:icons: font | ||
:source-highlighter: highlightjs | ||
:toc: left | ||
:toclevels: 4 | ||
:sectlinks: | ||
:operation-http-request-title: Example request | ||
:operation-http-response-title: Example response | ||
|
||
[[POST-API]] | ||
== POST | ||
|
||
[[GET-POST]] | ||
=== GET POST | ||
operation::getPost[snippets='http-request,http-response'] | ||
:operation-http-request-title: Request | ||
:operation-http-response-title: Response | ||
|
||
[[POST-POST]] | ||
=== CREATE POST | ||
operation::create Post[snippets='http-request,http-response'] | ||
include::{docdir}/products/products.adoc[] |
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,17 @@ | ||
[[GET-POST]] | ||
=== 상품 조회 | ||
|
||
.Request Header | ||
|=== | ||
|파라미터 |타입 |필수여부 |설명 | ||
|Authorization |String |필수 |인증 키 | ||
|=== | ||
|
||
.Request Parameter | ||
|=== | ||
|파라미터 |타입 |필수여부 |설명 | ||
|page |Integer|선택 |페이지 번호 | ||
|size |Integer|선택 |한 페이지에 표시할 데이터 개수 | ||
|=== | ||
|
||
operation::getProducts[snippets='http-request,http-response'] |
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,4 @@ | ||
[[POST-API]] | ||
== 상품 | ||
|
||
include::{docdir}/products/products-get.adoc[] |
43 changes: 0 additions & 43 deletions
43
server/src/main/java/kr/or/kosa/cmsplusmain/test/controller/PostController.java
This file was deleted.
Oops, something went wrong.
53 changes: 53 additions & 0 deletions
53
...main/java/kr/or/kosa/cmsplusmain/test/domain/products/controller/TProductsController.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,53 @@ | ||
package kr.or.kosa.cmsplusmain.test.domain.products.controller; | ||
|
||
import kr.or.kosa.cmsplusmain.test.domain.products.dto.TProductsResponseDto; | ||
import kr.or.kosa.cmsplusmain.test.domain.products.entity.TProducts; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.*; | ||
import java.util.stream.Collectors; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1/vendor/products") | ||
public class TProductsController { | ||
|
||
private List<TProducts> TProductsList = Arrays.asList( | ||
TProducts.builder().name("제목1").price(1000.0).contractCount(5).createdAt("2024-07-07").notes("내용1").build(), | ||
TProducts.builder().name("제목2").price(2000.0).contractCount(10).createdAt("2024-07-08").notes("내용2").build(), | ||
TProducts.builder().name("제목3").price(3000.0).contractCount(15).createdAt("2024-07-09").notes("내용3").build() | ||
); | ||
|
||
@GetMapping | ||
public ResponseEntity<Map<String, Object>> getProducts(@RequestParam(defaultValue = "0") int page, | ||
@RequestParam(defaultValue = "2") int size) { | ||
int start = page * size; | ||
int end = Math.min((page + 1) * size, TProductsList.size()); | ||
|
||
if (start > TProductsList.size()) { | ||
return ResponseEntity.ok(Map.of( | ||
"page", page, | ||
"size", size, | ||
"totalPage", (TProductsList.size() + size - 1) / size, | ||
"totalCount", TProductsList.size(), | ||
"data", Collections.emptyList() | ||
)); | ||
} | ||
|
||
List<TProductsResponseDto> productsResponseList = this.TProductsList.subList(start, end).stream() | ||
.map(TProductsResponseDto::fromEntity) | ||
.collect(Collectors.toList()); | ||
|
||
Map<String, Object> response = new LinkedHashMap<>(); | ||
response.put("page", page); | ||
response.put("size", size); | ||
response.put("totalPage", (this.TProductsList.size() + size - 1) / size); | ||
response.put("totalCount", this.TProductsList.size()); | ||
response.put("data", productsResponseList); | ||
|
||
return ResponseEntity.ok(response); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...r/src/main/java/kr/or/kosa/cmsplusmain/test/domain/products/dto/TProductsResponseDto.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 kr.or.kosa.cmsplusmain.test.domain.products.dto; | ||
|
||
import kr.or.kosa.cmsplusmain.test.domain.products.entity.TProducts; | ||
import lombok.*; | ||
|
||
@Getter | ||
@Builder | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class TProductsResponseDto { | ||
|
||
private String name; | ||
private double price; | ||
private int contractCount; | ||
private String createdAt; | ||
private String notes; | ||
|
||
public static TProductsResponseDto fromEntity(TProducts tProducts) { | ||
return TProductsResponseDto.builder() | ||
.name(tProducts.getName()) | ||
.contractCount(tProducts.getContractCount()) | ||
.price(tProducts.getPrice()) | ||
.createdAt(tProducts.getCreatedAt()) | ||
.notes(tProducts.getNotes()) | ||
.build(); | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
server/src/main/java/kr/or/kosa/cmsplusmain/test/domain/products/entity/TProducts.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,17 @@ | ||
package kr.or.kosa.cmsplusmain.test.domain.products.entity; | ||
|
||
import lombok.*; | ||
|
||
@Getter | ||
@Builder | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class TProducts { | ||
|
||
private String name; | ||
private double price; | ||
private int contractCount; | ||
private String createdAt; | ||
private String notes; | ||
|
||
} |
11 changes: 0 additions & 11 deletions
11
server/src/main/java/kr/or/kosa/cmsplusmain/test/dto/PostRequestDto.java
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
server/src/main/java/kr/or/kosa/cmsplusmain/test/dto/PostResponseDto.java
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
server/src/main/java/kr/or/kosa/cmsplusmain/test/entity/Post.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.