Refactor GQL code. Auto load and save active shops. Auto start monitors.

This commit is contained in:
Patrick Fic
2020-01-20 15:42:59 -08:00
parent bc5cb13113
commit fa75c58633
11 changed files with 166 additions and 68 deletions

View File

@@ -1,4 +1,6 @@
using GraphQL.Client;
using GraphQL.Common.Request;
using GraphQL.Common.Response;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -9,11 +11,33 @@ namespace BodyshopUploader.Utils
{
public static class GraphQL
{
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
public static GraphQLClient CreateGQLClient()
{
var graphQLClient = new GraphQLClient("https://bodyshop-dev-db.herokuapp.com/v1/graphql");
graphQLClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + Utils.Auth.authlink.FirebaseToken);
return graphQLClient;
}
public static async Task<dynamic> ExecuteQuery(GraphQLRequest r)
{
using (var g = Utils.GraphQL.CreateGQLClient())
{
logger.Trace("Firing GQL Query: {0} {1}", r.Query.ToString(), r.Variables);
var graphQLResponse = await g.PostAsync(r);
if (graphQLResponse.Errors == null)
{
logger.Trace("GQL Response: {0}", graphQLResponse.Data);
return graphQLResponse.Data;
}
else
{
logger.Error("Error executing query.");
Array.ForEach(graphQLResponse.Errors, x => logger.Error(x.ToString()));
return null;
}
}
}
}
}

View File

@@ -83,15 +83,12 @@ namespace BodyshopUploader.Utils
}
private static async Task UpsertQueueItem(DTO_QueueItem item)
{
//Save the job to the DB.
{
item.Job.shopid = "52b7357c-0edd-4c95-85c3-dfdbcdfad9ac";
item.Job.est_number = "123";
item.Job.vehicle.data.shopid = "52b7357c-0edd-4c95-85c3-dfdbcdfad9ac";
logger.Info("Should upsert the job graphqlly here. {0}", item.Job);
logger.Info("Manually setting the shop id! {0}", item.Job);
var r = new GraphQLRequest
{
@@ -104,20 +101,25 @@ namespace BodyshopUploader.Utils
}
}",
Variables = new
{
{
jobInput = item.Job
}
};
using (var g = Utils.GraphQL.CreateGQLClient())
var d = await Utils.GraphQL.ExecuteQuery(r);
if(d!= null)
{
var graphQLResponse = await g.PostAsync(r);
if(graphQLResponse.Errors == null)
App.Current.Dispatcher.Invoke(() =>
{
logger.Trace("Job posted succesfully.");
}
Growler.AddNotification(new Notification()
{
Title = Properties.Resources.Msg_NewJobUploadError,
Subtitle = item.Job?.owner?.first_name?.Value + " " + item.Job?.owner?.last_name?.Value,
Message = item.Job?.vehicle?.v_model_yr?.Value + " " + item.Job?.vehicle?.v_make_desc?.Value + " " + item.Job?.vehicle?.v_model_desc?.Value
});
});
}
_jobs.Dequeue();
App.Current.Dispatcher.Invoke(() =>