<commit_before>package shoppingapi

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

	"github.com/PaluMacil/dwn/dwn"
	"github.com/PaluMacil/dwn/sections/shopping"
)

// api/shopping/item
func (rt *ShoppingRoute) handleItem() {
	if rt.API().Current == nil {
		http.Error(rt.W, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
	}
	if spouse, err := rt.API().Current.Is(dwn.BuiltInGroupSpouse); err != nil {
		rt.API().ServeInternalServerError(err)
		return
	} else if !spouse {
		http.Error(rt.W, http.StatusText(http.StatusForbidden), http.StatusForbidden)
		return
	}
	switch rt.R.Method {
	case "POST":
		var item shopping.Item
		err := json.NewDecoder(rt.R.Body).Decode(&item)
		if err != nil {
			rt.API().ServeBadRequest()
			return
		}
		err = rt.Db.Shopping.Items.Set(item)
		if err != nil {
			rt.API().ServeInternalServerError(err)
			return
		}
	case "DELETE":
		var item shopping.Item
		err := json.NewDecoder(rt.R.Body).Decode(&item)
		if err != nil {
			rt.API().ServeInternalServerError(err)
			return
		}
		err = rt.Db.Shopping.Items.Delete(item.Name)
		if err != nil {
			rt.API().ServeInternalServerError(err)
			return
		}
		rt.W.WriteHeader(http.StatusNoContent)
	default:
		rt.API().ServeMethodNotAllowed()
		return
	}
}<commit_msg>delete doesn't have a body<commit_after>package shoppingapi

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

	"github.com/PaluMacil/dwn/dwn"
	"github.com/PaluMacil/dwn/sections/shopping"
)

// api/shopping/item
func (rt *ShoppingRoute) handleItem() {
	if rt.API().Current == nil {
		http.Error(rt.W, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
	}
	if spouse, err := rt.API().Current.Is(dwn.BuiltInGroupSpouse); err != nil {
		rt.API().ServeInternalServerError(err)
		return
	} else if !spouse {
		http.Error(rt.W, http.StatusText(http.StatusForbidden), http.StatusForbidden)
		return
	}
	switch rt.R.Method {
	case "POST":
		var item shopping.Item
		err := json.NewDecoder(rt.R.Body).Decode(&item)
		if err != nil {
			rt.API().ServeBadRequest()
			return
		}
		err = rt.Db.Shopping.Items.Set(item)
		if err != nil {
			rt.API().ServeInternalServerError(err)
			return
		}
	case "DELETE":
		qry, err := url.QueryUnescape(rt.R.URL.Query().Get("name"))
		if len(qry) == 0 || err != nil {
			rt.API().ServeBadRequest()
			return
		}
		err = rt.Db.Shopping.Items.Delete(qry)
		if err != nil {
			rt.API().ServeInternalServerError(err)
			return
		}
		rt.W.WriteHeader(http.StatusNoContent)
	default:
		rt.API().ServeMethodNotAllowed()
		return
	}
}
{'fraction_non_alphanumeric': 0.15625, 'fraction_numerical': 0.00039556962025316455, 'mean_word_length': 3.7988614800759013, 'pattern_counts': {'":': 4, '<': 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': '4610337', 'n_tokens_mistral': 1039, 'n_tokens_neox': 968, 'n_words': 159}