package com.gree.mall.miniapp.controller.common;

import com.gree.mall.miniapp.annotation.ApiNotAuth;
import com.gree.mall.miniapp.exception.RemoteServiceException;
import com.gree.mall.miniapp.logic.common.CommonLogic;
import lombok.RequiredArgsConstructor;
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;

@RequiredArgsConstructor
@Controller
public class RedirectController {


    private final CommonLogic commonLogic;

    @ApiNotAuth
    @GetMapping("img/get")
    public void getImg(
            @RequestParam() String key,
            HttpServletResponse response
    ) throws IOException, RemoteServiceException {
        String file = commonLogic.getFile(key);
        response.sendRedirect(file);
    }


    @ApiNotAuth
    @GetMapping("redirect")
    public void redirect(
            @RequestParam() String url,
            HttpServletResponse response
    ) throws IOException, RemoteServiceException {
        response.sendRedirect(url);
    }

}
