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

feat!: Issue filters #142

Merged
merged 11 commits into from
Aug 15, 2024
2 changes: 1 addition & 1 deletion .test.env
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ DB_SCHEMA=internal/database/mariadb/init/schema.sql

DB_CONTAINER_IMAGE=mariadb:latest

DOCKER_IMAGE_REGISTRY=hub.docker.com
DOCKER_IMAGE_REGISTRY=index.docker.io

DOCKER_CREDENTIAL_STORE=docker-credential-desktop

Expand Down
16 changes: 16 additions & 0 deletions internal/api/graphql/gqlgen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,22 @@ models:
resolver: true
services:
resolver: true
IssueMatchFilterValue:
fields:
status:
resolver: false
severity:
resolver: false
issueType:
resolver: false
primaryName:
resolver: true
affectedService:
resolver: true
componentName:
resolver: true
supportGroupName:
resolver: true
ServiceFilterValue:
fields:
serviceName:
Expand Down
27 changes: 23 additions & 4 deletions internal/api/graphql/graph/baseResolver/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,29 @@ import (
)

var (
FilterServiceName string = "Service Name"
FilterSupportGroupName string = "SupportGroup Name"
FilterUserName string = "User Name"
FilterUniqueUserID string = "Unique User ID"
FilterDisplayServiceName string = "Service Name"
FilterDisplaySupportGroupName string = "Support Group Name"
FilterDisplayUserName string = "User Name"
FilterDisplayUniqueUserId string = "Unique User ID"
FilterDisplayComponentName string = "Component Name"
FilterDisplayIssueType string = "Issue Type"
FilterDisplayIssueMatchStatus string = "Issue Match Status"
FilterDisplayIssuePrimaryName string = "Issue Name"
FilterDisplayIssueSeverity string = "Severity"

ServiceFilterServiceName string = "serviceName"
ServiceFilterUniqueUserId string = "uniqueUserId"
ServiceFilterType string = "type"
ServiceFilterUserName string = "userName"
ServiceFilterSupportGroupName string = "supportGroupName"

IssueMatchFilterPrimaryName string = "primaryName"
IssueMatchFilterComponentName string = "componentName"
IssueMatchFilterIssueType string = "issueType"
IssueMatchFilterStatus string = "status"
IssueMatchFilterSeverity string = "severity"
IssueMatchFilterAffectedService string = "affectedService"
IssueMatchFilterSupportGroupName string = "supportGroupName"
)

