package cn.reghao.oss.console.app.controller.page;

import cn.reghao.oss.console.app.model.vo.KeyValue;
import cn.reghao.oss.console.app.model.vo.UserKeyVo;
import cn.reghao.oss.console.app.service.StoreNodeService;
import cn.reghao.oss.console.app.service.UserKeyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author reghao
 * @date 2024-02-27 10:24:31
 */
@Api(tags = "我的帐号页面")
@Controller
@RequestMapping("/store/my/key")
public class UserKeyPageController {
    private final StoreNodeService storeNodeService;
    private final UserKeyService userKeyService;

    public UserKeyPageController(StoreNodeService storeNodeService, UserKeyService userKeyService) {
        this.storeNodeService = storeNodeService;
        this.userKeyService = userKeyService;
    }

    @ApiOperation(value = "我的帐号页面")
    @GetMapping(value = "")
    public String userKeyPage(Model model) {
        List<UserKeyVo> list = userKeyService.getUserKeys();
        model.addAttribute("list", list);
        return "/userkey/index1";
    }

    @ApiOperation(value = "帐号创建页面")
    @GetMapping(value = "/add")
    public String userKeyAddPage(Model model) {
        List<KeyValue> storeNodes = storeNodeService.getNodeKeyValues();
        model.addAttribute("storeNodes", storeNodes);
        return "/userkey/add";
    }
}
