Skip to content

Commit

Permalink
[KAN-123] feat(functionaltest): 상품 조회 테스트 완료
Browse files Browse the repository at this point in the history
  • Loading branch information
rlatkd committed Jul 6, 2024
1 parent 3631c4a commit 2c4ff21
Show file tree
Hide file tree
Showing 14 changed files with 711 additions and 144 deletions.
18 changes: 11 additions & 7 deletions server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,22 @@ asciidoctor {
inputs.dir snippetsDir
configurations 'asciidoctorExtensions'
dependsOn test
sources {
include("**/*.adoc")
}
baseDirFollowsSourceFile()
}

bootJar {
task copyDocs(type: Copy) {
dependsOn asciidoctor
from "${asciidoctor.outputDir}"
into "src/main/resources/static/docs" // src/main/resources/static/docs로 복사
}

// build 경로 안에 있는 index.html을 밖으로 꺼내준다.
copy {
from "${asciidoctor.outputDir}"
into "src/main/resources/static/docs" // src/main/resources/static/docs로 복사
}

build {
dependsOn copyDocs
}

/**
* QueryDSL Build Options
*/
Expand Down
1 change: 1 addition & 0 deletions server/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.gradle.jvmargs=-Dfile.encoding=UTF-8
23 changes: 9 additions & 14 deletions server/src/docs/asciidoc/index.adoc
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[]
17 changes: 17 additions & 0 deletions server/src/docs/asciidoc/products/products-get.adoc
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']
4 changes: 4 additions & 0 deletions server/src/docs/asciidoc/products/products.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[[POST-API]]
== 상품

include::{docdir}/products/products-get.adoc[]

This file was deleted.

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);
}
}
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();
}

}
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;

}

This file was deleted.

This file was deleted.

12 changes: 0 additions & 12 deletions server/src/main/java/kr/or/kosa/cmsplusmain/test/entity/Post.java

This file was deleted.

Loading

0 comments on commit 2c4ff21

Please sign in to comment.