package cn.reghao.devops.mgr.build.controller;

import cn.reghao.devops.mgr.build.service.BuildDirService;
import cn.reghao.jutil.jdk.result.Result;
import cn.reghao.jutil.jdk.result.WebResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @author reghao
 * @date 2019-08-30 18:49:15
 */
@Slf4j
@Api(tags = "构建目录配置接口")
@RestController
@RequestMapping("/api/build/dir")
public class BuildDirController {
    private final BuildDirService buildDirService;

    public BuildDirController(BuildDirService buildDirService) {
        this.buildDirService = buildDirService;
    }

    @ApiOperation(value = "清空构建目录", notes = "N")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    @PostMapping(value = "/erase", produces = MediaType.APPLICATION_JSON_VALUE)
    public String emptyBuildDir() {
        Result result = buildDirService.erase();
        return WebResult.result(result);
    }
}
