-
Notifications
You must be signed in to change notification settings - Fork 0
/
completed-main.cs
105 lines (88 loc) · 4.12 KB
/
completed-main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// TRIP CHANGE WORKSHOP
using System;
using System.Text.Json;
using TripChangeWorkshop;
public class TripChange
{
public string type { get; set; }
public LatLong current_location { get; set; }
public string username {get; set;} // 3) add remaining fields from docs (username, route_success, load_id)
public string load_id {get; set;}
public bool route_success {get; set;}
public TripPolicyResult[] trip_policy_results {get; set;} // 7.c) add trip policy result to TripChange model
}
public class Program
{
static public void Main(string[] args)
{
MessageClient client = new MessageClient(System.Environment.GetEnvironmentVariable("ELEOS_API_KEY"));
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
Database database = new Database();
database.initializeLoads();
app.MapGet("/services", (HttpContext context) => {
var host = context.Request.Host.Value;
string services = @$"
Enter the follwing urls into their appropriate boxes in the Service Config page... </br></br>
<b>Authentication Service:</b> https://{host}/authenticate <br/><br/>
<b>Load Service:</b> https://{host}/loads <br/><br/>
<b>TODO Service:</b> https://{host}/todos <br/><br/>
<b>Trip Change Service:</b> https://{host}/tripchanges
";
return services;
});
app.MapGet("/authenticate/{api_token}", () =>
{
return database.retrieveUser();
});
app.MapGet("/loads", () =>
{
return database.getLoads();
});
app.MapGet("/todos", () =>
{
return database.getToDos();
});
app.MapGet("/tripchanges", () =>
{
// 2) return the trip changes we are store (for deubugging)
return database.getTripChanges();
});
app.MapPut("/tripchanges/{uuid}", (TripChange tripChange) =>
{
// 1) store trip change
database.storeTripChange(tripChange);
// 7) get trip policy off trip change
// 7.a) add trip policy result to trip change model (top of the file)
// 7.b) disable/enable nav on the load if policy is violated/passed
// 7.c) send load update to force refresh the load
// TripPolicyResult tripPolicy = tripChange.trip_policy_results.FirstOrDefault(x => x.code == "MAX-MILES");
TripPolicyResult tripPolicy = tripChange.trip_policy_results.FirstOrDefault(x => x.code == "MAX-MILES");
if (tripPolicy != null) {
if(tripPolicy.violation == true){
database.updatePreventNavigation(tripChange.load_id, true);
}
else {
database.updatePreventNavigation(tripChange.load_id, false);
}
client.sendLoadUpdate(tripChange.username, tripChange.load_id);
}
switch(tripChange.type){ // 4) add switch statement and move-stop/change-stop-location case
case "move-stop":
case "change-stop-location":
client.sendMessage(tripChange.username, "We received your load update. Please follow up with dispatch.");
break;
case "issue-report": // 5) add switch statement and issue-report case
ToDo t = new ToDo("Issue Report Follow-up", "Please describe the issue you had during navigation", "2024-11-30T22:30:00.0000+00:00", "ISSUE-REPORT");
database.storeToDo(t);
break;
case "mute-policy": // (OPTIONAL) add case for "mute-policy" and re-enable navigation on load
database.updatePreventNavigation(tripChange.load_id, false);
client.sendLoadUpdate(tripChange.username, tripChange.load_id);
break;
}
}
);
app.Run();
}
}