Skip to content

Commit

Permalink
feat: add ServiceFilter query (#130)
Browse files Browse the repository at this point in the history
* feat: add Service Filter Query

* feat: add Service Filter Query

updates

* feat: add Service Filter

Update

* feat: add Service Filter

Update generate.go

* wip

* Adding ServiceFilter

* feat: add Service Filter Query

* remove pagination

* chore(refactoring): made UniqueUserID plural

* test: switched LOCAL_TEST_DB to true

---------

Co-authored-by: dustindemmerle <[email protected]>
Co-authored-by: David Rochow <[email protected]>
  • Loading branch information
3 people authored Aug 12, 2024
1 parent 547d0b8 commit 3e80ebe
Show file tree
Hide file tree
Showing 35 changed files with 2,701 additions and 42 deletions.
10 changes: 10 additions & 0 deletions internal/api/graphql/gqlgen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,14 @@ models:
supportGroups:
resolver: true
services:
resolver: true
ServiceFilterValue:
fields:
serviceName:
resolver: true
uniqueUserId:
resolver: true
userName:
resolver: true
supportGroupName:
resolver: true
10 changes: 9 additions & 1 deletion internal/api/graphql/graph/baseResolver/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@ package baseResolver
import (
"context"
"fmt"
"strconv"

"github.com/99designs/gqlgen/graphql"
"github.com/samber/lo"
"github.wdf.sap.corp/cc/heureka/internal/entity"
"strconv"
)

var (
FilterServiceName string = "Service Name"
FilterSupportGroupName string = "SupportGroup Name"
FilterUserName string = "User Name"
FilterUniqueUserID string = "Unique User ID"
)

type ResolverError struct {
Expand Down
38 changes: 38 additions & 0 deletions internal/api/graphql/graph/baseResolver/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,41 @@ func ServiceBaseResolver(app app.Heureka, ctx context.Context, filter *model.Ser
return &connection, nil

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

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

f := &entity.ServiceFilter{
Paginated: entity.Paginated{},
SupportGroupName: filter.SupportGroupName,
Name: filter.ServiceName,
OwnerName: filter.UserName,
}

opt := GetListOptions(requestedFields)

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

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

var pointerNames []*string

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

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

return &filterItem, nil
}
50 changes: 50 additions & 0 deletions internal/api/graphql/graph/baseResolver/support_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.wdf.sap.corp/cc/heureka/internal/api/graphql/graph/model"
"github.wdf.sap.corp/cc/heureka/internal/app"
"github.wdf.sap.corp/cc/heureka/internal/entity"
"github.wdf.sap.corp/cc/heureka/internal/util"
)

func SupportGroupBaseResolver(app app.Heureka, ctx context.Context, filter *model.SupportGroupFilter, first *int, after *string, parent *model.NodeParent) (*model.SupportGroupConnection, error) {
Expand Down Expand Up @@ -85,3 +86,52 @@ func SupportGroupBaseResolver(app app.Heureka, ctx context.Context, filter *mode

return &connection, nil
}

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

if filter == nil {
filter = &model.SupportGroupFilter{}
}
var userIds []*int64

if len(filter.UserIds) > 0 {
userIds, err = util.ConvertStrToIntSlice(filter.UserIds)

if err != nil {
logrus.WithField("Filter", filter).Error("SupportGroupNameBaseResolver: Error while parsing 'UserIds'")
return nil, NewResolverError("SupportGroupNameBaseResolver", "Bad Request - unable to parse 'UserIds'")
}
}

f := &entity.SupportGroupFilter{
Paginated: entity.Paginated{},
UserId: userIds,
Name: filter.SupportGroupName,
}

opt := GetListOptions(requestedFields)

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

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

var pointerNames []*string

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

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

return &filterItem, nil
}
76 changes: 76 additions & 0 deletions internal/api/graphql/graph/baseResolver/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func UserBaseResolver(app app.Heureka, ctx context.Context, filter *model.UserFi
SupportGroupId: supportGroupId,
ServiceId: serviceId,
Name: filter.UserName,
UniqueUserID: filter.UniqueUserID,
}

opt := GetListOptions(requestedFields)
Expand Down Expand Up @@ -125,3 +126,78 @@ func UserBaseResolver(app app.Heureka, ctx context.Context, filter *model.UserFi

return &connection, nil
}
func UserNameBaseResolver(app app.Heureka, ctx context.Context, filter *model.UserFilter) (*model.FilterItem, error) {
requestedFields := GetPreloads(ctx)
logrus.WithFields(logrus.Fields{
"requestedFields": requestedFields,
}).Debug("Called UserNameBaseResolver")

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

f := &entity.UserFilter{
Paginated: entity.Paginated{},
Name: filter.UserName,
UniqueUserID: filter.UniqueUserID,
}

opt := GetListOptions(requestedFields)

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

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

var pointerNames []*string

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

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

return &filterItem, nil
}

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

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

f := &entity.UserFilter{
Paginated: entity.Paginated{},
UniqueUserID: filter.UniqueUserID,
Name: filter.UserName,
}

opt := GetListOptions(requestedFields)

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

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

var pointerNames []*string

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

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

return &filterItem, nil
}
Loading

0 comments on commit 3e80ebe

Please sign in to comment.