Skip to content

Commit

Permalink
change function parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
morphy2k committed May 16, 2020
1 parent 8a9575e commit d3ebd2a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
24 changes: 12 additions & 12 deletions controller/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,23 +163,23 @@ Loop:

switch kind {
case item.KindArmor:
err = filter.AddString(r.URL.Query().Get("type"), "type")
err = filter.AddInt(r.URL.Query().Get("armor.class"), "armor.class")
err = filter.AddString(r.URL.Query().Get("armor.material.name"), "armor.material.name")
err = filter.AddString("type", r.URL.Query().Get("type"))
err = filter.AddInt("armor.class", r.URL.Query().Get("armor.class"))
err = filter.AddString("armor.material.name", r.URL.Query().Get("armor.material.name"))
case item.KindFirearm:
err = filter.AddString(r.URL.Query().Get("type"), "type")
err = filter.AddString(r.URL.Query().Get("class"), "class")
err = filter.AddString(r.URL.Query().Get("caliber"), "caliber")
err = filter.AddString("type", r.URL.Query().Get("type"))
err = filter.AddString("class", r.URL.Query().Get("class"))
err = filter.AddString("caliber", r.URL.Query().Get("caliber"))
case item.KindTacticalrig:
err = filter.AddInt(r.URL.Query().Get("armor.class"), "armor.class")
err = filter.AddString(r.URL.Query().Get("armor.material.name"), "armor.material.name")
err = filter.AddInt("armor.class", r.URL.Query().Get("armor.class"))
err = filter.AddString("armor.material.name", r.URL.Query().Get("armor.material.name"))
case item.KindAmmunition:
err = filter.AddString(r.URL.Query().Get("type"), "type")
err = filter.AddString(r.URL.Query().Get("caliber"), "caliber")
err = filter.AddString("type", r.URL.Query().Get("type"))
err = filter.AddString("caliber", r.URL.Query().Get("caliber"))
case item.KindMagazine:
err = filter.AddString(r.URL.Query().Get("caliber"), "caliber")
err = filter.AddString("caliber", r.URL.Query().Get("caliber"))
case item.KindMedical, item.KindFood, item.KindGrenade, item.KindClothing, item.KindModificationMuzzle, item.KindModificationDevice, item.KindModificationSight, item.KindModificationSightSpecial, item.KindModificationGoggles:
err = filter.AddString(r.URL.Query().Get("type"), "type")
err = filter.AddString("type", r.URL.Query().Get("type"))
}
if err != nil {
s := &Status{}
Expand Down
22 changes: 11 additions & 11 deletions model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,25 @@ func NewResponse(msg string, code int) *Response {
type Filter map[string]interface{}

// AddString adds a string to the given MongoDB field
func (f Filter) AddString(val, path string) error {
func (f Filter) AddString(field, value string) error {
var err error
if val != "" {
f[path], err = url.QueryUnescape(val)
if value != "" {
f[field], err = url.QueryUnescape(value)
}

return err
}

// AddInt adds an integer to the given MongoDB field
func (f Filter) AddInt(val, path string) error {
if val != "" {
func (f Filter) AddInt(field, value string) error {
if value != "" {
var err error
val, err = url.QueryUnescape(val)
value, err = url.QueryUnescape(value)
if err != nil {
return err
}

f[path], err = strconv.ParseInt(val, 10, 64)
f[field], err = strconv.ParseInt(value, 10, 64)
if err != nil {
return err
}
Expand All @@ -90,15 +90,15 @@ func (f Filter) AddInt(val, path string) error {
}

// AddFloat adds a float to the given MongoDB field
func (f Filter) AddFloat(val, path string) error {
if val != "" {
func (f Filter) AddFloat(field, value string) error {
if value != "" {
var err error
val, err = url.QueryUnescape(val)
value, err = url.QueryUnescape(value)
if err != nil {
return err
}

f[path], err = strconv.ParseFloat(val, 64)
f[field], err = strconv.ParseFloat(value, 64)
if err != nil {
return err
}
Expand Down

0 comments on commit d3ebd2a

Please sign in to comment.