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

Mr2011/issue 310/im ordering #438

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

Conversation

MR2011
Copy link
Collaborator

@MR2011 MR2011 commented Jan 9, 2025

This PR implements the ordering for IssueMatch by:

  • Issue PrimaryName
  • ComponentInstance CCRN
  • IssueMatch Rating (not in API yet)
  • IssueMatch Target Remediation Date

Example query can be found in internal/api/graphql/graph/queryCollection/issueMatch/withOrder.graphql

Cursor not yet implemented.

Comment on lines +275 to +298
type Order struct {
By DbColumnName
Direction OrderDirection
}

func CreateOrderMap(order []Order) map[DbColumnName]OrderDirection {
m := map[DbColumnName]OrderDirection{}
for _, o := range order {
m[o.By] = o.Direction
}
return m
}

func CreateOrderString(order []Order) string {
orderStr := ""
for i, o := range order {
if i > 0 {
orderStr = fmt.Sprintf("%s, %s %s", orderStr, o.By, o.Direction)
} else {
orderStr = fmt.Sprintf("%s %s %s", orderStr, o.By, o.Direction)
}
}
return orderStr
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since "common.go" is already full with stuff I'd suggest putting anything Order related into it's own file (as a logical separation).

I still think having in general more (small) files is better than having a "common.go".

Comment on lines +25 to +72
func EncodeCursor(order []Order, opts ...NewCursor) (string, error) {
var cursors cursors
for _, opt := range opts {
err := opt(&cursors)
if err != nil {
fmt.Println("err")
return "", err
}
}

m := CreateOrderMap(order)
for _, f := range cursors.fields {
if orderDirection, ok := m[f.Name]; ok {
f.Order = orderDirection
}
}

var buf bytes.Buffer
encoder := base64.NewEncoder(base64.StdEncoding, &buf)
err := json.NewEncoder(encoder).Encode(cursors.fields)
if err != nil {
return "", err
}
encoder.Close()
return buf.String(), nil
}

func DecodeCursor(cursor string) ([]Field, error) {
decoded, err := base64.StdEncoding.DecodeString(cursor)
if err != nil {
return nil, fmt.Errorf("failed to decode base64 string: %w", err)
}

var fields []Field
if err := json.Unmarshal(decoded, &fields); err != nil {
return nil, fmt.Errorf("failed to unmarshal JSON: %w", err)
}

return fields, nil
}

func WithIssueMatch(im IssueMatch) NewCursor {
return func(cursors *cursors) error {
cursors.fields = append(cursors.fields, Field{Name: IssueMatchId, Value: im.Id, Order: OrderDirectionAsc})
// cursors.fields = append(cursors.fields, Field{Name: IssueMatchRating, Value: im.Rating, Order: OrderDirectionAsc})
return nil
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I couldn't figure out how these 2 functions are used. But I guess the implementions is not complete.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, the Cursor is not fully implemented yet. This code might change once I start the implementation

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.

2 participants