Skip to content

Commit 69b8624

Browse files
CLAP-146 Feature : 카테고리 목록 조회 API 구현
* 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 구현 * CLAP-147 Feature : 카테고리 수정 API 구현 <footer> - 관련: #119 * CLAP-147 Feature : 카테고리 추가, 수정 API 리뷰반영 수정 <footer> - 관련: #119 --------- Co-authored-by: nano-mm <nano123@gachon.ac.kr>
1 parent be5c7fd commit 69b8624

20 files changed

+327
-4
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package clap.server.adapter.inbound.web.admin;
22

33
import clap.server.adapter.inbound.security.SecurityUserDetails;
4-
import clap.server.adapter.inbound.web.dto.admin.AddSubCategoryRequest;
54
import clap.server.adapter.inbound.web.dto.admin.AddMainCategoryRequest;
5+
import clap.server.adapter.inbound.web.dto.admin.AddSubCategoryRequest;
66
import clap.server.application.port.inbound.admin.AddCategoryUsecase;
77
import clap.server.common.annotation.architecture.WebAdapter;
88
import io.swagger.v3.oas.annotations.Operation;
@@ -18,7 +18,7 @@
1818
@Tag(name = "05. Admin")
1919
@WebAdapter
2020
@RequiredArgsConstructor
21-
@RequestMapping("/api/managements")
21+
@RequestMapping("/api/management")
2222
public class AddCategoryController {
2323
private final AddCategoryUsecase addCategoryUsecase;
2424

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package clap.server.adapter.inbound.web.admin;
2+
3+
import clap.server.adapter.inbound.web.dto.admin.FindAllCategoryResponse;
4+
import clap.server.adapter.inbound.web.dto.admin.FindMainCategoryResponse;
5+
import clap.server.adapter.inbound.web.dto.admin.FindSubCategoryResponse;
6+
import clap.server.application.port.inbound.admin.FindAllCategoryUsecase;
7+
import clap.server.application.port.inbound.admin.FindMainCategoryUsecase;
8+
import clap.server.application.port.inbound.admin.FindSubCategoryUsecase;
9+
import clap.server.common.annotation.architecture.WebAdapter;
10+
import io.swagger.v3.oas.annotations.Operation;
11+
import io.swagger.v3.oas.annotations.tags.Tag;
12+
import lombok.RequiredArgsConstructor;
13+
import org.springframework.http.ResponseEntity;
14+
import org.springframework.web.bind.annotation.GetMapping;
15+
import org.springframework.web.bind.annotation.RequestMapping;
16+
17+
import java.util.List;
18+
19+
@Tag(name = "카테고리 조회")
20+
@WebAdapter
21+
@RequiredArgsConstructor
22+
@RequestMapping("/api")
23+
public class FindCategoryController {
24+
private final FindAllCategoryUsecase findAllCategoryUsecase;
25+
private final FindMainCategoryUsecase findmainCategoryUsecase;
26+
private final FindSubCategoryUsecase findsubCategoryUsecase;
27+
28+
@Operation(summary = "모든 카테고리 조회")
29+
@GetMapping("/category")
30+
public ResponseEntity<FindAllCategoryResponse> findAllCategory() {
31+
return ResponseEntity.ok(findAllCategoryUsecase.findAllCategory());
32+
}
33+
34+
@Operation(summary = "1차 카테고리 조회")
35+
@GetMapping("/main-category")
36+
public ResponseEntity<List<FindMainCategoryResponse>> findMainCategory() {
37+
return ResponseEntity.ok(findmainCategoryUsecase.findMainCategory());
38+
}
39+
40+
@Operation(summary = "2차 카테고리 조회")
41+
@GetMapping("/sub-category")
42+
public ResponseEntity<List<FindSubCategoryResponse>> findSubCategory() {
43+
return ResponseEntity.ok(findsubCategoryUsecase.findSubCategory());
44+
}
45+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package clap.server.adapter.inbound.web.admin;
2+
3+
import clap.server.adapter.inbound.security.SecurityUserDetails;
4+
import clap.server.adapter.inbound.web.dto.admin.UpdateCategoryRequest;
5+
import clap.server.application.port.inbound.admin.UpdateCategoryUsecase;
6+
import clap.server.common.annotation.architecture.WebAdapter;
7+
import io.swagger.v3.oas.annotations.Operation;
8+
import io.swagger.v3.oas.annotations.tags.Tag;
9+
import lombok.RequiredArgsConstructor;
10+
import org.springframework.security.access.annotation.Secured;
11+
import org.springframework.security.core.annotation.AuthenticationPrincipal;
12+
import org.springframework.web.bind.annotation.PatchMapping;
13+
import org.springframework.web.bind.annotation.RequestBody;
14+
import org.springframework.web.bind.annotation.RequestMapping;
15+
16+
@Tag(name = "카테고리 수정")
17+
@WebAdapter
18+
@RequiredArgsConstructor
19+
@RequestMapping("/api/management")
20+
public class UpdateCategoryController {
21+
private final UpdateCategoryUsecase updateCategoryUsecase;
22+
23+
@Operation(summary = "카테고리 수정")
24+
@PatchMapping("/categories/categoryId")
25+
@Secured("ROLE_ADMIN")
26+
public void updateCategory(@AuthenticationPrincipal SecurityUserDetails userInfo, Long categoryId,
27+
@RequestBody UpdateCategoryRequest updateCategoryRequest) {
28+
updateCategoryUsecase.updateCategory(userInfo.getUserId(), categoryId, updateCategoryRequest.name(), updateCategoryRequest.code());
29+
}
30+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package clap.server.adapter.inbound.web.dto.admin;
2+
3+
import java.util.List;
4+
5+
public record FindAllCategoryResponse(
6+
List<FindMainCategoryResponse> mainCategory,
7+
List<FindSubCategoryResponse> subCategory
8+
) {
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package clap.server.adapter.inbound.web.dto.admin;
2+
3+
public record FindMainCategoryResponse(
4+
Long id,
5+
String name,
6+
String code
7+
) {
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package clap.server.adapter.inbound.web.dto.admin;
2+
3+
public record FindSubCategoryResponse(
4+
Long id,
5+
Long mainCategoryId,
6+
String name,
7+
String code
8+
) {
9+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package clap.server.adapter.inbound.web.dto.admin;
2+
3+
import jakarta.validation.constraints.NotBlank;
4+
import jakarta.validation.constraints.Pattern;
5+
import org.hibernate.validator.constraints.Length;
6+
7+
public record UpdateCategoryRequest(
8+
@NotBlank @Length(max = 20)
9+
String name,
10+
@NotBlank @Pattern(regexp = "^[A-Z]{1,2}$", message = "올바른 카테고리 코드 형식이 아닙니다.")
11+
String code
12+
) {
13+
}

src/main/java/clap/server/adapter/outbound/persistense/CategoryPersistenceAdapter.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import clap.server.domain.model.task.Category;
1010
import lombok.RequiredArgsConstructor;
1111

12+
import java.util.List;
1213
import java.util.Optional;
1314

1415
@PersistenceAdapter
@@ -24,6 +25,30 @@ public Optional<Category> findById(Long id) {
2425
return categoryEntity.map(categoryPersistenceMapper::toDomain);
2526
}
2627

28+
@Override
29+
public List<Category> findAll() {
30+
return categoryRepository.findByIsDeletedFalse()
31+
.stream()
32+
.map(categoryPersistenceMapper::toDomain)
33+
.toList();
34+
}
35+
36+
@Override
37+
public List<Category> findMainCategory() {
38+
return categoryRepository.findByIsDeletedFalseAndMainCategoryIsNull()
39+
.stream()
40+
.map(categoryPersistenceMapper::toDomain)
41+
.toList();
42+
}
43+
44+
@Override
45+
public List<Category> findSubCategory() {
46+
return categoryRepository.findByIsDeletedFalseAndMainCategoryIsNotNull()
47+
.stream()
48+
.map(categoryPersistenceMapper::toDomain)
49+
.toList();
50+
}
51+
2752
@Override
2853
public void save(Category category) {
2954
categoryRepository.save(categoryPersistenceMapper.toEntity(category));

src/main/java/clap/server/adapter/outbound/persistense/repository/task/CategoryRepository.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
import org.springframework.data.jpa.repository.JpaRepository;
44
import org.springframework.stereotype.Repository;
55

6+
import java.util.List;
7+
68
@Repository
79
public interface CategoryRepository extends JpaRepository<CategoryEntity, Long> {
10+
11+
List<CategoryEntity> findByIsDeletedFalse();
12+
List<CategoryEntity> findByIsDeletedFalseAndMainCategoryIsNull();
13+
List<CategoryEntity> findByIsDeletedFalseAndMainCategoryIsNotNull();
814
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package clap.server.application.mapper.response;
2+
3+
import clap.server.adapter.inbound.web.dto.admin.FindAllCategoryResponse;
4+
import clap.server.adapter.inbound.web.dto.admin.FindMainCategoryResponse;
5+
import clap.server.adapter.inbound.web.dto.admin.FindSubCategoryResponse;
6+
import clap.server.domain.model.task.Category;
7+
8+
import java.util.List;
9+
10+
public class CategoryResponseMapper {
11+
12+
public static FindAllCategoryResponse toFindAllCategoryResponse(
13+
List<FindMainCategoryResponse> mainCategoryResponses,
14+
List<FindSubCategoryResponse> subCategoryResponses) {
15+
return new FindAllCategoryResponse(mainCategoryResponses, subCategoryResponses);
16+
}
17+
18+
public static FindMainCategoryResponse toFindMainCategoryResponse(Category category) {
19+
return new FindMainCategoryResponse(category.getCategoryId(), category.getName(), category.getCode());
20+
}
21+
22+
public static FindSubCategoryResponse toFindSubCategoryResponse(Category category) {
23+
return new FindSubCategoryResponse(category.getCategoryId(), category.getMainCategory().getCategoryId(), category.getName(), category.getCode());
24+
}
25+
}

0 commit comments

Comments
 (0)