package com.playlet.web.controller.tool;

import com.playlet.common.core.domain.Result;
import com.playlet.web.service.SmsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>短信接口</p>
 * @author clunt
 */
@Slf4j
@RestController
@Api(tags = "通用*短信接口")
@RequestMapping(value = "/tool/sms")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class SmsController {

    private final SmsService smsService;

    @ApiOperation(value = "发送短信验证码", httpMethod = "POST")
    @PostMapping("/sendSmsCode")
    @ResponseBody
    public Result<String> sendSmsCode(@RequestParam(value = "phone") String phone){
        try {
            smsService.sendSmsCode(phone);
            return Result.success();
        }catch (Exception e){
            log.error("调用短信服务异常:{}", e.getMessage(), e);
            return Result.error();
        }
    }

}
