Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Case insensitive matching of field names #337

Merged
merged 21 commits into from
Aug 5, 2022

Conversation

ychen-bloxer
Copy link
Contributor

@ychen-bloxer ychen-bloxer commented Jul 22, 2022

there is an issue returning the values for an object when requesting the list of DNS Server Groups (API object auth_nsg) via API when using the fields.

When there is no specific filter/tag applied in the query, everything looks good and the complete data is displayed.

@chinmayb
Copy link
Contributor

Please give some more details of the fix and please avoid using internal tickets.

gorm/fields.go Outdated
if !ok {
fmt.Printf("===> no field found")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use log package

@ychen-bloxer ychen-bloxer changed the title Atlas 13969 Case insensitive search for objects in the GORM layer Jul 27, 2022
@daniel-garcia daniel-garcia changed the title Case insensitive search for objects in the GORM layer Case insensitive matching of field names Jul 29, 2022
@ychen-bloxer ychen-bloxer marked this pull request as draft August 1, 2022 16:00
Copy link
Contributor

@brocwoodworthIBLX brocwoodworthIBLX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couple of minor things and a question to be addressed

gorm/fields.go Outdated
@@ -3,37 +3,39 @@ package gorm
import (
"context"
"fmt"
"github.com/infobloxopen/atlas-app-toolkit/util"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please revert the change in import order. usually you can run go fmt ./... in the parent directory and it will sort these for you

gorm/fields.go Outdated
sf, ok := objType.FieldByName(util.Camel(f.GetName()))
func handlePreloads(f *query.Field, objType reflect.Type, ignoreCase ...bool) ([]string, error) {
queryFieldName := f.GetName()
fmt.Printf("Query name = %v\n", queryFieldName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use log package here instead of fmt

gorm/fields.go Outdated

var sf reflect.StructField
var ok bool
if len(ignoreCase) > 0 && ignoreCase[0] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe I'm missing something but why is ignoreCase a ...bool instead of just a plain old bool?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an "optional" parameter for backward compatibility.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok that makes sense. if that's the case then make sure that there is a unti test for ignoreCase being false, and one for there being no ignoreCase value at all

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there are. In test file, the function has been called as followed
FieldSelectionStringToGorm(context.Background(), test.fs, &Model{}) // no "ignoreCase" = false
FieldSelectionStringToGorm(context.Background(), test.fs, &Model{}, true)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it might be nice to have at least one FieldSelectionStringToGorm(context.Background(), test.fs, &Model{}, false) just for completion's sake

Copy link
Contributor

@brocwoodworthIBLX brocwoodworthIBLX left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ychen-bloxer ychen-bloxer marked this pull request as ready for review August 2, 2022 18:32
@ychen-bloxer ychen-bloxer marked this pull request as draft August 2, 2022 19:04
gorm/fields.go Outdated Show resolved Hide resolved
@@ -16,7 +16,7 @@ type SortingCriteriaConverter interface {
}

type FieldSelectionConverter interface {
FieldSelectionToGorm(ctx context.Context, fs *query.FieldSelection, obj interface{}) ([]string, error)
FieldSelectionToGorm(ctx context.Context, fs *query.FieldSelection, obj interface{}, ignoreCase ...bool) ([]string, error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to be a option struct{} not a boolean. consider the meaning is for multiple options.

@ychen-bloxer ychen-bloxer marked this pull request as ready for review August 4, 2022 23:06
Copy link
Contributor

@daniel-garcia daniel-garcia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@ychen-bloxer ychen-bloxer merged commit f5fa79b into infobloxopen:master Aug 5, 2022
@ychen-bloxer ychen-bloxer deleted the atlas-13969 branch August 5, 2022 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants