Compare commits

..

No commits in common. "main" and "v3.0.1" have entirely different histories.
main ... v3.0.1

1 changed files with 9 additions and 14 deletions

View File

@ -23,8 +23,6 @@ const (
var adverbs = []string{" Außerdem ", " Zusätzlich ", " Weiterhin ", " Des Weiteren "} var adverbs = []string{" Außerdem ", " Zusätzlich ", " Weiterhin ", " Des Weiteren "}
type categoryBin struct { type categoryBin struct {
Cents uint64
Euros uint64
NumFree uint NumFree uint
NumPaid uint NumPaid uint
} }
@ -79,6 +77,7 @@ func (s Server) orderPlaced(w http.ResponseWriter, r *http.Request) {
Item uint Item uint
Price string Price string
} }
Total string
}{} }{}
err = decoder.Decode(&order) err = decoder.Decode(&order)
@ -112,12 +111,6 @@ func (s Server) orderPlaced(w http.ResponseWriter, r *http.Request) {
category := categories[name] category := categories[name]
if euros > 0 || cents > 0 { if euros > 0 || cents > 0 {
category.Cents += cents
if carry := category.Cents / 100; carry > 0 {
category.Cents -= carry * 100
category.Euros += carry
}
category.Euros += euros
category.NumPaid++ category.NumPaid++
} else { } else {
category.NumFree++ category.NumFree++
@ -161,15 +154,15 @@ func (s Server) orderPlaced(w http.ResponseWriter, r *http.Request) {
preposition = `aus der Kategorie "` preposition = `aus der Kategorie "`
quote = `" ` quote = `" `
} }
if bin.Euros > 0 || bin.Cents > 0 { if totalEuros, totalCents, err := parsePrice(order.Total); err == nil && (totalEuros > 0 || totalCents > 0) {
var adverb, fraction string var adverb, fraction string
if bin.NumPaid > 1 { if bin.NumPaid > 1 {
adverb = "insgesamt " adverb = "insgesamt "
} }
if bin.Cents > 0 { if totalCents > 0 {
fraction = fmt.Sprintf(",%02d", bin.Cents) fraction = fmt.Sprintf(",%02d", totalCents)
} }
total = fmt.Sprint("für ", adverb, bin.Euros, fraction, " Euro ") total = fmt.Sprint("für ", adverb, totalEuros, fraction, " Euro ")
} }
body.WriteString(fmt.Sprint(adverb, verb, free, conjunction, paid, noun, preposition, category, quote, total, "bestellt.")) body.WriteString(fmt.Sprint(adverb, verb, free, conjunction, paid, noun, preposition, category, quote, total, "bestellt."))
@ -222,7 +215,9 @@ func (s Server) fetchCategory(organizer, event string, item uint) string {
decoder = json.NewDecoder(resp.Body) decoder = json.NewDecoder(resp.Body)
itemCategory := struct{ itemCategory := struct{
InternalName string `json:"internal_name"` Name struct{
German string `json:"de-informal"`
}
}{} }{}
err = decoder.Decode(&itemCategory) err = decoder.Decode(&itemCategory)
@ -230,7 +225,7 @@ func (s Server) fetchCategory(organizer, event string, item uint) string {
return "" return ""
} }
return itemCategory.InternalName return itemCategory.Name.German
} }
func parsePrice(price string) (euros uint64, cents uint64, err error) { func parsePrice(price string) (euros uint64, cents uint64, err error) {