public AircraftGraphType(IFlightStorage flightStorage)
        {
            Field(o => o.Title);
            Field(o => o.Type);
            Field(o => o.Model);
            Field(o => o.TailNumber);
            Field(o => o.Airline);
            Field(o => o.FlightNumber);

            FieldAsync <ListGraphType <StringGraphType> >("pictureUrls",
                                                          arguments: new QueryArguments
            {
                new QueryArgument(typeof(IntGraphType))
                {
                    Name = "random"
                }
            },
                                                          resolve: async context =>
            {
                var list   = await flightStorage.GetAircraftPictureUrlsAsync(context.Source.TailNumber);
                var random = context.GetArgument <int?>("random");
                if (random != null)
                {
                    list = list.Shuffle().Take(random.Value).ToList();
                }
                return(list);
            });
        }
예제 #2
0
        public FlightGraphType(IFlightStorage flightStorage)
        {
            Field(o => o.Id);
            Field(o => o.Title, nullable: true);
            Field(o => o.Description, nullable: true);

            Field(o => o.AddedDateTime);
            Field(o => o.StartDateTime);
            Field(o => o.EndDateTime, nullable: true);

            Field(o => o.Airline, nullable: true);
            Field(o => o.FlightNumber, nullable: true);

            Field(o => o.Aircraft, type: typeof(AircraftGraphType));

            Field(o => o.StatusTakeOff, nullable: true, type: typeof(FlightStatusGraphType));
            Field(o => o.StatusLanding, nullable: true, type: typeof(FlightStatusGraphType));

            Field(o => o.TakeOffDateTime, nullable: true);
            Field(o => o.LandingDateTime, nullable: true);

            Field(o => o.AirportFrom, nullable: true);
            Field(o => o.AirportTo, nullable: true);

            Field(o => o.State, type: typeof(FlightStateGraphType));

            Field(o => o.FlightPlan, type: typeof(FlightPlanGraphType));

            Field(o => o.VideoUrl, nullable: true);

            FieldAsync <BooleanGraphType>("hasScreenshots",
                                          resolve: async context =>
            {
                var route = await flightStorage.GetRouteAsync(context.Source.Id);
                return(route.Any(o => string.IsNullOrEmpty(o.ScreenshotUrl)));
            });

            FieldAsync <ListGraphType <FlightStatusGraphType> >("route",
                                                                arguments: new QueryArguments(
                                                                    new QueryArgument <UIntGraphType> {
                Name = "last"
            }
                                                                    ),
                                                                resolve: async context =>
            {
                System.Diagnostics.Debug.WriteLine($"[{System.DateTime.Now.ToString("HH:mm:ss")}] Start getting route of {context.Source.Id}...");
                var route = await flightStorage.GetRouteAsync(context.Source.Id);
                System.Diagnostics.Debug.WriteLine($"[{System.DateTime.Now.ToString("HH:mm:ss")}] Got route of {context.Source.Id}.");

                var last = context.GetArgument <int?>("last");
                if (last != null)
                {
                    route = route.TakeLast((int)last).ToList();
                    System.Diagnostics.Debug.WriteLine($"[{System.DateTime.Now.ToString("HH:mm:ss")}] Filtered route of {context.Source.Id}.");
                }
                return(route);
            });
        }
예제 #3
0
        public RootMutationGraphType(IFlightStorage flightStorage)
        {
            this.flightStorage = flightStorage;

            FieldAsync <FlightGraphType>("addFlight",
                                         arguments: new QueryArguments(
                                             new QueryArgument <NonNullGraphType <AddFlightInput> > {
                Name = "flight"
            }
                                             ),
                                         resolve: ResolveAddFlight);

            FieldAsync <FlightGraphType>("updateFlight",
                                         arguments: new QueryArguments(
                                             new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "id"
            },
                                             new QueryArgument <NonNullGraphType <UpdateFlightInput> > {
                Name = "flight"
            }
                                             ),
                                         resolve: ResolveUpdateFlight);

            FieldAsync <FlightGraphType>("patchFlight",
                                         arguments: new QueryArguments(
                                             new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "id"
            },
                                             new QueryArgument <NonNullGraphType <PatchFlightInput> > {
                Name = "flight"
            }
                                             ),
                                         resolve: ResolvePatchFlight);

            FieldAsync <FlightGraphType>("appendRoute",
                                         arguments: new QueryArguments(
                                             new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "id"
            },
                                             new QueryArgument <NonNullGraphType <ListGraphType <FlightStatusInput> > > {
                Name = "route"
            }
                                             ),
                                         resolve: ResolveAppendRoute);

            FieldAsync <BooleanGraphType>("deleteFlight",
                                          arguments: new QueryArguments(
                                              new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "id"
            }
                                              ),
                                          resolve: ResolveDeleteFlight).AuthorizeWith("Authenticated");
        }
예제 #4
0
        public RootQueryGraphType(IFlightStorage flightStorage)
        {
            FieldAsync <ListGraphType <FlightGraphType> >(
                "flights",
                arguments: new QueryArguments(
                    new QueryArgument <IntGraphType> {
                Name = "last"
            }
                    ),
                resolve: async context =>
            {
                var data = await flightStorage.GetFlightsAsync();

                data = data.OrderByDescending(a => a.AddedDateTime);

                var last = context.GetArgument <int?>("last");
                if (last != null)
                {
                    data = data.Take(last.Value);
                }

                return(data);
            }
                );

            FieldAsync <FlightGraphType>(
                "flight",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "id"
            }
                    ),
                resolve: async context =>
            {
                var id = context.GetArgument <string>("id");
                return(await flightStorage.GetFlightAsync(id));
            }
                );

            FieldAsync <ListGraphType <AircraftGraphType> >(
                "aircrafts",
                arguments: new QueryArguments(),
                resolve: async context =>
            {
                var result = new List <AircraftData>();
                await foreach (var aircraft in flightStorage.GetAircraftsAsync())
                {
                    result.Add(aircraft);
                }
                return(result);
            }
                );

            FieldAsync <AircraftGraphType>(
                "aircraft",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "tailNumber"
            }
                    ),
                resolve: async context =>
            {
                var tailNumber = context.GetArgument <string>("tailNumber");
                return(await flightStorage.GetAircraftAsync(tailNumber));
            }
                );
        }