<commit_before>package server

import (
	"net/http"

	"github.com/gin-gonic/gin"
	"gitlab-odx.oracle.com/odx/functions/api"
	"gitlab-odx.oracle.com/odx/functions/api/models"
)

func (s *Server) handleRouteList(c *gin.Context) {
	ctx := c.Request.Context()

	filter := &models.RouteFilter{}

	if img := c.Query("image"); img != "" {
		filter.Image = img
	}

	var routes []*models.Route
	var err error
	appName, exists := c.Get(api.AppName)
	name, ok := appName.(string)
	if exists && ok && name != "" {
		routes, err = s.Datastore.GetRoutesByApp(ctx, name, filter)
	} else {
		routes, err = s.Datastore.GetRoutes(ctx, filter)
	}

	if err != nil {
		handleErrorResponse(c, err)
		return
	}

	c.JSON(http.StatusOK, routesResponse{"Successfully listed routes", routes})
}<commit_msg>Ensure app exists before listing its routes<commit_after>package server

import (
	"net/http"

	"github.com/gin-gonic/gin"
	"gitlab-odx.oracle.com/odx/functions/api"
	"gitlab-odx.oracle.com/odx/functions/api/models"
)

func (s *Server) handleRouteList(c *gin.Context) {
	ctx := c.Request.Context()

	filter := &models.RouteFilter{}

	if img := c.Query("image"); img != "" {
		filter.Image = img
	}

	var routes []*models.Route
	var err error
	appName, exists := c.Get(api.AppName)
	name, ok := appName.(string)
	if exists && ok && name != "" {
		routes, err = s.Datastore.GetRoutesByApp(ctx, name, filter)
		if len(routes) == 0 {
			_, err = s.Datastore.GetApp(ctx, name)
		}
	} else {
		routes, err = s.Datastore.GetRoutes(ctx, filter)
	}

	if err != nil {
		handleErrorResponse(c, err)
		return
	}

	c.JSON(http.StatusOK, routesResponse{"Successfully listed routes", routes})
}
{'fraction_non_alphanumeric': 0.16344993968636912, 'fraction_numerical': 0.0006031363088057901, 'mean_word_length': 3.922848664688427, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6579822', 'n_tokens_mistral': 656, 'n_tokens_neox': 629, 'n_words': 130}