package com.ruoyi.web.app;

import com.ruoyi.bst.order.domain.OrderQuery;
import com.ruoyi.bst.order.domain.dto.OrderCreateDTO;
import com.ruoyi.bst.order.service.OrderService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.enums.LogBizType;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/app/order")
public class AppOrderController extends BaseController {

    @Autowired
    private OrderService orderService;

    @ApiOperation("下单并支付")
    @PostMapping
    public AjaxResult createOrder(@RequestBody @Validated OrderCreateDTO dto) {
        dto.setUserId(getUserId());
        return success(orderService.createOrder(dto));
    }

    @ApiOperation("用户查看自己的订单信息")
    @GetMapping
    public TableDataInfo list(OrderQuery query) {
        startPage();
        query.setUserId(getUserId());
        return getDataTable(orderService.selectOrderList(query));
    }

    @ApiOperation("查看订单详情")
    @GetMapping("/orderDetail/{orderId}")
    public AjaxResult orderDetail(@PathVariable Long orderId) {
        OrderQuery query = new OrderQuery();
        query.setId(orderId);
        query.setUserId(getUserId());
        return success( orderService.selectOne(query));
    }

}
