package com.qmth.themis.admin.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qmth.themis.business.constant.SystemConstant;
import com.qmth.themis.business.entity.TBAppVersion;
import com.qmth.themis.business.service.TBAppVersionService;
import com.qmth.themis.common.util.Result;
import com.qmth.themis.common.util.ResultUtil;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.util.Collections;

/**
 * @Description: 移动端 前端控制器
 * @Param:
 * @return:
 * @Author: wangliang
 * @Date: 2020/11/20
 */
@Api(tags = "移动端Controller")
@RestController
@RequestMapping(SystemConstant.PREFIX_URL_ADMIN + "/app")
@Validated
public class TBAppVersionController {
    private final static Logger log = LoggerFactory.getLogger(TBAppVersionController.class);

    @Resource
    TBAppVersionService tbAppVersionService;

    @ApiOperation(value = "移动端版本新增/编辑接口")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "{\"success\":true}", response = Result.class)})
    public Result save(@ApiParam(value = "移动端版本信息", required = true) @RequestBody TBAppVersion tbAppVersion) {
        tbAppVersionService.saveOrUpdate(tbAppVersion);
        return ResultUtil.ok(true);
    }

    @ApiOperation(value = "移动端版本查询接口")
    @RequestMapping(value = "/query", method = RequestMethod.POST)
    @ApiResponses({@ApiResponse(code = 200, message = "移动端信息", response = TBAppVersion.class)})
    public Result query(@ApiParam(value = "分页页码", required = true) @RequestParam @Min(SystemConstant.PAGE_NUMBER_MIN) int pageNumber,
                        @ApiParam(value = "分页数", required = true) @RequestParam @Min(SystemConstant.PAGE_SIZE_MIN) @Max(SystemConstant.PAGE_SIZE_MAX) int pageSize) {
        return ResultUtil.ok(tbAppVersionService.appVersionQuery(new Page<>(pageNumber, pageSize)));
    }
}