Esempio n. 1
0
        public HitMutation(IHitService hitService,
                           IJWTService jWTService,
                           IHeroService heroService,
                           IValidatorService validatorService)
        {
            Name = "Mutation";

            Field <StringGraphType>(
                "createHit",
                arguments: new QueryArguments
            {
                new QueryArgument <NonNullGraphType <StringGraphType> > {
                    Name = "token"
                },
                new QueryArgument <NonNullGraphType <IdGraphType> > {
                    Name = "dragonId"
                }
            },
                resolve: context =>
            {
                var token    = context.GetArgument <string>("token");
                var dragonId = context.GetArgument <int>("dragonId");
                validatorService.ValidateToken(token);

                var heroName = jWTService.GetHeroNameFromToken(token);
                var hero     = heroService.GetHeroByName(heroName);

                hitService.CreateHit(hero, dragonId);

                return(null);
            });
        }
Esempio n. 2
0
        public HeroQuery(IHeroService heroService,
                         IJWTService jWTService,
                         IValidatorService validator)
        {
            Name = "Query";
            Field <ListGraphType <HeroType> >(
                "heroes",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "token"
            },
                    new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "pageNumber"
            },
                    new QueryArgument <StringGraphType> {
                Name = "beginningOfTheName"
            },
                    new QueryArgument <DateTimeGraphType> {
                Name = "before"
            },
                    new QueryArgument <DateTimeGraphType> {
                Name = "after"
            }
                    ),
                resolve: context =>
            {
                var token              = context.GetArgument <string>("token");
                var pageNumber         = context.GetArgument <int>("pageNumber");
                var beginningOfTheName = context.GetArgument <string>("beginningOfTheName", defaultValue: null);
                var before             = context.GetArgument <DateTime?>("before", defaultValue: null);
                var after              = context.GetArgument <DateTime?>("after", defaultValue: null);

                validator.ValidateToken(token);

                var heroes = heroService.GetAllHeroes().Result;

                if (beginningOfTheName != null)
                {
                    heroes = heroService.FilterHeroesByNameAsync(heroes, beginningOfTheName).Result;
                }

                if (before != null)
                {
                    heroes = heroService.FilterHeroesCreatedBeforeAsync(heroes, before.Value).Result;
                }

                if (after != null)
                {
                    heroes = heroService.FilterHeroesCreatedAfterAsync(heroes, after.Value).Result;
                }

                return(heroService.GetPageWithHeroesAsync(heroes, pageNumber));
            });
        }
Esempio n. 3
0
        public DragonMutation(IDragonService dragonService,
                              IValidatorService validator)
        {
            Name = "Mutation";

            Field <IdGraphType>("createDragon",
                                arguments: new QueryArguments
            {
                new QueryArgument <NonNullGraphType <StringGraphType> > {
                    Name = "token"
                }
            },
                                resolve: context =>
            {
                var token = context.GetArgument <string>("token");
                validator.ValidateToken(token);

                return(dragonService.CreateDragonAsync());
            });
        }
