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

import cn.reghao.jutil.jdk.result.Result;
import cn.reghao.jutil.jdk.result.WebResult;
import cn.reghao.oss.console.app.model.dto.UserNodeDto;
import cn.reghao.oss.console.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 UserNodeController {
    private final UserNodeService userNodeService;

    public UserNodeController(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 userNodeId) {
        Result result = userNodeService.delete(userNodeId);
        return WebResult.result(result);
    }
}
