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: add ServiceFilter query #130

Merged
merged 11 commits into from
Aug 12, 2024
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.ListUniqueUserID(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
Loading