<commit_before>package controllers

import (
	"encoding/json"
	"net/http"

	"github.com/gorilla/mux"
	"github.com/projectjane/jane/models"
)

// GetRoutes Returns all routes, HTTP GET - /api/v1/routes
// swagger:route GET /api/v1/routes routes getRoutes
//		 Returns all routes
//
//     Consumes:
//     - application/json
//
//     Produces:
//     - application/json
//
//     Schemes: http, https
//
//     Responses:
//       200:
//       401:
//			 500:
func GetRoutes(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json")

	aliases, err := data.GetAliases()
	if err != nil {
		sendError(w, err, http.StatusInternalServerError, "Failed to get aliases.")
		return
	}

	aliasesJSON, err := json.Marshal(aliases)
	if err != nil {
		sendError(w, err, http.StatusInternalServerError, "Failed to marshal object.")
		return
	}

	w.WriteHeader(http.StatusOK)
	w.Write(aliasesJSON)
}

// GetRouteByID Returns a route by id, HTTP GET - /api/v1/routes/{id}
// swagger:route GET /api/v1/routes/{routeId} routes getRouteByID
//		 Returns a connector by id
//
//     Consumes:
//     - application/json
//
//     Produces:
//     - application/json
//
//     Schemes: http, https
//
//     Responses:
//       200:
//       401:
//			 500:
func GetRouteByID(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json")

	vars := mux.Vars(r)
	id := vars["id"]

	alias, err := data.GetAliasByID(id)
	if err != nil {
		sendError(w, err, http.StatusInternalServerError, "Failed to get alias.")
		return
	}

	aliasJSON, err := json.Marshal(alias)
	if err != nil {
		sendError(w, err, http.StatusInternalServerError, "Failed to marshal object.")
		return
	}

	w.WriteHeader(http.StatusOK)
	w.Write(aliasJSON)
}

// CreateRoute Creates a command alias, HTTP GET - /api/v1/routes
// swagger:route POST /api/v1/routes routes createRoute
//		 Creates a command alias
//
//     Consumes:
//     - application/json
//
//     Produces:
//     - application/json
//
//     Schemes: http, https
//
//     Responses:
//       200:
//       401:
//			 500:
func CreateRoute(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json")

	var alias models.Alias
	err := json.NewDecoder(r.Body).Decode(&alias)
	if err != nil {
		sendError(w, err, http.StatusInternalServerError, "Invalid alias format.")
		return
	}

	alias, err := data.CreateAlias(alias)
	if err != nil {
		sendError(w, err, http.StatusInternalServerError, "Failed to create alias.")
		return
	}

	aliasJSON, err := json.Marshal(alias)
	if err != nil {
		sendError(w, err, http.StatusInternalServerError, "Failed to marshal object.")
		return
	}

	w.WriteHeader(http.StatusOK)
	w.Write(aliasJSON)
}

// UpdateRouteByID Updates an alias, HTTP GET - /api/v1/routes/{id}
// swagger:route PUT /api/v1/routes/{routeId} routes updateRouteByID
//		 Updates an alias
//
//     Consumes:
//     - application/json
//
//     Produces:
//     - application/json
//
//     Schemes: http, https
//
//     Responses:
//       200:
//       401:
//			 500:
func UpdateRouteByID(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json")

	var alias models.Alias
	err := json.NewDecoder(r.Body).Decode(&alias)
	if err != nil {
		sendError(w, err, http.StatusInternalServerError, "Invalid connector format.")
		return
	}

	alias, err = data.UpdateAliasByID(alias)
	if err != nil {
		sendError(w, err, http.StatusInternalServerError, "Failed to update alias.")
		return
	}

	aliasJSON, err := json.Marshal(alias)
	if err != nil {
		sendError(w, err, http.StatusInternalServerError, "Failed to marshal object.")
		return
	}

	w.WriteHeader(http.StatusOK)
	w.Write(aliasJSON)
}

//RouteID Struct for routeID parameter
//swagger:parameters getRouteByID updateRouteByID
type RouteID struct {

	// in: path
	RouteID string `json:"routeId"`
}<commit_msg>Cleaning up routes controller<commit_after>package controllers

import (
	"encoding/json"
	"net/http"

	"github.com/gorilla/mux"
	"github.com/projectjane/jane/models"
)

// GetRoutes Returns all routes, HTTP GET - /api/v1/routes
// swagger:route GET /api/v1/routes routes getRoutes
//		 Returns all routes
//
//     Consumes:
//     - application/json
//
//     Produces:
//     - application/json
//
//     Schemes: http, https
//
//     Responses:
//       200:
//       401:
//			 500:
func GetRoutes(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json")

	routes, err := data.GetRoutes()
	if err != nil {
		sendError(w, err, http.StatusInternalServerError, "Failed to get routes.")
		return
	}

	routesJSON, err := json.Marshal(routes)
	if err != nil {
		sendError(w, err, http.StatusInternalServerError, "Failed to marshal object.")
		return
	}

	w.WriteHeader(http.StatusOK)
	w.Write(routesJSON)
}