Esempio n. 4
0
        public HitQuery(IHitService hitService,
                        IHeroService heroService,
                        IJWTService jWTService,
                        IValidatorService validatorService)
        {
            Name = "Query";
            Field <ListGraphType <DamageStatisticType> >(
                "getHeroDamageStatistic",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "token"
            },
                    new QueryArgument <NonNullGraphType <IdGraphType> > {
                Name = "pageNumber"
            },
                    new QueryArgument <BooleanGraphType> {
                Name = "sortNameAsc"
            },
                    new QueryArgument <BooleanGraphType> {
                Name = "sortNameDesc"
            },
                    new QueryArgument <BooleanGraphType> {
                Name = "sortDamageAsc"
            },
                    new QueryArgument <BooleanGraphType> {
                Name = "sortDamageDesc"
            }
                    ),
                resolve: context =>
            {
                var token          = context.GetArgument <string>("token");
                var pageNumber     = context.GetArgument <int>("pageNumber");
                var sortNameAsc    = context.GetArgument <bool>("sortNameAsc");
                var sortNameDesc   = context.GetArgument <bool>("sortNameDesc");
                var sortDamageAsc  = context.GetArgument <bool>("sortDamageAsc");
                var sortDamageDesc = context.GetArgument <bool>("sortDamageDesc");

                validatorService.ValidateToken(token);

                var heroName        = jWTService.GetHeroNameFromToken(token);
                var heroId          = heroService.GetHeroByName(heroName).Id;
                var damageStatistic = hitService.GetHeroDamageStatistic(heroId).Result;

                damageStatistic = hitService.GetPageWithDamagesAsync(damageStatistic, pageNumber).Result;
                if (sortNameAsc)
                {
                    damageStatistic = hitService.SortByNameAsc(damageStatistic).Result;
                }

                if (sortNameDesc)
                {
                    damageStatistic = hitService.SortByNameDesc(damageStatistic).Result;
                }

                if (sortDamageAsc)
                {
                    damageStatistic = hitService.SortByDamageAsc(damageStatistic).Result;
                }

                if (sortDamageDesc)
                {
                    damageStatistic = hitService.SortByDamageDesc(damageStatistic).Result;
                }

                return(damageStatistic);
            });
        }
Esempio n. 5
0
        public DragonQuery(IDragonService dragonService,
                           IValidatorService validatorService)
        {
            Name = "Query";

            Field <DragonType>(
                "dragonById",
                arguments: new QueryArguments
            {
                new QueryArgument <NonNullGraphType <StringGraphType> > {
                    Name = "token"
                },
                new QueryArgument <IdGraphType> {
                    Name = "id"
                }
            },
                resolve: context =>
            {
                var token = context.GetArgument <string>("token");
                var id    = context.GetArgument <int>("id");

                validatorService.ValidateToken(token);

                return(dragonService.FindDragonByIdAsync(id));
            });

            Field <ListGraphType <DragonType> >(
                "dragons",
                arguments: new QueryArguments
            {
                new QueryArgument <NonNullGraphType <StringGraphType> > {
                    Name = "token"
                },
                new QueryArgument <NonNullGraphType <IdGraphType> > {
                    Name = "pageNumber"
                },
                new QueryArgument <StringGraphType> {
                    Name = "beginningOfTheName"
                },
                new QueryArgument <IdGraphType> {
                    Name = "maxHpMoreThen"
                },
                new QueryArgument <IdGraphType> {
                    Name = "maxHpLessThen"
                },
                new QueryArgument <IdGraphType> {
                    Name = "hpMoreThen"
                },
                new QueryArgument <IdGraphType> {
                    Name = "hpLessThen"
                },
            },
                resolve: context =>
            {
                var token              = context.GetArgument <string>("token");
                var pageNumber         = context.GetArgument <int>("pageNumber");
                var beginningOfTheName = context.GetArgument <string>("beginningOfTheName", defaultValue: "");
                var maxHpMoreThen      = context.GetArgument <int>("maxHpMoreThen", defaultValue: 80);
                var maxHpLessThen      = context.GetArgument <int>("maxHpLessThen", defaultValue: 100);
                var hpMoreThen         = context.GetArgument <int>("hpMoreThen", defaultValue: 0);
                var hpLessThen         = context.GetArgument <int>("hpLessThen", defaultValue: 100);

                validatorService.ValidateToken(token);

                var dragons = dragonService.GetDragonsAsync().Result;
                dragons     = dragonService.GetPageWithDragonsAsync(dragons, pageNumber).Result;

                dragons = dragonService.FilterDragonsByNameAsync(dragons, beginningOfTheName).Result;
                dragons = dragonService.FilterDragonsByHp(dragons, hpMoreThen, hpLessThen).Result;
                dragons = dragonService.FilterDragonsByMaxHp(dragons, maxHpMoreThen, maxHpLessThen).Result;

                return(dragons);
            }
                );
        }