...

Source file src/edge-infra.dev/pkg/edge/api/graph/resolver/channel_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  	"fmt"
    10  
    11  	"edge-infra.dev/pkg/edge/api/apierror"
    12  	"edge-infra.dev/pkg/edge/api/graph/model"
    13  	channelMappers "edge-infra.dev/pkg/edge/api/services/channels"
    14  	"github.com/google/uuid"
    15  )
    16  
    17  // DeleteChannel is the resolver for the deleteChannel field.
    18  func (r *mutationResolver) DeleteChannel(ctx context.Context, channelID uuid.UUID) (bool, error) {
    19  	_, err := r.ChannelService.DeleteChannel(ctx, channelID, false)
    20  	return err == nil, err
    21  }
    22  
    23  // RotateChannelNow is the resolver for the rotateChannelNow field.
    24  func (r *mutationResolver) RotateChannelNow(ctx context.Context, channelID uuid.UUID, bannerEdgeID uuid.UUID) (*model.Channel, error) {
    25  	_, err := r.ChannelService.RotateChannelNow(ctx, bannerEdgeID, channelID)
    26  	if err != nil {
    27  		errorMsg := fmt.Sprintf(apierror.ChannelRotateErrorMsg, channelID)
    28  		return nil, apierror.New(apierror.ChannelRotateError).
    29  			AddGenericErrorExtension(errorMsg, err)
    30  	}
    31  
    32  	newRotatedChannel, err := r.ChannelService.GetChannel(ctx, channelID)
    33  	if err != nil {
    34  		errorMsg := fmt.Sprintf(apierror.GetChannelAPIErrorMsg, channelID)
    35  		return nil, apierror.New(apierror.GetChannelsAPIError).
    36  			AddGenericErrorExtension(errorMsg, err)
    37  	}
    38  
    39  	newChannel := channelMappers.ConvertChannelTypeToModelChannel(newRotatedChannel)
    40  
    41  	return newChannel, nil
    42  }
    43  
    44  // CreateChannel is the resolver for the createChannel field.
    45  func (r *mutationResolver) CreateChannel(ctx context.Context, payload model.ChannelInput) (*model.Channel, error) {
    46  	createChannel := channelMappers.MapChannelInput(payload)
    47  
    48  	channel, err := r.ChannelService.CreateChannel(ctx, createChannel)
    49  
    50  	if err != nil {
    51  		errorMsg := fmt.Sprintf(apierror.CreateChannelAPIErrorMsg, payload.Name)
    52  		return nil, apierror.New(apierror.CreateChannelIAMPolicyError).
    53  			AddGenericErrorExtension(errorMsg, err)
    54  	}
    55  
    56  	createdChannel := channelMappers.ConvertChannelTypeToModelChannel(channel)
    57  
    58  	return createdChannel, nil
    59  }
    60  
    61  // CreateChannelIam is the resolver for the createChannelIAM field.
    62  func (r *mutationResolver) CreateChannelIam(ctx context.Context, channelID uuid.UUID, saEmail string) (*model.ChannelIAMPolicy, error) {
    63  	channelIAMPolicy, err := r.ChannelService.CreateChannelIAM(ctx, channelID, saEmail)
    64  
    65  	if err != nil {
    66  		errorMsg := fmt.Sprintf(apierror.CreateChannelIAMPolicyErrorMessage, saEmail)
    67  		return nil, apierror.New(apierror.CreateChannelIAMPolicyError).
    68  			AddGenericErrorExtension(errorMsg, err)
    69  	}
    70  
    71  	return channelIAMPolicy, nil
    72  }
    73  
    74  // Channels is the resolver for the channels field.
    75  func (r *queryResolver) Channels(ctx context.Context) ([]*model.Channel, error) {
    76  	channels, err := r.ChannelService.GetChannels(ctx)
    77  
    78  	if err != nil {
    79  		return nil, apierror.New(apierror.GetChannelsAPIError).
    80  			AddGenericErrorExtension(apierror.GetChannelsAPIErrorMsg, err)
    81  	}
    82  
    83  	channelModels := channelMappers.MapToChannelModels(channels)
    84  	return channelModels, nil
    85  }
    86  

View as plain text