diff --git a/src/main/java/com/hanaro/starbucks/controller/MenuController.java b/src/main/java/com/hanaro/starbucks/controller/MenuController.java index 89be5ba..063c438 100644 --- a/src/main/java/com/hanaro/starbucks/controller/MenuController.java +++ b/src/main/java/com/hanaro/starbucks/controller/MenuController.java @@ -1,7 +1,9 @@ package com.hanaro.starbucks.controller; +import com.hanaro.starbucks.dto.category.CategoryResDto; import com.hanaro.starbucks.dto.menu.MenuReqDto; import com.hanaro.starbucks.dto.menu.MenuResDto; +import com.hanaro.starbucks.service.CategoryService; import com.hanaro.starbucks.service.MenuService; import lombok.RequiredArgsConstructor; import org.springframework.http.MediaType; @@ -18,6 +20,7 @@ @CrossOrigin("http://localhost:5173") public class MenuController { private final MenuService menuService; + private final CategoryService categoryService; @GetMapping("") public List getMenuList() { @@ -43,4 +46,9 @@ public void deleteMenuByMenuIdx(@PathVariable int menuIdx) throws Exception{ public void updateMenu(@PathVariable int menuIdx, @RequestPart(value = "dto") MenuReqDto menuReqDto, @RequestPart(value = "menuImg", required = false) MultipartFile img) throws Exception{ menuService.updateMenu(menuIdx, menuReqDto, img); } + + @GetMapping("/category") + public List getCategoryList() { + return categoryService.getCategoryList(); + } } diff --git a/src/main/java/com/hanaro/starbucks/dto/category/CategoryResDto.java b/src/main/java/com/hanaro/starbucks/dto/category/CategoryResDto.java new file mode 100644 index 0000000..a5b49e5 --- /dev/null +++ b/src/main/java/com/hanaro/starbucks/dto/category/CategoryResDto.java @@ -0,0 +1,19 @@ +package com.hanaro.starbucks.dto.category; + +import com.hanaro.starbucks.entity.Category; +import lombok.Getter; +import lombok.NoArgsConstructor; + + +@Getter +@NoArgsConstructor +public class CategoryResDto { + private int categoryIdx; + + private String categoryName; + + public CategoryResDto(Category category) { + this.categoryIdx = category.getCategoryIdx(); + this.categoryName = category.getCategoryName(); + } +} diff --git a/src/main/java/com/hanaro/starbucks/service/CategoryService.java b/src/main/java/com/hanaro/starbucks/service/CategoryService.java new file mode 100644 index 0000000..1830cca --- /dev/null +++ b/src/main/java/com/hanaro/starbucks/service/CategoryService.java @@ -0,0 +1,21 @@ +package com.hanaro.starbucks.service; + +import com.hanaro.starbucks.dto.category.CategoryResDto; +import com.hanaro.starbucks.entity.Category; +import com.hanaro.starbucks.repository.CategoryRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.stream.Collectors; + +@Service +@RequiredArgsConstructor +public class CategoryService { + private final CategoryRepository categoryRepository; + + public List getCategoryList() { + List categories = categoryRepository.findAll(); + return categories.stream().map(CategoryResDto::new).collect(Collectors.toList()); + } +}