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

import cn.reghao.jutil.jdk.result.Result;
import cn.reghao.oss.console.app.model.dto.NodeUpdateDto;
import cn.reghao.jutil.jdk.result.WebResult;
import cn.reghao.oss.console.app.service.StoreNodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author reghao
 * @date 2024-02-23 11:29:14
 */
@Slf4j
@Api(tags = "存储节点数据接口")
@RestController
@RequestMapping("/api/store/node")
public class StoreNodeController {
    private final StoreNodeService storeNodeService;

    public StoreNodeController(StoreNodeService storeNodeService) {
        this.storeNodeService = storeNodeService;
    }

    @ApiOperation(value = "设置存储节点的域名")
    @PostMapping(value = "/update", produces = MediaType.APPLICATION_JSON_VALUE)
    public String updateStoreNodeDomain(@Validated NodeUpdateDto nodeUpdateDto) {
        Result result = storeNodeService.updateDomain(nodeUpdateDto);
        return WebResult.result(result);
    }

    @ApiOperation(value = "删除存储节点")
    @DeleteMapping(value = "/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
    public String deleteStoreNode(@PathVariable("id") Integer nodeId) {
        Result result = storeNodeService.delete(nodeId);
        return WebResult.result(result);
    }
}
