1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Net;
|
---|
4 | using AllocsFixes.JSON;
|
---|
5 |
|
---|
6 | namespace AllocsFixes.NetConnections.Servers.Web.API {
|
---|
7 | class Markers : AbsRestApi {
|
---|
8 | private readonly Dictionary<string, (string, string)> markers = new Dictionary<string, (string, string)> ();
|
---|
9 |
|
---|
10 | private static readonly JSONArray emptyResult = new JSONArray ();
|
---|
11 |
|
---|
12 | public Markers () {
|
---|
13 | markers.Add (WebUtils.GenerateGuid (), ("539", "498"));
|
---|
14 | markers.Add (WebUtils.GenerateGuid (), ("-18", "524"));
|
---|
15 | markers.Add (WebUtils.GenerateGuid (), ("29", "-162"));
|
---|
16 | markers.Add (WebUtils.GenerateGuid (), ("458", "-257"));
|
---|
17 | }
|
---|
18 |
|
---|
19 | protected override void HandleRestGet (RequestContext _context) {
|
---|
20 | string id = _context.RequestPath;
|
---|
21 |
|
---|
22 | if (string.IsNullOrEmpty (id)) {
|
---|
23 | JSONArray result = new JSONArray ();
|
---|
24 |
|
---|
25 | foreach (KeyValuePair<string, (string, string)> kvp in markers) {
|
---|
26 | JSONObject marker = new JSONObject ();
|
---|
27 | marker.Add ("id", new JSONString (kvp.Key));
|
---|
28 | marker.Add ("lat", new JSONString (kvp.Value.Item1));
|
---|
29 | marker.Add ("lng", new JSONString (kvp.Value.Item2));
|
---|
30 | result.Add (marker);
|
---|
31 | }
|
---|
32 |
|
---|
33 | SendEnvelopedResult (_context, result);
|
---|
34 | return;
|
---|
35 | }
|
---|
36 |
|
---|
37 | if (!markers.TryGetValue (id, out (string, string) location)) {
|
---|
38 | SendEnvelopedResult (_context, emptyResult, HttpStatusCode.NotFound);
|
---|
39 | return;
|
---|
40 | }
|
---|
41 |
|
---|
42 | {
|
---|
43 | JSONArray result = new JSONArray ();
|
---|
44 | JSONObject marker = new JSONObject ();
|
---|
45 | marker.Add ("id", new JSONString (id));
|
---|
46 | marker.Add ("lat", new JSONString (location.Item1));
|
---|
47 | marker.Add ("lng", new JSONString (location.Item2));
|
---|
48 | result.Add (marker);
|
---|
49 | SendEnvelopedResult (_context, result);
|
---|
50 | }
|
---|
51 | }
|
---|
52 |
|
---|
53 | protected override void HandleRestPost (RequestContext _context, JSONNode _jsonBody) {
|
---|
54 | if (!(_jsonBody is JSONObject bodyObject)) {
|
---|
55 |
|
---|
56 | }
|
---|
57 |
|
---|
58 | throw new NotImplementedException ();
|
---|
59 | }
|
---|
60 |
|
---|
61 | protected override void HandleRestPut (RequestContext _context, JSONNode _jsonBody) {
|
---|
62 | throw new NotImplementedException ();
|
---|
63 | }
|
---|
64 |
|
---|
65 | protected override void HandleRestDelete (RequestContext _context) {
|
---|
66 | throw new NotImplementedException ();
|
---|
67 | }
|
---|
68 | }
|
---|
69 | }
|
---|