Skip to content

Commit 3b46d6f

Browse files
CLAP-148 Feature : 카테고리 CUD 리뷰 반영 수정, 조회 반환 양식 수정
* CLAP-110 Feature : 담당자별 작업 처리량 조회 API 구현 <footer> - 관련: #73 * CLAP-111 Refactor : 통계 조회 API 리팩토링 및 기능 수정 <footer> - 관련: #74 * 내 작업한 내용에 대한 설명 * 담당자 조회 API 구현 * CLAP-111 Refactor : 통계 조회 API 주소 통합, 리팩토링, 예외처리 <footer> - 관련: #74 * Bug : 프로퍼티파일 수정 * CLAP-104 CI/CD : CI에서 s3.yml 파일 생성하도록 수정 * CLAP-146 Feature : 카테고리 목록 조회 API 구현 <footer> - 관련: #118 * CLAP-147 Feature : 카테고리 수정 API 구현 <footer> - 관련: #119 * CLAP-147 Feature : 카테고리 추가, 수정 API 리뷰반영 수정 <footer> - 관련: #119 * CLAP-148 Feature : 카테고리 삭제 API 구현 <footer> - 관련: #120 * CLAP-148 Feature : 카테고리 삭제 API 수정 <footer> - 관련: #120 * CLAP-148 Docs : 카테고리 API 스웨거 수정 <footer> - 관련: #120 * CLAP-107 Bug : CI test yml파일 key 중복 수정 <footer> - 관련: #60 * CLAP-148 Feature : 카테고리 CUD 리뷰 반영 수정, 조회 반환 양식 수정 <footer> - 관련: #120
1 parent 22640a6 commit 3b46d6f

File tree

9 files changed

+36
-25
lines changed

9 files changed

+36
-25
lines changed