type ResolverError struct {
Expand Down
37 changes: 37 additions & 0 deletions internal/api/graphql/graph/baseResolver/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,40 @@ func ComponentBaseResolver(app app.Heureka, ctx context.Context, filter *model.C
return &connection, nil

}

func ComponentNameBaseResolver(app app.Heureka, ctx context.Context, filter *model.ComponentFilter) (*model.FilterItem, error) {
requestedFields := GetPreloads(ctx)
logrus.WithFields(logrus.Fields{
"requestedFields": requestedFields,
}).Debug("Called ComponentNameBaseResolver")

if filter == nil {
filter = &model.ComponentFilter{}
}

f := &entity.ComponentFilter{
Paginated: entity.Paginated{},
Name: filter.ComponentName,
}

opt := GetListOptions(requestedFields)

names, err := app.ListComponentNames(f, opt)

if err != nil {
return nil, NewResolverError("ComponentNameBaseReolver", err.Error())
}

var pointerNames []*string

for _, name := range names {
pointerNames = append(pointerNames, &name)
}

filterItem := model.FilterItem{
DisplayName: &FilterDisplayComponentName,
Values: pointerNames,
}

return &filterItem, nil
}
43 changes: 43 additions & 0 deletions internal/api/graphql/graph/baseResolver/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,46 @@ func IssueBaseResolver(app app.Heureka, ctx context.Context, filter *model.Issue

return &connection, nil
}

func IssueNameBaseResolver(app app.Heureka, ctx context.Context, filter *model.IssueFilter) (*model.FilterItem, error) {
requestedFields := GetPreloads(ctx)
logrus.WithFields(logrus.Fields{
"requestedFields": requestedFields,
}).Debug("Called IssueNameBaseResolver")

if filter == nil {
filter = &model.IssueFilter{}
}

f := &entity.IssueFilter{
Paginated: entity.Paginated{},
ServiceName: filter.AffectedService,
PrimaryName: filter.PrimaryName,
Type: lo.Map(filter.IssueType, func(item *model.IssueTypes, _ int) *string { return pointer.String(item.String()) }),
Search: filter.Search,
IssueMatchStatus: nil, //@todo Implement
IssueMatchDiscoveryDate: nil, //@todo Implement
IssueMatchTargetRemediationDate: nil, //@todo Implement
}

opt := GetListOptions(requestedFields)

names, err := app.ListIssueNames(f, opt)

if err != nil {
return nil, NewResolverError("IssueNamesBaseReolver", err.Error())
}

var pointerNames []*string

for _, name := range names {
pointerNames = append(pointerNames, &name)
}

filterItem := model.FilterItem{
DisplayName: &FilterDisplayIssuePrimaryName,
Values: pointerNames,
}

return &filterItem, nil
}
16 changes: 15 additions & 1 deletion internal/api/graphql/graph/baseResolver/issue_match.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,18 @@ func IssueMatchBaseResolver(app app.Heureka, ctx context.Context, filter *model.
filter = &model.IssueMatchFilter{}
}

issue_match_ids := []*int64{}
for _, issue_match_id := range filter.ID {
filterById, err := ParseCursor(issue_match_id)
if err != nil {
logrus.WithField("filter", filter).Error("IssueMatchBaseResolver: Error while parsing filter value 'id'")
return nil, NewResolverError("IssueMatchBaseResolver", "Bad Request - unable to parse filter, the value of the filter ID is invalid")
}
issue_match_ids = append(issue_match_ids, filterById)
}

f := &entity.IssueMatchFilter{
Id: issue_match_ids,
Paginated: entity.Paginated{First: first, After: afterId},
AffectedServiceName: filter.AffectedService,
Status: lo.Map(filter.Status, func(item *model.IssueMatchStatusValues, _ int) *string { return pointer.String(item.String()) }),
Expand All @@ -101,6 +112,10 @@ func IssueMatchBaseResolver(app app.Heureka, ctx context.Context, filter *model.
IssueId: issueId,
EvidenceId: eId,
ComponentInstanceId: ciId,
Search: filter.Search,
ComponentName: filter.ComponentName,
PrimaryName: filter.PrimaryName,
IssueType: lo.Map(filter.IssueType, func(item *model.IssueTypes, _ int) *string { return pointer.String(item.String()) }),
}

opt := GetListOptions(requestedFields)
Expand Down Expand Up @@ -133,5 +148,4 @@ func IssueMatchBaseResolver(app app.Heureka, ctx context.Context, filter *model.
}

return &connection, nil

}
4 changes: 2 additions & 2 deletions internal/api/graphql/graph/baseResolver/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ func ServiceNameBaseResolver(app app.Heureka, ctx context.Context, filter *model
}

filterItem := model.FilterItem{
FilterName: &FilterServiceName,
Values: pointerNames,
DisplayName: &FilterDisplayServiceName,
Values: pointerNames,
}

return &filterItem, nil
Expand Down
4 changes: 2 additions & 2 deletions internal/api/graphql/graph/baseResolver/support_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ func SupportGroupNameBaseResolver(app app.Heureka, ctx context.Context, filter *
}

filterItem := model.FilterItem{
FilterName: &FilterSupportGroupName,
Values: pointerNames,
DisplayName: &FilterDisplaySupportGroupName,
Values: pointerNames,
}

return &filterItem, nil
Expand Down
8 changes: 4 additions & 4 deletions internal/api/graphql/graph/baseResolver/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ func UserNameBaseResolver(app app.Heureka, ctx context.Context, filter *model.Us
}

filterItem := model.FilterItem{
FilterName: &FilterUserName,
Values: pointerNames,
DisplayName: &FilterDisplayUserName,
Values: pointerNames,
}

return &filterItem, nil
Expand Down Expand Up @@ -195,8 +195,8 @@ func UniqueUserIDBaseResolver(app app.Heureka, ctx context.Context, filter *mode
}

filterItem := model.FilterItem{
FilterName: &FilterUniqueUserID,
Values: pointerNames,
DisplayName: &FilterDisplayUniqueUserId,
Values: pointerNames,
}

return &filterItem, nil
Expand Down
Loading
Loading