select dishes by categoryId
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package com.sky.controller.user;
|
||||
|
||||
import com.sky.result.Result;
|
||||
import com.sky.service.DishService;
|
||||
import com.sky.vo.DishVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/user/dish")
|
||||
@Api(tags = "UserDish")
|
||||
@Slf4j
|
||||
public class UserDishController {
|
||||
@Autowired
|
||||
private DishService dishService;
|
||||
|
||||
@GetMapping("/list")
|
||||
public Result<List<DishVO>> list(Long categoryId) {
|
||||
log.info("select dishes by categoryId {}", categoryId);
|
||||
return Result.success(dishService.getDishVoByCategoryId(categoryId));
|
||||
}
|
||||
}
|
||||
@@ -57,4 +57,6 @@ public interface DishService {
|
||||
* @param id
|
||||
*/
|
||||
void startOrStop(Integer status, Long id);
|
||||
|
||||
List<DishVO> getDishVoByCategoryId(Long categoryId);
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@@ -196,4 +198,17 @@ public class DishServiceImpl implements DishService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DishVO> getDishVoByCategoryId(Long categoryId) {
|
||||
List<Dish> dishes = dishMapper.selectByCategoryId(categoryId);
|
||||
List<DishVO> dishVOList = new ArrayList<>();
|
||||
for (Dish dish : dishes) {
|
||||
DishVO dishVO = new DishVO();
|
||||
BeanUtils.copyProperties(dish, dishVO);
|
||||
dishVO.setFlavors(dishFlavorMapper.getByDishId(dish.getId()));
|
||||
dishVOList.add(dishVO);
|
||||
}
|
||||
return dishVOList;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user