src/main/java/clap/server/adapter/inbound/web/admin/AddCategoryController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
@Tag(name = "05. Admin")
1919
@WebAdapter
2020
@RequiredArgsConstructor
21-
@RequestMapping("/api/management")
21+
@RequestMapping("/api/managements")
2222
public class AddCategoryController {
2323
private final AddCategoryUsecase addCategoryUsecase;
2424

src/main/java/clap/server/adapter/inbound/web/admin/DeleteCategoryController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
@Tag(name = "05. Admin")
1616
@WebAdapter
1717
@RequiredArgsConstructor
18-
@RequestMapping("/api/management")
18+
@RequestMapping("/api/managements")
1919
public class DeleteCategoryController {
2020
private final DeleteCategoryUsecase deleteCategoryUsecase;
2121

src/main/java/clap/server/adapter/inbound/web/admin/FindCategoryController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class FindCategoryController {
2727

2828
@Operation(summary = "모든 카테고리 조회")
2929
@GetMapping("/category")
30-
public ResponseEntity<FindAllCategoryResponse> findAllCategory() {
30+
public ResponseEntity<List<FindAllCategoryResponse>> findAllCategory() {
3131
return ResponseEntity.ok(findAllCategoryUsecase.findAllCategory());
3232
}
3333

src/main/java/clap/server/adapter/inbound/web/admin/UpdateCategoryController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
@Tag(name = "05. Admin")
1818
@WebAdapter
1919
@RequiredArgsConstructor
20-
@RequestMapping("/api/management")
20+
@RequestMapping("/api/managements")
2121
public class UpdateCategoryController {
2222
private final UpdateCategoryUsecase updateCategoryUsecase;
2323

src/main/java/clap/server/adapter/inbound/web/dto/admin/FindAllCategoryResponse.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import java.util.List;
44

55
public record FindAllCategoryResponse(
6-
List<FindMainCategoryResponse> mainCategory,
6+
Long id,
7+
String name,
8+
String code,
79
List<FindSubCategoryResponse> subCategory
810
) {
911
}

src/main/java/clap/server/application/mapper/response/CategoryResponseMapper.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
public class CategoryResponseMapper {
1111

1212
public static FindAllCategoryResponse toFindAllCategoryResponse(
13-
List<FindMainCategoryResponse> mainCategoryResponses,
13+
Long id,
14+
String name,
15+
String code,
1416
List<FindSubCategoryResponse> subCategoryResponses) {
15-
return new FindAllCategoryResponse(mainCategoryResponses, subCategoryResponses);
17+
return new FindAllCategoryResponse(id, name, code, subCategoryResponses);
1618
}
1719

1820
public static FindMainCategoryResponse toFindMainCategoryResponse(Category category) {

src/main/java/clap/server/application/port/inbound/admin/FindAllCategoryUsecase.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import clap.server.adapter.inbound.web.dto.admin.FindAllCategoryResponse;
44

5+
import java.util.List;
6+
57
public interface FindAllCategoryUsecase {
6-
FindAllCategoryResponse findAllCategory();
8+
List<FindAllCategoryResponse> findAllCategory();
79
}

src/main/java/clap/server/application/service/admin/DeleteCategoryService.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
package clap.server.application.service.admin;
22

33
import clap.server.application.port.inbound.admin.DeleteCategoryUsecase;
4-
import clap.server.application.port.outbound.member.LoadMemberPort;
4+
import clap.server.application.port.inbound.domain.MemberService;
55
import clap.server.application.port.outbound.task.LoadCategoryPort;
66
import clap.server.common.annotation.architecture.ApplicationService;
77
import clap.server.domain.model.member.Member;
88
import clap.server.exception.ApplicationException;
99
import lombok.RequiredArgsConstructor;
1010
import org.springframework.transaction.annotation.Transactional;
1111

12-
import static clap.server.exception.code.MemberErrorCode.ACTIVE_MEMBER_NOT_FOUND;
1312
import static clap.server.exception.code.TaskErrorCode.CATEGORY_NOT_FOUND;
1413

1514
@ApplicationService
1615
@RequiredArgsConstructor
1716
public class DeleteCategoryService implements DeleteCategoryUsecase {
1817
private final LoadCategoryPort loadCategoryPort;
19-
private final LoadMemberPort loadMemberPort;
18+
private final MemberService memberService;
2019

2120
@Override
2221
@Transactional
2322
public void deleteCategory(Long adminId, Long categoryId) {
24-
Member admin = loadMemberPort.findActiveMemberById(adminId).orElseThrow(() -> new ApplicationException(ACTIVE_MEMBER_NOT_FOUND));
23+
Member admin = memberService.findActiveMember(adminId);
2524
loadCategoryPort.findById(categoryId)
2625
.orElseThrow(() -> new ApplicationException(CATEGORY_NOT_FOUND))
2726
.deleteCategory(admin);
Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
package clap.server.application.service.admin;
22

33
import clap.server.adapter.inbound.web.dto.admin.FindAllCategoryResponse;
4-
import clap.server.adapter.inbound.web.dto.admin.FindMainCategoryResponse;
54
import clap.server.adapter.inbound.web.dto.admin.FindSubCategoryResponse;
65
import clap.server.application.mapper.response.CategoryResponseMapper;
76
import clap.server.application.port.inbound.admin.FindAllCategoryUsecase;
87
import clap.server.application.port.outbound.task.LoadCategoryPort;
98
import clap.server.common.annotation.architecture.ApplicationService;
9+
import clap.server.domain.model.task.Category;
1010
import lombok.RequiredArgsConstructor;
1111
import org.springframework.transaction.annotation.Transactional;
1212

13-
import java.util.ArrayList;
1413
import java.util.List;
1514

1615
@ApplicationService
@@ -20,16 +19,23 @@ public class FindAllCategoryService implements FindAllCategoryUsecase {
2019

2120
@Override
2221
@Transactional(readOnly = true)
23-
public FindAllCategoryResponse findAllCategory() {
24-
List<FindMainCategoryResponse> mainCategoryResponses = new ArrayList<>();
25-
List<FindSubCategoryResponse> subCategoryResponses = new ArrayList<>();
26-
loadCategoryPort.findAll().forEach(category -> {
27-
if (category.getMainCategory() == null) {
28-
mainCategoryResponses.add(CategoryResponseMapper.toFindMainCategoryResponse(category));
29-
} else {
30-
subCategoryResponses.add(CategoryResponseMapper.toFindSubCategoryResponse(category));
31-
}
32-
});
33-
return CategoryResponseMapper.toFindAllCategoryResponse(mainCategoryResponses, subCategoryResponses);
22+
public List<FindAllCategoryResponse> findAllCategory() {
23+
List<Category> categories = loadCategoryPort.findAll();
24+
return categories.stream().filter(category -> category.getMainCategory() == null)
25+
.map(parent -> CategoryResponseMapper.toFindAllCategoryResponse(
26+
parent.getCategoryId(),
27+
parent.getName(),
28+
parent.getCode(),
29+
getSubCategories(categories, parent) // 2차 카테고리 리스트 변환
30+
))
31+
.toList();
32+
}
33+
34+
private List<FindSubCategoryResponse> getSubCategories(List<Category> categories, Category parent) {
35+
return categories.stream()
36+
.filter(category -> category.getMainCategory() != null &&
37+
category.getMainCategory().getCategoryId().equals(parent.getCategoryId())) // 부모가 같은 것들 필터링
38+
.map(CategoryResponseMapper::toFindSubCategoryResponse)
39+
.toList();
3440
}
3541
}

0 commit comments

Comments
 (0)