added team view to season_leagues
This commit is contained in:
24
internal/validation/boolfield.go
Normal file
24
internal/validation/boolfield.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package validation
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type BoolField struct {
|
||||
FieldBase
|
||||
Value bool
|
||||
}
|
||||
|
||||
func newBoolField(key string, g Getter) *BoolField {
|
||||
raw := g.Get(key)
|
||||
val, err := strconv.ParseBool(raw)
|
||||
if err != nil {
|
||||
g.AddCheck(newFailedCheck("Invalid boolean value",
|
||||
fmt.Sprintf("Field %s requires a boolean value, %s given", key, raw)))
|
||||
}
|
||||
return &BoolField{
|
||||
newField(key, g),
|
||||
val,
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,18 @@ func (f *FormGetter) Get(key string) string {
|
||||
}
|
||||
|
||||
func (f *FormGetter) GetList(key string) []string {
|
||||
return strings.Split(f.Get(key), ",")
|
||||
if f.r.Form == nil {
|
||||
return nil
|
||||
}
|
||||
values, ok := f.r.Form[key]
|
||||
if !ok || len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
// Support both comma-separated single values and multiple form fields
|
||||
if len(values) == 1 {
|
||||
return strings.Split(values[0], ",")
|
||||
}
|
||||
return values
|
||||
}
|
||||
|
||||
func (f *FormGetter) GetMaps(key string) []map[string]string {
|
||||
@@ -72,6 +83,10 @@ func (f *FormGetter) Int(key string) *IntField {
|
||||
return newIntField(key, f)
|
||||
}
|
||||
|
||||
func (f *FormGetter) Bool(key string) *BoolField {
|
||||
return newBoolField(key, f)
|
||||
}
|
||||
|
||||
func (f *FormGetter) Time(key string, format *timefmt.Format) *TimeField {
|
||||
return newTimeField(key, format, f)
|
||||
}
|
||||
|
||||
@@ -46,6 +46,10 @@ func (q *QueryGetter) Int(key string) *IntField {
|
||||
return newIntField(key, q)
|
||||
}
|
||||
|
||||
func (q *QueryGetter) Bool(key string) *BoolField {
|
||||
return newBoolField(key, q)
|
||||
}
|
||||
|
||||
func (q *QueryGetter) Time(key string, format *timefmt.Format) *TimeField {
|
||||
return newTimeField(key, format, q)
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ type Getter interface {
|
||||
AddCheck(check *ValidationRule)
|
||||
String(key string) *StringField
|
||||
Int(key string) *IntField
|
||||
Bool(key string) *BoolField
|
||||
Time(key string, format *timefmt.Format) *TimeField
|
||||
StringList(key string) *StringList
|
||||
IntList(key string) *IntList
|
||||
|
||||
Reference in New Issue
Block a user