package cn.edu.whu.boot.apkversion.controller;

import cn.edu.whu.boot.apkversion.service.ApkVersionService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("apkversion")
public class ApkVersionController {

    @Autowired
    ApkVersionService versionService;

    @RequestMapping(value="latest",produces="text/html;charset=UTF-8")
    @ResponseBody
    public String getLatestVersionInfo(){

        String latestVersion=versionService.getLatestVersion();
        String downUrl=versionService.getApkPath(latestVersion);
        String description=versionService.getDescriptionByVersion(latestVersion);
        JSONObject jsonVersion=new JSONObject();
        jsonVersion.put("version",latestVersion);
        jsonVersion.put("downUrl",downUrl);
        jsonVersion.put("description",description);
        return  JSON.toJSONString(jsonVersion);
    }
}

