fix : 카테고리 확인 API 수정
This commit is contained in:
@@ -9,12 +9,41 @@ class ProductService
|
||||
{
|
||||
|
||||
/**
|
||||
* 회원 조회(리스트)
|
||||
* 카테고리 트리 전체 조회 (parent_id = null 기준)
|
||||
*/
|
||||
public static function getCategory()
|
||||
public static function getCategory($request)
|
||||
{
|
||||
$query = CommonCode::where('code_group','category')->where('parent_id',null);
|
||||
$parentId = $request->parentId ?? null;
|
||||
$group = $request->group ?? 'category';
|
||||
|
||||
// 재귀적으로 트리 구성
|
||||
$list = self::fetchCategoryTree($parentId, $group);
|
||||
|
||||
return ApiResponse::response('result', $list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 내부 재귀 함수 (하위 카테고리 트리 구조로 구성)
|
||||
*/
|
||||
protected static function fetchCategoryTree($parentId = null, $group = 'category')
|
||||
{
|
||||
$categories = CommonCode::where('code_group', 'category')
|
||||
->where('parent_id', $parentId)
|
||||
->orderBy('sort_order')->debug();
|
||||
$categories = $categories->get();
|
||||
|
||||
foreach ($categories as $category) {
|
||||
$category->children = self::fetchCategoryTree($category->id);
|
||||
}
|
||||
return $categories;
|
||||
}
|
||||
|
||||
/**
|
||||
* (예시) 기존의 flat 리스트 조회
|
||||
*/
|
||||
public static function getCategoryFlat($group = 'category')
|
||||
{
|
||||
$query = CommonCode::where('code_group',$group)->whereNull('parent_id');
|
||||
return ApiResponse::response('get', $query);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user