// GetRouteByID Returns a route by id, HTTP GET - /api/v1/routes/{id}
// swagger:route GET /api/v1/routes/{routeId} routes getRouteByID
//		 Returns a route by id
//
//     Consumes:
//     - application/json
//
//     Produces:
//     - application/json
//
//     Schemes: http, https
//
//     Responses:
//       200:
//       401:
//			 500:
func GetRouteByID(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json")

	vars := mux.Vars(r)
	routeID := vars["id"]

	route, err := data.GetRouteByID(routeID)
	if err != nil {
		sendError(w, err, http.StatusInternalServerError, "Failed to get route.")
		return
	}

	routeJSON, err := json.Marshal(route)
	if err != nil {
		sendError(w, err, http.StatusInternalServerError, "Failed to marshal object.")
		return
	}

	w.WriteHeader(http.StatusOK)
	w.Write(routeJSON)
}

// CreateRoute Creates a command alias, HTTP GET - /api/v1/routes
// swagger:route POST /api/v1/routes routes createRoute
//		 Creates a route
//
//     Consumes:
//     - application/json
//
//     Produces:
//     - application/json
//
//     Schemes: http, https
//
//     Responses:
//       200:
//       401:
//			 500:
func CreateRoute(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json")

	var route models.Route
	err := json.NewDecoder(r.Body).Decode(&route)
	if err != nil {
		sendError(w, err, http.StatusInternalServerError, "Invalid route format.")
		return
	}

	route, err := data.CreateRoute(route)
	if err != nil {
		sendError(w, err, http.StatusInternalServerError, "Failed to create route.")
		return
	}

	routeJSON, err := json.Marshal(route)
	if err != nil {
		sendError(w, err, http.StatusInternalServerError, "Failed to marshal object.")
		return
	}

	w.WriteHeader(http.StatusOK)
	w.Write(routeJSON)
}

// UpdateRouteByID Updates a route, HTTP GET - /api/v1/routes/{id}
// swagger:route PUT /api/v1/routes/{routeId} routes updateRouteByID
//		 Updates a route
//
//     Consumes:
//     - application/json
//
//     Produces:
//     - application/json
//
//     Schemes: http, https
//
//     Responses:
//       200:
//       401:
//			 500:
func UpdateRouteByID(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json")

	var route models.Route
	err := json.NewDecoder(r.Body).Decode(&route)
	if err != nil {
		sendError(w, err, http.StatusInternalServerError, "Invalid route format.")
		return
	}

	route, err = data.UpdateAliasByID(route)
	if err != nil {
		sendError(w, err, http.StatusInternalServerError, "Failed to update route.")
		return
	}

	routeJSON, err := json.Marshal(route)
	if err != nil {
		sendError(w, err, http.StatusInternalServerError, "Failed to marshal object.")
		return
	}

	w.WriteHeader(http.StatusOK)
	w.Write(routeJSON)
}

// DeleteRouteByID Deletes a route, HTTP DELETE - /api/v1/routes/{id}
// swagger:route DELETE /api/v1/routes/{routeId} routes deleteRouteByID
//		 Deletes a route
//
//     Consumes:
//     - application/json
//
//     Produces:
//     - application/json
//
//     Schemes: http, https
//
//     Responses:
//       200:
//       401:
//			 500:
func DeleteRouteByID(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "application/json")

	vars := mux.Vars(r)
	routeID := vars["id"]

	err := data.DeleteRouteByID(routeID)
	if err != nil {
		sendError(w, err, http.StatusInternalServerError, "Failed to delete route.")
		return
	}

	respJSON, err := json.Marshal("Successfully deleted route")
	if err != nil {
		sendError(w, err, http.StatusInternalServerError, "Failed to marshal object.")
		return
	}

	w.WriteHeader(http.StatusOK)
	w.Write(respJSON)
}

//RouteID Struct for routeID parameter
//swagger:parameters getRouteByID updateRouteByID deleteRouteByID
type RouteID struct {

	// in: path
	RouteID string `json:"routeId"`
}
{'fraction_non_alphanumeric': 0.14942660550458717, 'fraction_numerical': 0.011353211009174313, 'mean_word_length': 2.9551020408163264, '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': '7640852', 'n_tokens_mistral': 3160, 'n_tokens_neox': 3012, 'n_words': 701}