package com.skr.mdm.controller;

import com.skr.mdm.constant.CmdTypeConstants;
import com.skr.mdm.dto.LoginUserDTO;
import com.skr.mdm.result.ResponseResult;
import com.skr.mdm.service.CmdHandlerService;
import com.skr.mdm.service.StrategyFactory;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @author nfq
 * @date 2020/8/11 15:31
 */
@RestController
@Slf4j
@Api(tags = "应用安装上传")
@RequestMapping("/appInstall")
public class AppInstallController {

    @PostMapping("upload")
    @ApiOperation("应用安装信息上传")
    public ResponseResult uploadAppInstall(@RequestParam @ApiParam(value = "安装信息", required = true) String data,
                                           @ApiIgnore Authentication authentication) {
        LoginUserDTO loginUserDTO = (LoginUserDTO) authentication.getPrincipal();
        CmdHandlerService strategy = StrategyFactory.getStrategy(CmdTypeConstants.APP_INSTALL_INFO);
        return strategy.cmdHandler(loginUserDTO.getId(), data);
    }
}
