package com.weiwojc.controller;
|
|
import com.weiwojc.model.common.Result;
|
import com.weiwojc.model.entity.SecretKey;
|
import com.weiwojc.service.SecretKeyService;
|
import lombok.RequiredArgsConstructor;
|
import org.springframework.web.bind.annotation.*;
|
|
@RestController
|
@RequestMapping("/api/secret-key")
|
@RequiredArgsConstructor
|
public class SecretKeyController {
|
|
private final SecretKeyService secretKeyService;
|
|
/**
|
* 获取当前密钥
|
*/
|
@GetMapping
|
public Result<SecretKey> getCurrentSecretKey() {
|
SecretKey secretKey = secretKeyService.getCurrentSecretKey();
|
return Result.success(secretKey);
|
}
|
|
/**
|
* 更新密钥
|
*/
|
@GetMapping("/update/{key}")
|
public Result<SecretKey> updateSecretKey(@PathVariable String key) {
|
try {
|
SecretKey secretKey = secretKeyService.updateSecretKey(key);
|
return Result.success("密钥更新成功", secretKey);
|
} catch (RuntimeException e) {
|
return Result.badRequest(e.getMessage());
|
}
|
}
|
}
|