Skip to content

Commit

Permalink
Merge pull request #34 from Digital-Hana-Starbucks/feature/menu
Browse files Browse the repository at this point in the history
Feat: 카테고리 전체조회 API 작성 (#28)
  • Loading branch information
abcxj123 authored May 7, 2024
2 parents fcee988 + 77d854b commit d9cf978
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -18,6 +20,7 @@
@CrossOrigin("http://localhost:5173")
public class MenuController {
private final MenuService menuService;
private final CategoryService categoryService;

@GetMapping("")
public List<MenuResDto> getMenuList() {
Expand All @@ -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<CategoryResDto> getCategoryList() {
return categoryService.getCategoryList();
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
21 changes: 21 additions & 0 deletions src/main/java/com/hanaro/starbucks/service/CategoryService.java
Original file line number Diff line number Diff line change
@@ -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<CategoryResDto> getCategoryList() {
List<Category> categories = categoryRepository.findAll();
return categories.stream().map(CategoryResDto::new).collect(Collectors.toList());
}
}

0 comments on commit d9cf978

Please sign in to comment.