package com.waimai.api;

import com.waimai.common.annotation.Anonymous;
import com.waimai.common.core.controller.BaseController;
import com.waimai.common.core.domain.R;
import com.waimai.web.admin.domain.Food;
import com.waimai.web.admin.service.IFoodService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Anonymous
@RequestMapping("/api/food")
public class FoodsApiController {

    @Resource
    private IFoodService foodService;

    /**
     * 推荐食品
     *
     * @return
     */
    @RequestMapping("/recommend")
    public R<List<Food>> recommend() {
        return R.ok(foodService.selectFoodList(new Food()));
    }

    @RequestMapping("/category/{cid}")
    public R<List<Food>> selectByCategory(@PathVariable("cid") Long cid) {
        Food food = new Food();
        food.setCid(cid);
        return R.ok(foodService.selectFoodList(food));
    }

    @GetMapping("/{id}")
    public R<Food> selectDetail(@PathVariable Long id){
        return R.ok(foodService.selectFoodById(id));
    }
}
