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

import com.hc.business.model.ZccmUserAdvise;
import com.hc.business.service.ZccmUserAdviseService;
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;


/**
 * 用户建议表
 * (UserAdvise)表控制层
 *
 * @author java
 * @since 2020-11-16 14:20:06
 */

@RestController
@RequestMapping("/new/api/app/userAdvise")
public class AppUserAdviseController {

    /**
     * 服务对象
     */
    private final ZccmUserAdviseService userAdviseService;

    public AppUserAdviseController(ZccmUserAdviseService userAdviseService) {
        this.userAdviseService = userAdviseService;
    }

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

    @PostMapping("/insert")
    @ApiOperation(value = "新增 UserAdvise", response = Result.class)
    public Result addAppUserAdvise(@Valid @RequestBody ZccmUserAdvise userAdvise) {
        userAdvise.setAdviceType(2);
        return Result.success(userAdviseService.insert(userAdvise));
    }

    @GetMapping("/user/{userId}")
    @ApiOperation(value = "依据用户id获取 UserAdvise", response = Result.class)
    public Result listAppUserAdviseById(@ApiParam(value = "用户id")
                                        @PathVariable("userId") Integer userId,
                                        @RequestParam(defaultValue = "0") Integer page,
                                        @RequestParam(defaultValue = "0") Integer size) {
        return Result.success(this.userAdviseService.queryAllByUserId(userId, page, size));
    }

}