package com.hc.web.controller.browser.front;

import com.hc.business.model.OrderUserLog;
import com.hc.business.service.OrderUserLogService;
import com.hc.core.utils.result.Result;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


/**
 * (OrderUserLog)表控制层
 *
 * @author java
 * @since 2020-12-03 09:25:12
 */

@RestController
@RequestMapping("/new/api/front/orderUserLog")
public class FrontOrderUserLogController {

    /**
     * 服务对象
     */
    private final OrderUserLogService orderUserLogService;

    public FrontOrderUserLogController(OrderUserLogService orderUserLogService) {
        this.orderUserLogService = orderUserLogService;
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "依据主键获取 OrderUserLog", response = Result.class)
    public Result selectFrontOrderUserLog(@PathVariable("id") Integer id) {
        return Result.success(this.orderUserLogService.queryById(id));
    }

    @PostMapping("/insert")
    @ApiOperation(value = "新增 OrderUserLog", response = Result.class)
    public Result addFrontOrderUserLog(@Valid @RequestBody OrderUserLog orderUserLog) {
        return Result.success(orderUserLogService.insert(orderUserLog));
    }

    @GetMapping("/order/{orderId}")
    @ApiOperation(value = "依据订单id 获取 OrderUserLog", response = Result.class)
    public Result selectOrderUserLogByOrderId(@ApiParam(value = "订单id") @PathVariable("orderId") Integer orderId) {
        return Result.success(orderUserLogService.queryListByOrderId(orderId));
    }

    @PostMapping("/insert/list")
    @ApiOperation(value = "批量 新增 OrderUserLog", response = Result.class)
    public Result addFrontOrderUserLogList(@RequestBody List<OrderUserLog> orderUserLogList) {
        orderUserLogList.forEach(orderUserLogService::insert);
        return Result.success(orderUserLogList);
    }


}