package com.corewing.app.modules.app;

import com.corewing.app.common.Result;
import com.corewing.app.common.annotation.CommonLog;
import com.corewing.app.dto.CheckVersionRequest;
import com.corewing.app.entity.AppVersion;
import com.corewing.app.service.AppVersionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * app升级校验接口
 */
@Api(tags = "APP版本接口")
@RestController
@RequestMapping("/app_version")
public class AppVersionController {

    @Resource
    private AppVersionService appVersionService;

    /**
     * 校验是否存在新版本
     * @param checkVersionRequest
     * @return
     */
    @CommonLog("校验是否有新版本")
    @ApiOperation("校验是否有新版本")
    @GetMapping("/checkUpdate")
    public Result<Object> checkUpdate(CheckVersionRequest checkVersionRequest) {
        AppVersion version =  appVersionService.getNewAppVersion(checkVersionRequest);
        if(version == null) {
            return Result.error("暂无新版本");
        }
        return Result.success(version);

    }

}
