Skip to content

Commit

Permalink
[DEPLOY] 카테고리 계층 추가 (#204)
Browse files Browse the repository at this point in the history
* fix: 카테고리 상세조회 할 때 회원 아이디로 조회되는 오류 해결 (#200)

* [FEAT} 카테고리 계층 조회 구현 (#203)

* feat: 카테고리 계층 조회 구현

* feat: review 후 수정
  • Loading branch information
limbaba1120 authored Nov 13, 2024
1 parent c3feefe commit 6aba27d
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ public List<CategoryInfo.CategoryResponse> retrieveCategories() {
return categoryService.retrieveCategories();
}

public List<CategoryInfo.CategoryResponse> retrieveCategoryHierarchy(Long categoryId) {
return categoryService.retrieveCategoryHierarchy(categoryId);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.omocha.api.interfaces;

import java.util.List;

import org.omocha.api.common.response.ResultDto;
import org.omocha.api.interfaces.dto.CategoryDto;
import org.omocha.domain.auction.CategoryInfo;
import org.springframework.http.ResponseEntity;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
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;

@Tag(name = "카테고리 API(CategoryController)", description = "카테고리 생성, 전체 조회, 계층 조회 API 입니다.")
public interface CategoryApi {

@Operation(summary = "카테고리 생성", description = "새로운 카테고리를 생성합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "경매가 성공적으로 생성되었습니다.",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ResultDto.class))),
@ApiResponse(responseCode = "401", description = "인증되지 않은 사용자입니다.",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ResultDto.class))),
@ApiResponse(responseCode = "500", description = "서버 오류가 발생했습니다.",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ResultDto.class)))
})
ResponseEntity<ResultDto<CategoryDto.CategoryAddResponse>> categoryAdd(
@Parameter(description = "카테고리 생성 조건", required = true)
CategoryDto.CategoryAddRequest request
);

@Operation(summary = "카테고리 계층 조회", description = "카테고리 계층 목록을 조회합니다")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "성공적으로 경매 목록을 조회했습니다.",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ResultDto.class))),
@ApiResponse(responseCode = "400", description = "잘못된 요청입니다.",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ResultDto.class))),
@ApiResponse(responseCode = "500", description = "서버 오류가 발생했습니다.",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ResultDto.class)))
})
ResponseEntity<ResultDto<List<CategoryInfo.CategoryResponse>>> categoryHierarchy(
@Parameter(description = "카테고리 ID", required = true)
Long categoryId
);

@Operation(summary = "카테고리 전체 조회", description = "카테고리 전체 리스트를 조회합니다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "경매 상세 정보 조회 성공",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ResultDto.class))),
@ApiResponse(responseCode = "400", description = "잘못된 요청입니다.",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ResultDto.class))),
@ApiResponse(responseCode = "500", description = "서버 오류가 발생했습니다.",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = ResultDto.class)))
})
public ResponseEntity<ResultDto<List<CategoryInfo.CategoryResponse>>> categoryDetails();

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package org.omocha.api.interfaces;

import static org.omocha.domain.exception.code.SuccessCode.*;

import java.util.List;

