From 5f0ee3d35305e2dd1c0011d50672ec7c222f939b Mon Sep 17 00:00:00 2001 From: ghdcksgml1 Date: Sun, 5 Nov 2023 17:30:45 +0900 Subject: [PATCH] =?UTF-8?q?feat(#99):=20=EC=B9=B4=ED=85=8C=EA=B3=A0?= =?UTF-8?q?=EB=A6=AC=20=EC=A1=B0=ED=9A=8C=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../category/HouseworkCategoryController.java | 24 +++++++++++++++++ .../category/HouseworkCategoryService.java | 27 +++++++++++++++++++ .../response/HouseworkCategoryResponse.java | 27 +++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 heachi-core/housework-api/src/main/java/com/heachi/housework/api/controller/housework/category/HouseworkCategoryController.java create mode 100644 heachi-core/housework-api/src/main/java/com/heachi/housework/api/service/housework/category/HouseworkCategoryService.java create mode 100644 heachi-core/housework-api/src/main/java/com/heachi/housework/api/service/housework/category/response/HouseworkCategoryResponse.java 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(); + } +}