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

import cn.reghao.jutil.jdk.result.Result;
import cn.reghao.jutil.jdk.result.WebResult;
import cn.reghao.oss.web.app.model.dto.UserNodeDto;
import cn.reghao.oss.web.app.model.po.StoreNode;
import cn.reghao.oss.web.app.service.UserNodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author reghao
 * @date 2024-02-27 09:40:54
 */
@Api(tags = "用户存储节点数据接口")
@RestController
@RequestMapping("/api/store/my")
public class UserStoreNodeController {
    private final UserNodeService userNodeService;

    public UserStoreNodeController(UserNodeService userNodeService) {
        this.userNodeService = userNodeService;
    }

    @ApiOperation(value = "添加存储节点")
    @PostMapping(value = "/add", produces = MediaType.APPLICATION_JSON_VALUE)
    public String addUserNode(@Validated UserNodeDto userNodeDto) {
        Result result = userNodeService.add(userNodeDto);
        return WebResult.result(result);
    }

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