fixed some typos
This commit is contained in:
parent
ebeb36921a
commit
c726cb76f7
5 changed files with 30 additions and 16 deletions
|
|
@ -38,16 +38,16 @@ func InitStripe(secret string) { stripe.Key = secret }
|
|||
func parseFloat(input string) (int, error) {
|
||||
val, err := strconv.ParseFloat(input, 64)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("Invalid float format")
|
||||
return 0, fmt.Errorf("Nieprawidłowa wartość")
|
||||
}
|
||||
|
||||
if val < 0 || val > 100 {
|
||||
return 0, fmt.Errorf("Value must be between 0 and 100")
|
||||
return 0, fmt.Errorf("Wartość musi być między 0 a 100")
|
||||
}
|
||||
|
||||
doubled := val * 2
|
||||
if math.Abs(doubled-math.Round(doubled)) > 1e-9 {
|
||||
return 0, fmt.Errorf("Value must be a multiple of 0.5")
|
||||
return 0, fmt.Errorf("Wartość musi być wielokrotnością 0,5")
|
||||
}
|
||||
|
||||
return int(math.Round(val * 100)), nil
|
||||
|
|
@ -66,23 +66,32 @@ func parseOrder(r *http.Request) (order, error) {
|
|||
var errorList []error
|
||||
o.name = strings.TrimSpace(r.PostFormValue("name"))
|
||||
if !validName(o.name) {
|
||||
errorList = append(errorList, fmt.Errorf("Invalid name"))
|
||||
errorList = append(errorList, fmt.Errorf("Podaj imię i nazwisko"))
|
||||
}
|
||||
o.phone, err = parsePhone(r.PostFormValue("phone"))
|
||||
if err != nil {
|
||||
errorList = append(errorList, err)
|
||||
}
|
||||
total := 0
|
||||
for _, item := range data.Swieta {
|
||||
count, err := parseFloat(r.PostFormValue(item.Id))
|
||||
if err != nil {
|
||||
errorList = append(errorList, fmt.Errorf("Can't parse the count for %v: %v", item.Name, err))
|
||||
errorList = append(errorList, fmt.Errorf("Nieprawidłowa ilość dla: %v", item.Name))
|
||||
continue
|
||||
}
|
||||
if count%10 == 5 && !item.Halveable {
|
||||
errorList = append(errorList, fmt.Errorf("This item can't be bought in fractions %v", item.Name))
|
||||
errorList = append(errorList, fmt.Errorf("Produktu %v nie można zamówić w ułamkowej ilości", item.Name))
|
||||
continue
|
||||
}
|
||||
o.items = append(o.items, listItem{item.Id, count})
|
||||
price, err := strconv.Atoi(item.Price)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
total += count * price
|
||||
}
|
||||
if total < 5000 {
|
||||
errorList = append(errorList, fmt.Errorf("Minimalna wartość zamówienia wynosi 50zł"))
|
||||
}
|
||||
return o, errors.Join(errorList...)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,11 +46,11 @@ func parsePhone(input string) (string, error) {
|
|||
}
|
||||
|
||||
if len(cleaned) != 9 {
|
||||
return "", fmt.Errorf("invalid length: expected 9 digits, got %d", len(cleaned))
|
||||
return "", fmt.Errorf("Numer telefonu musi mieć 9 cyfr")
|
||||
}
|
||||
|
||||
if !isValidPolishMobile(cleaned) {
|
||||
return "", fmt.Errorf("invalid mobile prefix: %s does not match Polish mobile allocations", cleaned[:2])
|
||||
return "", fmt.Errorf("Nieprawidłowy numer telefonu — podaj polski numer komórkowy")
|
||||
}
|
||||
|
||||
return cleaned, nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue