Compare commits

...

3 Commits
v3.0.1 ... main

Author SHA1 Message Date
Luca 8bbec0cb64 Use internal category name
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details
2023-03-07 15:40:14 +01:00
Luca 1ff0f6e073 Fix incompatible types
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details
2023-03-06 00:44:17 +01:00
Luca a61e057cfb Calculate per-category sub-totals
continuous-integration/drone/push Build is failing Details
2023-03-06 00:42:51 +01:00
1 changed files with 14 additions and 9 deletions

View File

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