hongjli
2025-05-27 e7868348433a03f7aa61c84462697d93226b5df3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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());
        }
    }