package ink.wgink.gateway.router.routetype;

import ink.wgink.gateway.consts.ISystemConst;
import ink.wgink.gateway.handler.routetype.RouteTypeHandler;
import ink.wgink.gateway.router.BaseRouter;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;

/**
 * When you feel like quitting. Think about why you started
 * 当你想要放弃的时候，想想当初你为何开始
 *
 * @ClassName: RouteTypeRouter
 * @Description: 路由类型
 * @Author: WangGeng
 * @Date: 2021/5/8 13:14
 * @Version: 1.0
 **/
@Component
public class RouteTypeRouter extends BaseRouter {

    @Bean
    public RouterFunction<ServerResponse> routeTypeRouterFunction(RouteTypeHandler routeTypeHandler) {
        return RouterFunctions.nest(RequestPredicates.path(ISystemConst.ADMIN_ROUTER_PREFIX + "/api/route-type"),
                RouterFunctions
                        .route(RequestPredicates.POST("/save"), routeTypeHandler::save)
                        .andRoute(RequestPredicates.DELETE("/delete/{ids}"), routeTypeHandler::delete)
                        .andRoute(RequestPredicates.PUT("/update/{id}"), routeTypeHandler::update)
                        .andRoute(RequestPredicates.GET("/list"), routeTypeHandler::list)
                        .andRoute(RequestPredicates.GET("/get/{id}"), routeTypeHandler::get));
    }

}