import org.omocha.api.application.CategoryFacade;
import org.omocha.api.common.response.ResultDto;
import org.omocha.api.interfaces.dto.CategoryDto;
import org.omocha.api.interfaces.mapper.CategoryDtoMapper;
import org.omocha.domain.auction.CategoryCommand;
import org.omocha.domain.auction.CategoryInfo;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -19,13 +23,14 @@
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v2/categories")
public class CategoryController {
public class CategoryController implements CategoryApi {

private final CategoryFacade categoryFacade;
private final CategoryDtoMapper categoryMapper;

@Override
@PostMapping
public ResponseEntity<CategoryDto.CategoryAddResponse> categoryAdd(
public ResponseEntity<ResultDto<CategoryDto.CategoryAddResponse>> categoryAdd(
@RequestBody CategoryDto.CategoryAddRequest request
) {
CategoryCommand.AddCategory addCommand = categoryMapper.toCommand(request);
Expand All @@ -34,14 +39,49 @@ public ResponseEntity<CategoryDto.CategoryAddResponse> categoryAdd(

CategoryDto.CategoryAddResponse response = categoryMapper.toResponse(categoryId);

return ResponseEntity.ok(response);
ResultDto<CategoryDto.CategoryAddResponse> result = ResultDto.res(
CATEGORY_CREATE_SUCCESS.getStatusCode(),
CATEGORY_CREATE_SUCCESS.getDescription(),
response
);

return ResponseEntity
.status(CATEGORY_CREATE_SUCCESS.getHttpStatus())
.body(result);
}

@Override
@GetMapping("/{category_id}")
public ResponseEntity<ResultDto<List<CategoryInfo.CategoryResponse>>> categoryHierarchy(
@PathVariable("category_id") Long categoryId
) {

List<CategoryInfo.CategoryResponse> response = categoryFacade.retrieveCategoryHierarchy(categoryId);
ResultDto<List<CategoryInfo.CategoryResponse>> result = ResultDto.res(
CATEGORY_HIERARCHY_SUCCESS.getStatusCode(),
CATEGORY_HIERARCHY_SUCCESS.getDescription(),
response
);

return ResponseEntity
.status(CATEGORY_HIERARCHY_SUCCESS.getHttpStatus())
.body(result);
}

@Override
@GetMapping
public ResponseEntity<List<CategoryInfo.CategoryResponse>> categoryDetails() {
public ResponseEntity<ResultDto<List<CategoryInfo.CategoryResponse>>> categoryDetails() {

List<CategoryInfo.CategoryResponse> response = categoryFacade.retrieveCategories();

return ResponseEntity.ok(response);
ResultDto<List<CategoryInfo.CategoryResponse>> result = ResultDto.res(
CATEGORY_DETAIL_SUCCESS.getStatusCode(),
CATEGORY_DETAIL_SUCCESS.getDescription(),
response
);
return ResponseEntity
.status(CATEGORY_DETAIL_SUCCESS.getHttpStatus())
.body(result);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public interface CategoryService {

List<CategoryInfo.CategoryResponse> retrieveCategories();

// Category updateCategory(CategoryDto.CategoryUpdateRequest request);
List<CategoryInfo.CategoryResponse> retrieveCategoryHierarchy(Long categoryId);

// Category updateCategory(CategoryDto.CategoryUpdateRequest request);

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ public List<CategoryInfo.CategoryResponse> retrieveCategories() {
return categoryReader.getAllCategories();
}

@Override
public List<CategoryInfo.CategoryResponse> retrieveCategoryHierarchy(Long categoryId) {
return categoryReader.getCategoryHierarchyUpwards(categoryId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ public enum SuccessCode {
MEMBER_LOGIN_SUCCESS(HttpStatus.OK, "로그인이 완료되었습니다."),
MEMBER_LOGOUT_SUCCESS(HttpStatus.OK, "로그아웃이 완료되었습니다."),
VALIDATE_EMAIL_SUCCESS(HttpStatus.OK, "사용 가능한 이메일입니다."),

// Auction Code
AUCTION_CREATE_SUCCESS(HttpStatus.OK, "경매가 성공적으로 생성되었습니다."),
AUCTION_DELETE_SUCCESS(HttpStatus.OK, "경매가 성공적으로 삭제되었습니다."),
AUCTION_LIST_ACCESS_SUCCESS(HttpStatus.OK, "경매 리스트를 성공적으로 조회하였습니다."),
AUCTION_DETAIL_SUCCESS(HttpStatus.OK, "경매 상세정보를 성공적으로 조회하였습니다."),

// Category Code
CATEGORY_CREATE_SUCCESS(HttpStatus.OK, "카테고리가 성공적으로 생성되었습니다."),
CATEGORY_HIERARCHY_SUCCESS(HttpStatus.OK, "카테고리 계층 정보를 성공적으로 조회하였습니다"),
CATEGORY_DETAIL_SUCCESS(HttpStatus.OK, "카테고리 전체 조회를 성공했습니다."),

// Bid Code
BIDDING_CREATE_SUCCESS(HttpStatus.OK, "성공적으로 입찰되었습니다."),
BIDDING_GET_SUCCESS(HttpStatus.OK, "성공적으로 입찰을 불러왔습니다."),
Expand Down

0 comments on commit 6aba27d

Please sign in to comment.