Skip to content

Commit

Permalink
refactor: 팀원들간 API 명세 통일 작업 수행
Browse files Browse the repository at this point in the history
API 명세 통일 작업 수행
  • Loading branch information
yunjunghun0116 committed Jul 31, 2024
1 parent 5f8bc92 commit c971c7e
Show file tree
Hide file tree
Showing 37 changed files with 370 additions and 209 deletions.
11 changes: 4 additions & 7 deletions src/main/java/gift/client/KakaoApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import gift.dto.kakao.template.KakaoTemplateContent;
import gift.dto.kakao.template.KakaoTemplateLink;
import gift.exception.BadRequestException;
import gift.exception.InvalidKakaoTokenException;
import gift.exception.UnauthorizedAccessException;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -63,10 +63,7 @@ public KakaoTokenResponse getRefreshedTokenResponse(String refreshToken) {
.body(body)
.retrieve()
.onStatus(statusCode -> statusCode.equals(HttpStatus.UNAUTHORIZED), (req, res) -> {
throw new InvalidKakaoTokenException(INVALID_TOKEN_MESSAGE);
})
.onStatus(statusCode -> statusCode.equals(HttpStatus.BAD_REQUEST), (req, res) -> {
throw new InvalidKakaoTokenException(INVALID_TOKEN_MESSAGE);
throw new UnauthorizedAccessException("유효하지 않은 카카오 리프레시 토큰입니다.");
})
.body(String.class);

Expand Down Expand Up @@ -102,7 +99,7 @@ public void sendSelfMessageOrder(String accessToken, GiftOrderResponse giftOrder
.body(body)
.retrieve()
.onStatus(statusCode -> statusCode.equals(HttpStatus.UNAUTHORIZED), (req, res) -> {
throw new InvalidKakaoTokenException(INVALID_TOKEN_MESSAGE);
throw new UnauthorizedAccessException(INVALID_TOKEN_MESSAGE);
})
.body(String.class);
} catch (JsonProcessingException exception) {
Expand All @@ -122,7 +119,7 @@ private KakaoTemplate getCommerceTemplate(GiftOrderResponse giftOrderResponse) {
var objectType = "commerce";
var link = new KakaoTemplateLink("https://gift.kakao.com/product/2370524");
var content = new KakaoTemplateContent(giftOrderResponse.message(), "https://img1.kakaocdn.net/thumb/[email protected]/?fname=https%3A%2F%2Fst.kakaocdn.net%2Fproduct%2Fgift%2Fproduct%2F20240417111629_616eccb9d4cd464fa06d3430947dce15.jpg", giftOrderResponse.message(), link);
var commerce = new KakaoTemplateCommerce(giftOrderResponse.optionInformation().productName() + "[" + giftOrderResponse.optionInformation().name() + "]", giftOrderResponse.optionInformation().price() * giftOrderResponse.quantity());
var commerce = new KakaoTemplateCommerce(giftOrderResponse.productBasicInformation().name() + "[" + giftOrderResponse.optionResponse().name() + "]", giftOrderResponse.productBasicInformation().price() * giftOrderResponse.quantity());
return new KakaoTemplate(objectType, content, commerce);
}
}
8 changes: 2 additions & 6 deletions src/main/java/gift/controller/CategoryController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
import gift.dto.category.CategoryResponse;
import gift.service.CategoryService;
import jakarta.validation.Valid;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
Expand Down Expand Up @@ -50,9 +47,8 @@ public ResponseEntity<CategoryResponse> getCategory(@PathVariable Long id) {
}

@GetMapping
public ResponseEntity<List<CategoryResponse>> getCategories(
@PageableDefault(sort = "id", direction = Sort.Direction.DESC) Pageable pageable) {
var categories = categoryService.getCategories(pageable);
public ResponseEntity<List<CategoryResponse>> getCategories() {
var categories = categoryService.getCategories();
return ResponseEntity.ok(categories);
}

Expand Down
33 changes: 17 additions & 16 deletions src/main/java/gift/controller/OptionController.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package gift.controller;

import gift.controller.api.OptionApi;
import gift.dto.option.OptionAddRequest;
import gift.dto.option.OptionRequest;
import gift.dto.option.OptionResponse;
import gift.dto.option.OptionUpdateRequest;
import gift.service.OptionService;
import jakarta.validation.Valid;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -17,14 +13,13 @@
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.net.URI;
import java.util.List;

@RestController
@RequestMapping("/api/options")
@RequestMapping("/api/products/{productId}/options")
public class OptionController implements OptionApi {

private final OptionService optionService;
Expand All @@ -34,26 +29,32 @@ public OptionController(OptionService optionService) {
}

@PostMapping
public ResponseEntity<Void> addOption(@Valid @RequestBody OptionAddRequest optionAddRequest) {
var option = optionService.addOption(optionAddRequest);
return ResponseEntity.created(URI.create("/api/options/" + option.id())).build();
public ResponseEntity<Void> addOption(@PathVariable Long productId, @Valid @RequestBody OptionRequest optionRequest) {
var option = optionService.addOption(productId, optionRequest);
return ResponseEntity.created(URI.create("/api/products/" + productId + "/options/" + option.id())).build();
}

@PutMapping("/{id}")
public ResponseEntity<Void> updateOption(@PathVariable Long id, @Valid @RequestBody OptionUpdateRequest optionUpdateRequest) {
optionService.updateOption(id, optionUpdateRequest);
public ResponseEntity<Void> updateOption(@PathVariable Long productId, @PathVariable Long id, @Valid @RequestBody OptionRequest optionUpdateRequest) {
optionService.updateOption(productId, id, optionUpdateRequest);
return ResponseEntity.noContent().build();
}

@GetMapping("/{id}")
public ResponseEntity<OptionResponse> getOption(@PathVariable Long productId, @PathVariable Long id) {
var option = optionService.getOption(productId, id);
return ResponseEntity.ok(option);
}

@GetMapping
public ResponseEntity<List<OptionResponse>> getOptions(@RequestParam Long productId, @PageableDefault(sort = "id", direction = Sort.Direction.DESC) Pageable pageable) {
var options = optionService.getOptions(productId, pageable);
public ResponseEntity<List<OptionResponse>> getOptions(@PathVariable Long productId) {
var options = optionService.getOptions(productId);
return ResponseEntity.ok(options);
}

@DeleteMapping("/{id}")
public ResponseEntity<Void> deleteOption(@PathVariable Long id) {
optionService.deleteOption(id);
public ResponseEntity<Void> deleteOption(@PathVariable Long productId, @PathVariable Long id) {
optionService.deleteOption(productId, id);
return ResponseEntity.noContent().build();
}
}
20 changes: 13 additions & 7 deletions src/main/java/gift/controller/ProductController.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package gift.controller;

import gift.controller.api.ProductApi;
import gift.dto.product.ProductRequest;
import gift.dto.product.ProductAddRequest;
import gift.dto.product.ProductResponse;
import gift.dto.product.ProductUpdateRequest;
import gift.service.ProductService;
import jakarta.validation.Valid;
import org.springframework.data.domain.Pageable;
Expand All @@ -16,6 +17,7 @@
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.net.URI;
Expand All @@ -32,14 +34,14 @@ public ProductController(ProductService productService) {
}

@PostMapping
public ResponseEntity<Void> addProduct(@Valid @RequestBody ProductRequest productRequest) {
var product = productService.addProduct(productRequest);
public ResponseEntity<Void> addProduct(@Valid @RequestBody ProductAddRequest productAddRequest) {
var product = productService.addProduct(productAddRequest);
return ResponseEntity.created(URI.create("/api/products/" + product.id())).build();
}

@PutMapping("/{id}")
public ResponseEntity<Void> updateProduct(@PathVariable Long id, @Valid @RequestBody ProductRequest productRequest) {
productService.updateProduct(id, productRequest);
public ResponseEntity<Void> updateProduct(@PathVariable Long id, @Valid @RequestBody ProductUpdateRequest productUpdateRequest) {
productService.updateProduct(id, productUpdateRequest);
return ResponseEntity.noContent().build();
}

Expand All @@ -50,8 +52,12 @@ public ResponseEntity<ProductResponse> getProduct(@PathVariable Long id) {
}

@GetMapping
public ResponseEntity<List<ProductResponse>> getProducts(@PageableDefault(sort = "id", direction = Sort.Direction.DESC) Pageable pageable) {
var products = productService.getProducts(pageable);
public ResponseEntity<List<ProductResponse>> 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);
}
var products = productService.getProducts(categoryId, pageable);
return ResponseEntity.ok(products);
}

Expand Down
6 changes: 6 additions & 0 deletions src/main/java/gift/controller/WishProductController.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public ResponseEntity<Void> updateWishProduct(@PathVariable Long id, @Valid @Req
return ResponseEntity.noContent().build();
}

@GetMapping("/{id}")
public ResponseEntity<WishProductResponse> getWishProduct(@RequestAttribute("memberId") Long memberId, @PathVariable Long id) {
var wishProduct = wishProductService.getWishProduct(memberId, id);
return ResponseEntity.ok(wishProduct);
}

@GetMapping
public ResponseEntity<List<WishProductResponse>> getWishProducts(@RequestAttribute("memberId") Long memberId, @PageableDefault(sort = "id", direction = Sort.Direction.DESC) Pageable pageable) {
var wishProducts = wishProductService.getWishProducts(memberId, pageable);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/gift/controller/api/CategoryApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;

import java.util.List;
Expand All @@ -20,6 +19,7 @@ public interface CategoryApi {
@ApiResponses(value = {
@ApiResponse(responseCode = "201", description = "카테고리 생성 성공"),
@ApiResponse(responseCode = "401", description = "허용되지 않는 요청"),
@ApiResponse(responseCode = "409", description = "카테고리 생성 실패(사유 : 이미 존재하는 이름입니다. )"),
@ApiResponse(responseCode = "500", description = "내부 서버의 오류")
})
ResponseEntity<Void> addCategory(CategoryRequest categoryRequest);
Expand All @@ -28,6 +28,7 @@ public interface CategoryApi {
@ApiResponses(value = {
@ApiResponse(responseCode = "204", description = "카테고리 수정 성공"),
@ApiResponse(responseCode = "401", description = "허용되지 않는 요청"),
@ApiResponse(responseCode = "409", description = "카테고리 수정 실패(사유 : 이미 존재하는 이름입니다. )"),
@ApiResponse(responseCode = "500", description = "내부 서버의 오류")
})
ResponseEntity<Void> updateCategory(Long id, CategoryRequest categoryRequest);
Expand All @@ -46,7 +47,7 @@ public interface CategoryApi {
@ApiResponse(responseCode = "401", description = "허용되지 않는 요청", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "500", description = "내부 서버의 오류", content = @Content(schema = @Schema(hidden = true)))
})
ResponseEntity<List<CategoryResponse>> getCategories(Pageable pageable);
ResponseEntity<List<CategoryResponse>> getCategories();

@Operation(summary = "특정 카테고리를 삭제한다.")
@ApiResponses(value = {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gift/controller/api/GiftOrderApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public interface GiftOrderApi {
@Operation(summary = "회원의 새 주문을 생성한다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "201", description = "주문 생성 성공"),
@ApiResponse(responseCode = "401", description = "허용되지 않는 요청"),
@ApiResponse(responseCode = "401", description = "주문 생성 실패(사유 : 카카오 토큰이 만료되었거나, 허용되지 않은 요청입니다.)"),
@ApiResponse(responseCode = "500", description = "내부 서버의 오류")
})
ResponseEntity<Void> orderOption(Long memberId, GiftOrderRequest giftOrderRequest);
Expand Down
25 changes: 18 additions & 7 deletions src/main/java/gift/controller/api/OptionApi.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package gift.controller.api;

import gift.dto.option.OptionAddRequest;
import gift.dto.option.OptionRequest;
import gift.dto.option.OptionResponse;
import gift.dto.option.OptionUpdateRequest;
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;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;

import java.util.List;
Expand All @@ -22,32 +20,45 @@ public interface OptionApi {
@ApiResponses(value = {
@ApiResponse(responseCode = "201", description = "옵션 추가 성공"),
@ApiResponse(responseCode = "401", description = "허용되지 않는 요청"),
@ApiResponse(responseCode = "409", description = "옵션 추가 실패(사유 : 이미 존재하는 이름입니다. )"),
@ApiResponse(responseCode = "500", description = "내부 서버의 오류")
})
ResponseEntity<Void> addOption(OptionAddRequest optionAddRequest);
ResponseEntity<Void> addOption(Long productId, OptionRequest optionRequest);

@Operation(summary = "기존 옵션을 수정한다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "204", description = "옵션 수정 성공"),
@ApiResponse(responseCode = "400", description = "옵션 수정 실패(사유 : 옵션과 연결된 상품 ID 가 아닙니다.)"),
@ApiResponse(responseCode = "401", description = "허용되지 않는 요청"),
@ApiResponse(responseCode = "409", description = "옵션 수정 실패(사유 : 이미 존재하는 이름입니다. )"),
@ApiResponse(responseCode = "500", description = "내부 서버의 오류")
})
ResponseEntity<Void> updateOption(Long id, OptionUpdateRequest optionUpdateRequest);
ResponseEntity<Void> updateOption(Long productId, Long id, OptionRequest optionRequest);

@Operation(summary = "특정 옵션을 조회한다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "특정 옵션 조회 성공", content = @Content(schema = @Schema(implementation = OptionResponse.class))),
@ApiResponse(responseCode = "400", description = "특정 옵션 조회 실패(사유 : 옵션과 연결된 상품 ID 가 아닙니다.)"),
@ApiResponse(responseCode = "401", description = "허용되지 않는 요청", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "500", description = "내부 서버의 오류", content = @Content(schema = @Schema(hidden = true)))
})
ResponseEntity<OptionResponse> getOption(Long productId, Long id);

@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))),
@ApiResponse(responseCode = "500", description = "내부 서버의 오류", content = @Content(schema = @Schema(hidden = true)))
})
ResponseEntity<List<OptionResponse>> getOptions(Long productId, Pageable pageable);
ResponseEntity<List<OptionResponse>> getOptions(Long productId);

@Operation(summary = "특정 옵션을 삭제한다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "204", description = "옵션 삭제 성공"),
@ApiResponse(responseCode = "400", description = "옵션 삭제 실패(사유 : 옵션과 연결된 상품 ID 가 아닙니다.)"),
@ApiResponse(responseCode = "401", description = "허용되지 않는 요청"),
@ApiResponse(responseCode = "404", description = "옵션 삭제 실패(사유 : 존재하지 않는 ID 입니다.)"),
@ApiResponse(responseCode = "500", description = "내부 서버의 오류")
})
ResponseEntity<Void> deleteOption(Long id);
ResponseEntity<Void> deleteOption(Long productId, Long id);
}
11 changes: 7 additions & 4 deletions src/main/java/gift/controller/api/ProductApi.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package gift.controller.api;

import gift.dto.product.ProductRequest;
import gift.dto.product.ProductAddRequest;
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;
Expand All @@ -20,18 +21,20 @@ public interface ProductApi {
@Operation(summary = "새 상품을 등록한다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "201", description = "상품 등록 성공"),
@ApiResponse(responseCode = "400", description = "상품 등록 실패(사유 : 카카오가 포함된 이름입니다.)"),
@ApiResponse(responseCode = "401", description = "허용되지 않는 요청"),
@ApiResponse(responseCode = "500", description = "내부 서버의 오류")
})
ResponseEntity<Void> addProduct(ProductRequest productRequest);
ResponseEntity<Void> addProduct(ProductAddRequest productAddRequest);

@Operation(summary = "기존 상품을 수정한다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "204", description = "상품 수정 성공"),
@ApiResponse(responseCode = "400", description = "상품 수정 실패(사유 : 카카오가 포함된 이름입니다.)"),
@ApiResponse(responseCode = "401", description = "허용되지 않는 요청"),
@ApiResponse(responseCode = "500", description = "내부 서버의 오류")
})
ResponseEntity<Void> updateProduct(Long id, ProductRequest productRequest);
ResponseEntity<Void> updateProduct(Long id, ProductUpdateRequest productUpdateRequest);

@Operation(summary = "특정 상품을 조회한다.")
@ApiResponses(value = {
Expand All @@ -47,7 +50,7 @@ public interface ProductApi {
@ApiResponse(responseCode = "401", description = "허용되지 않는 요청", content = @Content(schema = @Schema(hidden = true))),
@ApiResponse(responseCode = "500", description = "내부 서버의 오류", content = @Content(schema = @Schema(hidden = true)))
})
ResponseEntity<List<ProductResponse>> getProducts(Pageable pageable);
ResponseEntity<List<ProductResponse>> getProducts(Long categoryId, Pageable pageable);

@Operation(summary = "특정 상품을 삭제한다.")
@ApiResponses(value = {
Expand Down
Loading

0 comments on commit c971c7e

Please sign in to comment.