package com.zfire.mall.manager.controller.common;

import com.zfire.mall.manager.annotation.ApiNotAuth;
import com.zfire.mall.manager.exception.RemoteServiceException;
import com.zfire.mall.manager.logic.common.CommonLogic;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
public class RedirectController {


    @Autowired
    CommonLogic commonLogic;

    @ApiNotAuth
    @GetMapping("/img/get")
    @ApiOperation(value = "获取图片")
    public void getImg(
            @ApiParam(required = true, value = "附件key") @RequestParam(required = true) String key,
            HttpServletResponse response
    ) throws IOException, RemoteServiceException {
        String file = commonLogic.getFile(key, response);
        response.sendRedirect(file);
    }

}
