package com.sv.api.controller;

import com.sv.api.service.impl.LoginRegisterServiceImpl;
import com.sv.service.common.OSSClientUtil;
import com.ydd.framework.core.annotation.AccessToken;
import com.ydd.framework.core.common.dto.ResponseDTO;
import com.ydd.framework.core.controller.BaseApiController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;

@RestController("upload")
public class UploadController extends BaseApiController {


    @Resource
    private OSSClientUtil ossClientUtil;
    @Resource
    private LoginRegisterServiceImpl loginRegisterService;

    @RequestMapping("/upload/avatar")
    @AccessToken
    public ResponseDTO uploadImg(@RequestParam("image") MultipartFile file) throws IOException {
        String imgUrl = ossClientUtil.uploadImg(file);
        loginRegisterService.updateInformation(getLoginMemberId(),null,imgUrl);
        return ResponseDTO.ok();
    }

}
