package com.lutao.cloud.admin.controller;

import cn.hutool.json.JSONArray;
import com.lutao.cloud.admin.api.entity.SysRouteConf;
import com.lutao.cloud.admin.service.SysRouteConfService;
import com.lutao.cloud.common.core.util.MessageInfo;
import com.lutao.cloud.common.log.annotation.SysLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * 路由
 *

 * @date 2018-11-06 10:17:18
 */
@Api(value = "/route", tags ={"路由"})
@ApiIgnore
@RestController
@AllArgsConstructor
@RequestMapping("/route")
public class SysRouteConfController{

	private final SysRouteConfService sysRouteConfService;

	/**
	 * 获取当前定义的路由信息
	 * @return
	 */
	@ApiOperation(value = "获取当前定义的路由信息", notes = "获取当前定义的路由信息", httpMethod = "GET")
	@GetMapping
	public MessageInfo<List<SysRouteConf>> listRoutes(){
		return MessageInfo.ok(sysRouteConfService.list());
	}

	/**
	 * 修改路由
	 * @param routes 路由定义
	 * @return
	 */
	@ApiOperation(value = "修改路由", notes = "修改路由", httpMethod = "PUT")
	@SysLog("修改路由")
	@PutMapping
	public MessageInfo<Mono<Void>> updateRoutes(@RequestBody JSONArray routes){
		return MessageInfo.ok(sysRouteConfService.updateRoutes(routes));
	}

}
