...

Source file src/edge-infra.dev/pkg/edge/api/graph/resolver/actions_queries.resolvers.go

Documentation: edge-infra.dev/pkg/edge/api/graph/resolver

     1  package resolver
     2  
     3  // This file will be automatically regenerated based on the schema, any resolver implementations
     4  // will be copied through when generating and any unknown code will be moved to the end.
     5  // Code generated by github.com/99designs/gqlgen version v0.17.45
     6  
     7  import (
     8  	"context"
     9  	"time"
    10  
    11  	"edge-infra.dev/pkg/edge/api/graph/model"
    12  	"edge-infra.dev/pkg/edge/api/graph/pagination"
    13  	"edge-infra.dev/pkg/edge/api/middleware"
    14  	"edge-infra.dev/pkg/edge/bsl"
    15  	"github.com/rs/zerolog/log"
    16  )
    17  
    18  // Actions is the resolver for the actions field.
    19  func (r *queryResolver) Actions(ctx context.Context, username *string, bannerEdgeID *string, clusterEdgeID *string, batchID *string, action *string, status *string, cursor *string, count *int) (*model.Actions, error) {
    20  	orgName := bsl.GetOrgShortName(middleware.ForContext(ctx).Organization)
    21  
    22  	tenant, err := r.BannerService.GetBannerTenantInfo(ctx, orgName)
    23  	if err != nil {
    24  		log.Ctx(ctx).Err(err).Msg("failed to get tenantEdgeID")
    25  		return nil, err
    26  	}
    27  	currentCursor, limit := pagination.Parse(cursor, count)
    28  	actions, totalCount, err := r.ActivityService.GetActions(ctx, username, bannerEdgeID, clusterEdgeID, batchID, action, status, tenant.TenantEdgeID, currentCursor.Cursor, limit, currentCursor.Previous)
    29  	if err != nil {
    30  		log.Ctx(ctx).Err(err).Msg("failed to get actions")
    31  		return nil, err
    32  	}
    33  
    34  	ends := currentCursor.Cursor
    35  	previousTime := ""
    36  	if len(actions) > 0 {
    37  		ends = actions[len(actions)-1].Time
    38  	}
    39  	if len(actions) > 0 && currentCursor.Offset != 0 {
    40  		previousTime = actions[0].Time
    41  	}
    42  	endTime, err := time.Parse(time.RFC3339, ends)
    43  	if err != nil {
    44  		log.Ctx(ctx).Err(err).Msg("failed to parse time")
    45  		return nil, err
    46  	}
    47  	pageInfo := pagination.Overall(currentCursor, endTime.Format(time.RFC3339), previousTime, len(actions), totalCount, currentCursor.Offset)
    48  
    49  	return &model.Actions{
    50  		Edges:    actions,
    51  		PageInfo: pageInfo,
    52  	}, nil
    53  }
    54  

View as plain text