Changeset 434 for binary-improvements2/MarkersMod/src
- Timestamp:
- May 17, 2023, 11:05:59 PM (18 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements2/MarkersMod/src/Markers.cs
r430 r434 26 26 markers.Add (WebUtils.GenerateGuid (), (lat, lng, null)); 27 27 } 28 29 GameRandomManager.Instance.FreeGameRandom (random); 28 30 } 29 31 … … 58 60 59 61 if (!markers.TryGetValue (id, out (int, int, string) properties2)) { 60 writer.WriteRaw ( JsonEmptyData);62 writer.WriteRaw (WebUtils.JsonEmptyData); 61 63 SendEnvelopedResult (_context, ref writer, HttpStatusCode.NotFound); 62 64 return; … … 77 79 _writer.WriteString (_markerId); 78 80 _writer.WriteRaw (jsonKeyLat); 79 _writer.WriteInt32 (_properties.Item1); 81 (int lat, int lng, string icon) = _properties; 82 _writer.WriteInt32 (lat); 80 83 _writer.WriteRaw (jsonKeyLng); 81 _writer.WriteInt32 ( _properties.Item2);84 _writer.WriteInt32 (lng); 82 85 _writer.WriteRaw (jsonKeyIcon); 83 _writer.WriteString ( _properties.Item3?? defaultIcon);86 _writer.WriteString (icon ?? defaultIcon); 84 87 _writer.WriteEndObject (); 85 88 } 86 89 87 90 protected override void HandleRestPost (RequestContext _context, IDictionary<string, object> _jsonInput, byte[] _jsonInputData) { 88 if (! TryGetJsonField (_jsonInput, "lat", out int lat)) {89 SendE rrorResult(_context, HttpStatusCode.BadRequest, _jsonInputData, "NO_OR_INVALID_LAT");91 if (!JsonCommons.TryGetJsonField (_jsonInput, "lat", out int lat)) { 92 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "NO_OR_INVALID_LAT"); 90 93 return; 91 94 } 92 95 93 if (! TryGetJsonField (_jsonInput, "lng", out int lng)) {94 SendE rrorResult(_context, HttpStatusCode.BadRequest, _jsonInputData, "NO_OR_INVALID_LNG");96 if (!JsonCommons.TryGetJsonField (_jsonInput, "lng", out int lng)) { 97 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "NO_OR_INVALID_LNG"); 95 98 return; 96 99 } 97 100 98 TryGetJsonField (_jsonInput, "icon", out string icon);101 JsonCommons.TryGetJsonField (_jsonInput, "icon", out string icon); 99 102 if (string.IsNullOrEmpty (icon)) { 100 103 icon = null; … … 110 113 111 114 protected override void HandleRestPut (RequestContext _context, IDictionary<string, object> _jsonInput, byte[] _jsonInputData) { 112 if (! TryGetJsonField (_jsonInput, "lat", out int lat)) {113 SendE rrorResult(_context, HttpStatusCode.BadRequest, _jsonInputData, "NO_OR_INVALID_LAT");115 if (!JsonCommons.TryGetJsonField (_jsonInput, "lat", out int lat)) { 116 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "NO_OR_INVALID_LAT"); 114 117 return; 115 118 } 116 119 117 if (! TryGetJsonField (_jsonInput, "lng", out int lng)) {118 SendE rrorResult(_context, HttpStatusCode.BadRequest, _jsonInputData, "NO_OR_INVALID_LNG");120 if (!JsonCommons.TryGetJsonField (_jsonInput, "lng", out int lng)) { 121 SendEmptyResponse (_context, HttpStatusCode.BadRequest, _jsonInputData, "NO_OR_INVALID_LNG"); 119 122 return; 120 123 } 121 124 122 125 bool keepIcon = !_jsonInput.TryGetValue ("icon", out _); 123 TryGetJsonField (_jsonInput, "icon", out string icon);126 JsonCommons.TryGetJsonField (_jsonInput, "icon", out string icon); 124 127 if (string.IsNullOrEmpty (icon)) { 125 128 icon = null; … … 129 132 130 133 if (!markers.TryGetValue (id, out (int, int, string) properties)) { 131 SendE rrorResult(_context, HttpStatusCode.NotFound, _jsonInputData, "ID_NOT_FOUND");134 SendEmptyResponse (_context, HttpStatusCode.NotFound, _jsonInputData, "ID_NOT_FOUND"); 132 135 return; 133 136 } … … 154 157 string id = _context.RequestPath; 155 158 156 PrepareEnvelopedResult (out JsonWriter writer); 157 writer.WriteRaw (JsonEmptyData); 158 SendEnvelopedResult (_context, ref writer, markers.Remove (id) ? HttpStatusCode.NoContent : HttpStatusCode.NotFound); 159 SendEmptyResponse (_context, markers.Remove (id) ? HttpStatusCode.NoContent : HttpStatusCode.NotFound); 159 160 } 160 161
Note:
See TracChangeset
for help on using the changeset viewer.