Skip to content

Commit

Permalink
docs: API 명세서 PageResponse 로 변경
Browse files Browse the repository at this point in the history
API 명세서 변경
  • Loading branch information
yunjunghun0116 committed Aug 1, 2024
1 parent 516b4e0 commit 864ab8c
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 39 deletions.
4 changes: 2 additions & 2 deletions src/main/java/gift/controller/GiftOrderController.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package gift.controller;

import gift.controller.api.GiftOrderApi;
import gift.dto.giftorder.GiftOrderPageResponse;
import gift.dto.giftorder.GiftOrderRequest;
import gift.dto.giftorder.GiftOrderResponse;
import gift.dto.page.PageResponse;
import gift.service.GiftOrderService;
import gift.service.KakaoService;
import gift.service.OptionService;
Expand Down Expand Up @@ -51,7 +51,7 @@ public ResponseEntity<GiftOrderResponse> getOrder(@PathVariable Long id) {
}

@GetMapping
public ResponseEntity<PageResponse<GiftOrderResponse>> getOrders(@RequestAttribute("memberId") Long memberId, @PageableDefault(sort = "id", direction = Sort.Direction.DESC) Pageable pageable) {
public ResponseEntity<GiftOrderPageResponse> getOrders(@RequestAttribute("memberId") Long memberId, @PageableDefault(sort = "id", direction = Sort.Direction.DESC) Pageable pageable) {
var orders = giftOrderService.getGiftOrders(memberId, pageable);
return ResponseEntity.ok(orders);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/gift/controller/ProductController.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package gift.controller;

import gift.controller.api.ProductApi;
import gift.dto.page.PageResponse;
import gift.dto.product.ProductAddRequest;
import gift.dto.product.ProductPageResponse;
import gift.dto.product.ProductResponse;
import gift.dto.product.ProductUpdateRequest;
import gift.service.ProductService;
Expand Down Expand Up @@ -52,7 +52,7 @@ public ResponseEntity<ProductResponse> getProduct(@PathVariable Long id) {
}

@GetMapping
public ResponseEntity<PageResponse<ProductResponse>> getProducts(@RequestParam(required = false) Long categoryId, @PageableDefault(sort = "id", direction = Sort.Direction.DESC) Pageable pageable) {
public ResponseEntity<ProductPageResponse> getProducts(@RequestParam(required = false) Long categoryId, @PageableDefault(sort = "id", direction = Sort.Direction.DESC) Pageable pageable) {
if (categoryId == null) {
var products = productService.getProducts(pageable);
return ResponseEntity.ok(products);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/gift/controller/WishProductController.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package gift.controller;

import gift.controller.api.WishProductApi;
import gift.dto.page.PageResponse;
import gift.dto.wishproduct.WishProductAddRequest;
import gift.dto.wishproduct.WishProductPageResponse;
import gift.dto.wishproduct.WishProductResponse;
import gift.dto.wishproduct.WishProductUpdateRequest;
import gift.service.WishProductService;
Expand Down Expand Up @@ -52,7 +52,7 @@ public ResponseEntity<WishProductResponse> getWishProduct(@RequestAttribute("mem
}

@GetMapping
public ResponseEntity<PageResponse<WishProductResponse>> getWishProducts(@RequestAttribute("memberId") Long memberId, @PageableDefault(sort = "id", direction = Sort.Direction.DESC) Pageable pageable) {
public ResponseEntity<WishProductPageResponse> getWishProducts(@RequestAttribute("memberId") Long memberId, @PageableDefault(sort = "id", direction = Sort.Direction.DESC) Pageable pageable) {
var wishProducts = wishProductService.getWishProducts(memberId, pageable);
return ResponseEntity.ok(wishProducts);
}
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/gift/controller/api/GiftOrderApi.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package gift.controller.api;

import gift.dto.giftorder.GiftOrderPageResponse;
import gift.dto.giftorder.GiftOrderRequest;
import gift.dto.giftorder.GiftOrderResponse;
import gift.dto.page.PageResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
Expand Down Expand Up @@ -34,11 +33,11 @@ public interface GiftOrderApi {

@Operation(summary = "회원의 모든 주문을 페이지 단위로 조회한다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "모든 주문 조회 성공", content = @Content(array = @ArraySchema(schema = @Schema(implementation = GiftOrderResponse.class)))),
@ApiResponse(responseCode = "200", description = "모든 주문 조회 성공", content = @Content(schema = @Schema(implementation = GiftOrderPageResponse.class))),
@ApiResponse(responseCode = "401", description = "허용되지 않는 요청", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "500", description = "내부 서버의 오류", content = @Content(schema = @Schema(hidden = true)))
})
ResponseEntity<PageResponse<GiftOrderResponse>> getOrders(Long memberId, Pageable pageable);
ResponseEntity<GiftOrderPageResponse> getOrders(Long memberId, Pageable pageable);

@Operation(summary = "특정 주문을 삭제한다.")
@ApiResponses(value = {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gift/controller/api/OptionApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public interface OptionApi {
})
ResponseEntity<OptionResponse> getOption(Long productId, Long id);

@Operation(summary = "모든 옵션을 페이지 단위로 조회한다.")
@Operation(summary = "모든 옵션을 조회한다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "모든 옵션 조회 성공", content = @Content(array = @ArraySchema(schema = @Schema(implementation = OptionResponse.class)))),
@ApiResponse(responseCode = "401", description = "허용되지 않는 요청", content = @Content(schema = @Schema(hidden = true))),
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/gift/controller/api/ProductApi.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package gift.controller.api;

import gift.dto.page.PageResponse;
import gift.dto.product.ProductAddRequest;
import gift.dto.product.ProductPageResponse;
import gift.dto.product.ProductResponse;
import gift.dto.product.ProductUpdateRequest;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
Expand Down Expand Up @@ -45,11 +44,11 @@ public interface ProductApi {

@Operation(summary = "모든 상품을 페이지 단위로 조회한다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "모든 상품 조회 성공", content = @Content(array = @ArraySchema(schema = @Schema(implementation = ProductResponse.class)))),
@ApiResponse(responseCode = "200", description = "모든 상품 조회 성공", content = @Content(schema = @Schema(implementation = ProductPageResponse.class))),
@ApiResponse(responseCode = "401", description = "허용되지 않는 요청", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "500", description = "내부 서버의 오류", content = @Content(schema = @Schema(hidden = true)))
})
ResponseEntity<PageResponse<ProductResponse>> getProducts(Long categoryId, Pageable pageable);
ResponseEntity<ProductPageResponse> getProducts(Long categoryId, Pageable pageable);

@Operation(summary = "특정 상품을 삭제한다.")
@ApiResponses(value = {
Expand Down
12 changes: 5 additions & 7 deletions src/main/java/gift/controller/api/WishProductApi.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package gift.controller.api;

import gift.dto.option.OptionResponse;
import gift.dto.page.PageResponse;
import gift.dto.wishproduct.WishProductAddRequest;
import gift.dto.wishproduct.WishProductPageResponse;
import gift.dto.wishproduct.WishProductResponse;
import gift.dto.wishproduct.WishProductUpdateRequest;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
Expand All @@ -20,7 +18,7 @@ public interface WishProductApi {

@Operation(summary = "회원의 위시 리스트에 상품을 추가한다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "201", description = "위시 리스트 추가 성공", content = @Content(schema = @Schema(implementation = OptionResponse.class))),
@ApiResponse(responseCode = "201", description = "위시 리스트 추가 성공", content = @Content(schema = @Schema(implementation = WishProductResponse.class))),
@ApiResponse(responseCode = "401", description = "허용되지 않는 요청", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "500", description = "내부 서버의 오류", content = @Content(schema = @Schema(hidden = true)))
})
Expand All @@ -36,7 +34,7 @@ public interface WishProductApi {

@Operation(summary = "회원의 특정 위시 리스트를 조회한다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "특정 위시 리스트 조회 성공", content = @Content(schema = @Schema(implementation = OptionResponse.class))),
@ApiResponse(responseCode = "200", description = "특정 위시 리스트 조회 성공", content = @Content(schema = @Schema(implementation = WishProductResponse.class))),
@ApiResponse(responseCode = "400", description = "특정 위시 리스트 조회 실패(사유 : 다른 사람의 위시 리스트는 접근할 수 없습니다.)", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "401", description = "허용되지 않는 요청", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "500", description = "내부 서버의 오류", content = @Content(schema = @Schema(hidden = true)))
Expand All @@ -45,11 +43,11 @@ public interface WishProductApi {

@Operation(summary = "회원의 위시 리스트에 있는 상품을 페이지 단위로 조회한다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "모든 위시 리스트 조회 성공", content = @Content(array = @ArraySchema(schema = @Schema(implementation = WishProductResponse.class)))),
@ApiResponse(responseCode = "200", description = "모든 위시 리스트 조회 성공", content = @Content(schema = @Schema(implementation = WishProductPageResponse.class))),
@ApiResponse(responseCode = "401", description = "허용되지 않는 요청", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "500", description = "내부 서버의 오류", content = @Content(schema = @Schema(hidden = true)))
})
ResponseEntity<PageResponse<WishProductResponse>> getWishProducts(Long memberId, Pageable pageable);
ResponseEntity<WishProductPageResponse> getWishProducts(Long memberId, Pageable pageable);

@Operation(summary = "회원의 위시 리스트에서 상품을 삭제한다.")
@ApiResponses(value = {
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/gift/dto/giftorder/GiftOrderPageResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package gift.dto.giftorder;

import java.util.List;

public record GiftOrderPageResponse(Integer page, Integer size, Long totalElements, Integer totalPages, List<GiftOrderResponse> content) {
}
6 changes: 0 additions & 6 deletions src/main/java/gift/dto/page/PageResponse.java

This file was deleted.

6 changes: 6 additions & 0 deletions src/main/java/gift/dto/product/ProductPageResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package gift.dto.product;

import java.util.List;

public record ProductPageResponse(Integer page, Integer size, Long totalElements, Integer totalPages, List<ProductResponse> content) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package gift.dto.wishproduct;

import java.util.List;

public record WishProductPageResponse(Integer page, Integer size, Long totalElements, Integer totalPages, List<WishProductResponse> content) {
}
6 changes: 3 additions & 3 deletions src/main/java/gift/service/GiftOrderService.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package gift.service;

import gift.dto.giftorder.GiftOrderPageResponse;
import gift.dto.giftorder.GiftOrderRequest;
import gift.dto.giftorder.GiftOrderResponse;
import gift.dto.option.OptionResponse;
import gift.dto.page.PageResponse;
import gift.dto.product.ProductBasicInformation;
import gift.exception.NotFoundElementException;
import gift.model.GiftOrder;
Expand Down Expand Up @@ -42,15 +42,15 @@ public GiftOrderResponse getGiftOrder(Long id) {
}

@Transactional(readOnly = true)
public PageResponse<GiftOrderResponse> getGiftOrders(Long memberId, Pageable pageable) {
public GiftOrderPageResponse getGiftOrders(Long memberId, Pageable pageable) {
var pageResult = giftOrderRepository.findAllByMemberId(memberId, pageable);
var orders = pageResult
.getContent()
.stream()
.map(this::getGiftOrderResponseFromGiftOrder)
.toList();

return new PageResponse<>(pageResult.getNumber(), pageResult.getSize(), pageResult.getTotalElements(), pageResult.getTotalPages(), orders);
return new GiftOrderPageResponse(pageResult.getNumber(), pageResult.getSize(), pageResult.getTotalElements(), pageResult.getTotalPages(), orders);
}

public void deleteOrder(Long id) {
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/gift/service/ProductService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import gift.dto.category.CategoryResponse;
import gift.dto.option.OptionRequest;
import gift.dto.page.PageResponse;
import gift.dto.product.ProductAddRequest;
import gift.dto.product.ProductPageResponse;
import gift.dto.product.ProductResponse;
import gift.dto.product.ProductUpdateRequest;
import gift.exception.InvalidProductNameWithKAKAOException;
Expand Down Expand Up @@ -54,26 +54,26 @@ public ProductResponse getProduct(Long id) {
}

@Transactional(readOnly = true)
public PageResponse<ProductResponse> getProducts(Pageable pageable) {
public ProductPageResponse getProducts(Pageable pageable) {
var pageResult = productRepository.findAll(pageable);
var products = pageResult
.getContent()
.stream()
.map(this::getProductResponseFromProduct)
.toList();
return new PageResponse<>(pageResult.getNumber(), pageResult.getSize(), pageResult.getTotalElements(), pageResult.getTotalPages(), products);
return new ProductPageResponse(pageResult.getNumber(), pageResult.getSize(), pageResult.getTotalElements(), pageResult.getTotalPages(), products);
}

@Transactional(readOnly = true)
public PageResponse<ProductResponse> getProducts(Long categoryId, Pageable pageable) {
public ProductPageResponse getProducts(Long categoryId, Pageable pageable) {
var pageResult = productRepository.findAllByCategoryId(categoryId, pageable);
var products = pageResult
.getContent()
.stream()
.map(this::getProductResponseFromProduct)
.toList();

return new PageResponse<>(pageResult.getNumber(), pageResult.getSize(), pageResult.getTotalElements(), pageResult.getTotalPages(), products);
return new ProductPageResponse(pageResult.getNumber(), pageResult.getSize(), pageResult.getTotalElements(), pageResult.getTotalPages(), products);
}

public void deleteProduct(Long productId) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/gift/service/WishProductService.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package gift.service;

import gift.dto.page.PageResponse;
import gift.dto.product.ProductBasicInformation;
import gift.dto.wishproduct.WishProductAddRequest;
import gift.dto.wishproduct.WishProductPageResponse;
import gift.dto.wishproduct.WishProductResponse;
import gift.dto.wishproduct.WishProductUpdateRequest;
import gift.exception.BadRequestException;
Expand Down Expand Up @@ -62,15 +62,15 @@ public WishProductResponse getWishProduct(Long memberId, Long id) {
}

@Transactional(readOnly = true)
public PageResponse<WishProductResponse> getWishProducts(Long memberId, Pageable pageable) {
public WishProductPageResponse getWishProducts(Long memberId, Pageable pageable) {
var pageResult = wishProductRepository.findAllByMemberId(memberId, pageable);
var wishProducts = pageResult
.getContent()
.stream()
.map(this::getWishProductResponseFromWishProduct)
.toList();

return new PageResponse<>(pageResult.getNumber(), pageResult.getSize(), pageResult.getTotalElements(), pageResult.getTotalPages(), wishProducts);
return new WishProductPageResponse(pageResult.getNumber(), pageResult.getSize(), pageResult.getTotalElements(), pageResult.getTotalPages(), wishProducts);
}

public void deleteWishProduct(Long wishProductId) {
Expand Down

0 comments on commit 864ab8c

Please sign in to comment.