diff --git a/heachi-core/housework-api/src/main/java/com/heachi/housework/api/controller/housework/category/HouseworkCategoryController.java b/heachi-core/housework-api/src/main/java/com/heachi/housework/api/controller/housework/category/HouseworkCategoryController.java new file mode 100644 index 00000000..9252cead --- /dev/null +++ b/heachi-core/housework-api/src/main/java/com/heachi/housework/api/controller/housework/category/HouseworkCategoryController.java @@ -0,0 +1,24 @@ +package com.heachi.housework.api.controller.housework.category; + +import com.heachi.admin.common.response.JsonResult; +import com.heachi.housework.api.service.housework.category.HouseworkCategoryService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Slf4j +@RestController +@RequiredArgsConstructor +@RequestMapping("/housework/category") +public class HouseworkCategoryController { + + private final HouseworkCategoryService houseworkCategoryService; + + @GetMapping("/") + public JsonResult selectCategory() { + + return JsonResult.successOf(houseworkCategoryService.selectCategory()); + } +} diff --git a/heachi-core/housework-api/src/main/java/com/heachi/housework/api/service/housework/category/HouseworkCategoryService.java b/heachi-core/housework-api/src/main/java/com/heachi/housework/api/service/housework/category/HouseworkCategoryService.java new file mode 100644 index 00000000..d5cbd766 --- /dev/null +++ b/heachi-core/housework-api/src/main/java/com/heachi/housework/api/service/housework/category/HouseworkCategoryService.java @@ -0,0 +1,27 @@ +package com.heachi.housework.api.service.housework.category; + +import com.heachi.housework.api.service.housework.category.response.HouseworkCategoryResponse; +import com.heachi.mysql.define.housework.category.repository.HouseworkCategoryRepository; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.stream.Collectors; + +@Slf4j +@Service +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class HouseworkCategoryService { + + private final HouseworkCategoryRepository houseworkCategoryRepository; + + public List selectCategory() { + + return houseworkCategoryRepository.findAll().stream() + .map(HouseworkCategoryResponse::of) + .collect(Collectors.toList()); + } +} diff --git a/heachi-core/housework-api/src/main/java/com/heachi/housework/api/service/housework/category/response/HouseworkCategoryResponse.java b/heachi-core/housework-api/src/main/java/com/heachi/housework/api/service/housework/category/response/HouseworkCategoryResponse.java new file mode 100644 index 00000000..991a3452 --- /dev/null +++ b/heachi-core/housework-api/src/main/java/com/heachi/housework/api/service/housework/category/response/HouseworkCategoryResponse.java @@ -0,0 +1,27 @@ +package com.heachi.housework.api.service.housework.category.response; + +import com.heachi.mysql.define.housework.category.HouseworkCategory; +import lombok.Builder; +import lombok.Getter; +import lombok.ToString; + +@Getter +@ToString +public class HouseworkCategoryResponse { + private Long id; // 카테고리 아이디 + private String name; // 카테고리 이름 + + @Builder + private HouseworkCategoryResponse(Long id, String name) { + this.id = id; + this.name = name; + } + + public static HouseworkCategoryResponse of(HouseworkCategory houseworkCategory) { + + return HouseworkCategoryResponse.builder() + .id(houseworkCategory.getId()) + .name(houseworkCategory.getName()) + .build(); + } +}