package com.czg.controller.admin;

import com.czg.account.service.CommonService;
import com.czg.resp.CzgResult;
import com.czg.service.account.util.AliOssUtil;
import jakarta.annotation.Resource;
import org.apache.commons.io.FilenameUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 公共接口
 * @author Administrator
 */
@RestController
@RequestMapping("/admin/common")
public class CommonController {
    @Resource
    private CommonService commonService;
    @Resource
    private AliOssUtil aliOssUtil;

    /**
     * 发送验证码
     * @param type 验证码类型
     * @return 是否成功
     */
    @GetMapping("/sms")
    public CzgResult<Boolean> sendSms(@RequestParam String type) {
        return CzgResult.success(commonService.sendSms(type));
    }

    /**
     * 文件上传
     * @param file 文件对象
     * @return 文件地址
     */
    @PostMapping("/upload")
    public CzgResult<String> upload(@RequestParam MultipartFile file) throws Exception {
        return CzgResult.success(aliOssUtil.uploadSuffix(file.getBytes(), FilenameUtils.getExtension(file.getOriginalFilename())));
    }
}
