Search in sources :

Example 1 with SearchRouteService

use of com.searchcode.app.service.route.SearchRouteService in project searchcode-server by boyter.

the class SearchcodeRoutes method RegisterSearchcodeRoutes.

public static void RegisterSearchcodeRoutes() {
    get("/", (request, response) -> {
        var codeRouteService = new CodeRouteService();
        var map = codeRouteService.html(request, response);
        if ((Boolean) map.getOrDefault("isIndex", Boolean.TRUE)) {
            return new FreeMarkerEngine().render(new ModelAndView(map, "index.ftl"));
        }
        return new FreeMarkerEngine().render(new ModelAndView(map, "searchcode_searchresults.ftl"));
    });
    get("/healthcheck/", (request, response) -> new JsonTransformer().render(true));
    get("/health-check/", (request, response) -> new JsonTransformer().render(true));
    get("/file/:codeid/*", (request, response) -> {
        var codeRouteService = new CodeRouteService();
        return new FreeMarkerEngine().render(new ModelAndView(codeRouteService.getCode(request, response), "coderesult.ftl"));
    });
    get("/repository/overview/:reponame/:repoid/", (request, response) -> {
        var codeRouteService = new CodeRouteService();
        return new FreeMarkerEngine().render(new ModelAndView(codeRouteService.getProject(request, response), "repository_overview.ftl"));
    });
    // /api/codesearch_I/
    path("/api", () -> {
        // Older endpoints maintained for backwards compatibility
        get("/codesearch_I/", (request, response) -> {
            addJsonHeaders(response);
            var searchRouteService = new SearchRouteService();
            return new JsonTransformer().render(searchRouteService.codeSearch_I(request, response));
        });
        get("/result/:codeid/", (request, response) -> {
            addJsonHeaders(response);
            var searchRouteService = new SearchRouteService();
            return new JsonTransformer().render(searchRouteService.codeResult(request, response));
        });
        // All new API endpoints should go in here to allow public exposure and versioning
        path("/v1", () -> {
            get("/version/", (request, response) -> {
                addJsonHeaders(response);
                return new JsonTransformer().render("");
            });
            get("/health-check/", (request, response) -> {
                addJsonHeaders(response);
                return new JsonTransformer().render("");
            });
        });
    });
}
Also used : FreeMarkerEngine(spark.template.freemarker.FreeMarkerEngine) CodeRouteService(com.searchcode.app.service.route.CodeRouteService) SearchRouteService(com.searchcode.app.service.route.SearchRouteService) ModelAndView(spark.ModelAndView) JsonTransformer(com.searchcode.app.util.JsonTransformer)

Aggregations

CodeRouteService (com.searchcode.app.service.route.CodeRouteService)1 SearchRouteService (com.searchcode.app.service.route.SearchRouteService)1 JsonTransformer (com.searchcode.app.util.JsonTransformer)1 ModelAndView (spark.ModelAndView)1 FreeMarkerEngine (spark.template.freemarker.FreeMarkerEngine)1