Skip to content

Commit

Permalink
fix lint error
Browse files Browse the repository at this point in the history
  • Loading branch information
ktkfree committed Jan 24, 2024
1 parent 577cafb commit f7b3bab
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion internal/filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (f *Filter) Scope(settings *Settings, sch *schema.Schema) (func(*gorm.DB) *
}
if joinName != "" {
if err := tx.Statement.Parse(tx.Statement.Model); err != nil {
tx.AddError(err)
_ = tx.AddError(err)
return tx
}
tx = join(tx, joinName, sch)
Expand Down
6 changes: 3 additions & 3 deletions internal/filter/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func joinScope(relationName string, rel *schema.Relationship, fields []string, b

return func(tx *gorm.DB) *gorm.DB {
if rel.FieldSchema.Table == "" {
tx.AddError(fmt.Errorf("Relation %q is anonymous, could not get table name", relationName))
_ = tx.AddError(fmt.Errorf("Relation %q is anonymous, could not get table name", relationName))
return tx
}
if columns != nil {
Expand Down Expand Up @@ -160,7 +160,7 @@ func join(tx *gorm.DB, joinName string, sch *schema.Schema) *gorm.DB {
}
}
if c, ok := tx.Statement.Clauses["FROM"]; ok {
from := c.Expression.(clause.From)
from, _ := c.Expression.(clause.From)
from.Joins = append(from.Joins, joins...)
c.Expression = from
tx.Statement.Clauses["FROM"] = c
Expand All @@ -171,7 +171,7 @@ func join(tx *gorm.DB, joinName string, sch *schema.Schema) *gorm.DB {

func joinExists(stmt *gorm.Statement, join clause.Join) bool {
if c, ok := stmt.Clauses["FROM"]; ok {
from := c.Expression.(clause.From)
from, _ := c.Expression.(clause.From)
c.Expression = from
for _, j := range from.Joins {
if j.Table == join.Table {
Expand Down
2 changes: 1 addition & 1 deletion internal/filter/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (s *Search) Scope(schema *schema.Schema) func(*gorm.DB) *gorm.DB {

if joinName != "" {
if err := tx.Statement.Parse(tx.Statement.Model); err != nil {
tx.AddError(err)
_ = tx.AddError(err)
return tx
}
tx = join(tx, joinName, schema)
Expand Down
2 changes: 1 addition & 1 deletion internal/filter/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (s *Settings) scopeFields(db *gorm.DB, request *goyave.Request, schema *sch
fields := strings.Split(request.String("fields"), ",")
if hasJoins {
if len(schema.PrimaryFieldDBNames) == 0 {
db.AddError(fmt.Errorf("Could not find primary key. Add `gorm:\"primaryKey\"` to your model"))
_ = db.AddError(fmt.Errorf("Could not find primary key. Add `gorm:\"primaryKey\"` to your model"))
return nil
}
fields = addPrimaryKeys(schema, fields)
Expand Down
2 changes: 1 addition & 1 deletion internal/filter/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (s *Sort) Scope(settings *Settings, schema *schema.Schema) func(*gorm.DB) *
return func(tx *gorm.DB) *gorm.DB {
if joinName != "" {
if err := tx.Statement.Parse(tx.Statement.Model); err != nil {
tx.AddError(err)
_ = tx.AddError(err)
return tx
}
tx = join(tx, joinName, schema)
Expand Down
11 changes: 7 additions & 4 deletions internal/pagination/pagination.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ func (p *Pagination) MakePaginationRequest() {
Or: false,
}

log.Info(helper.ModelToJson(f.Values))

pgFilters = append(pgFilters, &pgFilter)
}

Expand Down Expand Up @@ -202,13 +200,18 @@ func NewPagination(urlParams *url.Values) (*Pagination, error) {
column = arrColumns[1]
}

trimmedStr := strings.Trim(arr[2], "[]")
trimmedStr := strings.Trim(arr[1], "[]")
values := strings.Split(trimmedStr, ",")

op := "$cont"
if len(arr) == 3 {
op = arr[2]
}

pg.Filters = append(pg.Filters, Filter{
Column: helper.ToSnakeCase(strings.Replace(column, "[]", "", -1)),
Relation: releation,
Operator: arr[1],
Operator: op,
Values: values,
})
}
Expand Down

0 comments on commit f7b3bab

Please sign in to comment.