<commit_before>package controllers

import (
	"fmt"
	"net/http"
	"encoding/json"
	"github.com/gorilla/mux"
	"github.com/vonji/vonji-api/models"
	"github.com/vonji/vonji-api/api"
)

func GetResponse(w http.ResponseWriter, r *http.Request) {
	ctx := api.GetContext()

	responses := []models.Response{}
	ctx.Db.Find(&responses)

	for i, request := range responses {
		ctx.Db.Model(&request).Related(&responses[i].User)
	}

	json.NewEncoder(w).Encode(responses)
}

func GetResponseById(w http.ResponseWriter, r *http.Request) {
	ctx := api.GetContext()
	responses := models.Response{}

	id, err := parseUint(mux.Vars(r)["id"])

	if err != nil {
		http.Error(w, "Parameter ID is not an unsigned integer", http.StatusBadRequest)
		return
	}

	ctx.Db.First(&responses, id)
	ctx.Db.Model(&responses).Related(&responses.User)

	if responses.ID == 0 {
		http.Error(w, fmt.Sprintf("No request with ID %d found", id), http.StatusNotFound)
		return
	}

	json.NewEncoder(w).Encode(responses)
}

func CreateResponse(w http.ResponseWriter, r *http.Request) {
	response := models.Response{}
	ctx := api.GetContext()

	if err := json.NewDecoder(r.Body).Decode(&response); err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}

	ctx.Db.Create(&response)
}

func UpdateResponse(w http.ResponseWriter, r *http.Request) {
	response := models.Response{}
	ctx := api.GetContext()

	if err := json.NewDecoder(r.Body).Decode(&response); err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}

	ctx.Db.Save(&response)
}

func DeleteResponse(w http.ResponseWriter, r *http.Request) {
	response := models.Response{}
	ctx := api.GetContext()

	id, err := parseUint(mux.Vars(r)["id"])

	if err != nil {
		http.Error(w, "Parameter ID is not an unsigned integer", http.StatusBadRequest)
		return
	}

	response.ID = id

	ctx.Db.Delete(&response)
}

<commit_msg>Fix typo in responses<commit_after>package controllers

import (
	"fmt"
	"net/http"
	"encoding/json"
	"github.com/gorilla/mux"
	"github.com/vonji/vonji-api/models"
	"github.com/vonji/vonji-api/api"
)

func GetResponse(w http.ResponseWriter, r *http.Request) {
	ctx := api.GetContext()

	responses := []models.Response{}
	ctx.Db.Find(&responses)

	for i, request := range responses {
		ctx.Db.Model(&request).Related(&responses[i].User)
	}

	json.NewEncoder(w).Encode(responses)
}

func GetResponseById(w http.ResponseWriter, r *http.Request) {
	ctx := api.GetContext()
	response := models.Response{}

	id, err := parseUint(mux.Vars(r)["id"])

	if err != nil {
		http.Error(w, "Parameter ID is not an unsigned integer", http.StatusBadRequest)
		return
	}

	ctx.Db.First(&response, id)
	ctx.Db.Model(&response).Related(&response.User)


	if response.ID == 0 {
		http.Error(w, fmt.Sprintf("No request with ID %d found", id), http.StatusNotFound)
		return
	}

	json.NewEncoder(w).Encode(response)
}

func CreateResponse(w http.ResponseWriter, r *http.Request) {
	response := models.Response{}
	ctx := api.GetContext()

	if err := json.NewDecoder(r.Body).Decode(&response); err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}

	ctx.Db.Create(&response)
}

func UpdateResponse(w http.ResponseWriter, r *http.Request) {
	response := models.Response{}
	ctx := api.GetContext()

	if err := json.NewDecoder(r.Body).Decode(&response); err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}

	ctx.Db.Save(&response)
}

func DeleteResponse(w http.ResponseWriter, r *http.Request) {
	response := models.Response{}
	ctx := api.GetContext()

	id, err := parseUint(mux.Vars(r)["id"])

	if err != nil {
		http.Error(w, "Parameter ID is not an unsigned integer", http.StatusBadRequest)
		return
	}

	response.ID = id

	ctx.Db.Delete(&response)
}


{'fraction_non_alphanumeric': 0.1627969041900187, 'fraction_numerical': 0.0005337603416066186, 'mean_word_length': 4.424023154848046, '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': '4404061', 'n_tokens_mistral': 1387, 'n_tokens_neox': 1318, 'n_words': 271}