Exemplo n.º 1
0
 public RoutesController(IIOServiceContext context, IHttpContextAccessor httpContextAccessor, IGoogleDriveService googleDriveService, IVtexAPIService vtexAPIService, IDriveImportRepository driveImportRepository)
 {
     this._context               = context ?? throw new ArgumentNullException(nameof(context));
     this._httpContextAccessor   = httpContextAccessor ?? throw new ArgumentNullException(nameof(httpContextAccessor));
     this._googleDriveService    = googleDriveService ?? throw new ArgumentNullException(nameof(googleDriveService));
     this._vtexAPIService        = vtexAPIService ?? throw new ArgumentNullException(nameof(vtexAPIService));
     this._driveImportRepository = driveImportRepository ?? throw new ArgumentNullException(nameof(driveImportRepository));
 }
Exemplo n.º 2
0
        public Mutation(IGoogleDriveService googleDriveService, IDriveImportRepository driveImportRepository, IVtexAPIService vtexAPIService)
        {
            Name = "Mutation";

            Field <StringGraphType>(
                "importImages",
                resolve: context =>
            {
                return(vtexAPIService.DriveImport());
            });

            Field <BooleanGraphType>(
                "revokeToken",
                arguments: new QueryArguments(
                    new QueryArgument <StringGraphType> {
                Name = "accountName", Description = "Account Name"
            }
                    ),
                resolve: context =>
            {
                bool revoked = googleDriveService.RevokeGoogleAuthorizationToken().Result;
                if (revoked)
                {
                    string accountName = context.GetArgument <string>("accountName");
                    driveImportRepository.SaveFolderIds(null, accountName);
                }

                return(revoked);
            });

            Field <StringGraphType>(
                "googleAuthorize",
                resolve: context =>
            {
                return(googleDriveService.GetGoogleAuthorizationUrl());
            });

            Field <StringGraphType>(
                "createSheet",
                resolve: context =>
            {
                return(googleDriveService.CreateSheet());
            });

            Field <StringGraphType>(
                "processSheet",
                resolve: context =>
            {
                return(vtexAPIService.SheetImport());
            });

            Field <StringGraphType>(
                "addImages",
                resolve: context =>
            {
                return(googleDriveService.ClearAndAddImages());
            });
        }
Exemplo n.º 3
0
        public Query(IGoogleDriveService googleDriveService, IDriveImportRepository driveImportRepository)
        {
            Name = "Query";

            FieldAsync <BooleanGraphType>(
                "haveToken",
                resolve: async context =>
            {
                Token token = await googleDriveService.GetGoogleToken();
                return(token != null && !string.IsNullOrEmpty(token.RefreshToken));
            }
                );

            /// query Reviews($searchTerm: String, $from: Int, $to: Int, $orderBy: String, $status: Boolean)
            FieldAsync <StringGraphType>(
                "getOwnerEmail",
                arguments: new QueryArguments(
                    new QueryArgument <StringGraphType> {
                Name = "accountName", Description = "Account Name"
            }
                    ),
                resolve: async context =>
            {
                string email       = string.Empty;
                string accountName = context.GetArgument <string>("accountName");
                Token token        = await googleDriveService.GetGoogleToken();
                if (token != null)
                {
                    string newFolderId  = string.Empty;
                    FolderIds folderIds = await driveImportRepository.LoadFolderIds(accountName);
                    if (folderIds != null)
                    {
                        newFolderId = folderIds.NewFolderId;
                    }
                    else
                    {
                        newFolderId = await googleDriveService.FindNewFolderId(accountName);
                    }

                    ListFilesResponse listFilesResponse = await googleDriveService.ListFiles();
                    if (listFilesResponse != null)
                    {
                        var owners = listFilesResponse.Files.Where(f => f.Id.Equals(newFolderId)).Select(o => o.Owners.Distinct()).FirstOrDefault();
                        if (owners != null)
                        {
                            email = owners.Select(o => o.EmailAddress).FirstOrDefault();
                        }
                        else
                        {
                            newFolderId = await googleDriveService.FindNewFolderId(accountName);
                            owners      = listFilesResponse.Files.Where(f => f.Id.Equals(newFolderId)).Select(o => o.Owners.Distinct()).FirstOrDefault();
                            if (owners != null)
                            {
                                email = owners.Select(o => o.EmailAddress).FirstOrDefault();
                            }
                        }
                    }
                }

                return(email);
            }
                );

            FieldAsync <StringGraphType>(
                "sheetLink",
                resolve: async context =>
            {
                return(await googleDriveService.GetSheetLink());
            }
                );
        }