package com.ruoyi.web.modules.home.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.web.modules.home.service.IGoodsAppService;

/**
 * C 端商品详情（只读）
 */
@RestController
@RequestMapping("/api/goods")
public class GoodsAppController extends BaseController
{
    @Autowired
    private IGoodsAppService goodsAppService;

    @Anonymous
    @GetMapping("/{goodsId}")
    public AjaxResult detail(@PathVariable("goodsId") Long goodsId)
    {
        return success(goodsAppService.getDetail(goodsId));
    }

    @Anonymous
    @GetMapping("/{goodsId}/can-purchase")
    public AjaxResult canPurchase(@PathVariable("goodsId") Long goodsId)
    {
        return success(goodsAppService.canPurchase(goodsId));
    }

    @Anonymous
    @GetMapping("/{goodsId}/reviews")
    public TableDataInfo reviews(@PathVariable("goodsId") Long goodsId)
    {
        startPage();
        return getDataTable(goodsAppService.listReviews(goodsId));
    }
}
