Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,17 @@ public class CategoryService {

// ------------------- 전체 조회 -------------------
@Transactional(readOnly = true)
public List<CategoryResponse> findAllCategories() {
return categoryRepository.findAll().stream()
public List<CategoryResponse> findRootCategories() {
return categoryRepository.findByParentIsNull().stream()
.map(CategoryResponse::fromEntity)
.collect(Collectors.toList());
.toList();
}

@Transactional(readOnly = true)
public List<CategoryResponse> findByParentId(UUID parentId) {
return categoryRepository.findChildrenByParentId(parentId).stream()
.map(CategoryResponse::fromEntity)
.toList();
}

// ------------------- 단일 조회 -------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.irum.come2us.domain.category.domain.entity;

import com.irum.come2us.global.domain.BaseEntity;
import com.irum.come2us.global.presentation.advice.exception.CommonException;
import com.irum.come2us.global.presentation.advice.exception.errorcode.CategoryErrorCode;
import jakarta.persistence.*;
Expand All @@ -15,7 +16,7 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Builder(access = AccessLevel.PRIVATE)
public class Category {
public class Category extends BaseEntity {

private static final int MAX_DEPTH = 3;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ public class CategoryController {

// ------------------- 전체 조회 -------------------
@GetMapping
public List<CategoryResponse> getAllCategories() {
return categoryService.findAllCategories();
public List<CategoryResponse> getAllCategories(@RequestParam(required = false) UUID parentId) {
if (parentId != null) {
return categoryService.findByParentId(parentId);
}
return categoryService.findRootCategories();
}

// ------------------- 단일 조회 -------------------
Expand Down