From b9bab62698c540899dd1ad9848f6b12d7d4545d9 Mon Sep 17 00:00:00 2001 From: steveoh Date: Tue, 17 Dec 2024 15:30:42 -0700 Subject: [PATCH] refactor(api): use dotnet 9 auto properties --- .../ReverseGeocodeRequestOptionsContract.cs | 12 +++++----- .../SingleGeocodeRequestOptionsContract.cs | 22 +++++++++---------- .../SingleGeocodeResponseContract.cs | 5 ++--- .../InformationRequestOptionsContract.cs | 8 +++---- ...erseRouteMilepostRequestOptionsContract.cs | 22 +++++++++---------- .../ReverseRouteMilepostResponseContract.cs | 10 ++++----- .../Searching/SearchRequestOptionsContract.cs | 11 +++++----- src/api/Models/ApiKey.cs | 4 +--- src/api/Models/ArcGis/Candidate.cs | 17 ++++++-------- .../RoadsAndHighways/GeometryToMeasure.cs | 10 ++++----- .../RoadsAndHighways/MeasureToGeometry.cs | 7 +++--- 11 files changed, 54 insertions(+), 74 deletions(-) diff --git a/src/api/Features/Geocoding/ReverseGeocodeRequestOptionsContract.cs b/src/api/Features/Geocoding/ReverseGeocodeRequestOptionsContract.cs index 5fe73fc7..408eb0a4 100644 --- a/src/api/Features/Geocoding/ReverseGeocodeRequestOptionsContract.cs +++ b/src/api/Features/Geocoding/ReverseGeocodeRequestOptionsContract.cs @@ -3,8 +3,6 @@ namespace ugrc.api.Features.Geocoding; public class ReverseGeocodeRequestOptionsContract : IProjectable { - private double _distance = 5; - /// /// The distance in meters from the input location to look for an address. Max value is 2000. /// @@ -13,17 +11,17 @@ public class ReverseGeocodeRequestOptionsContract : IProjectable { /// [DefaultValue(5)] public double Distance { - get => _distance; + get; set { - _distance = Math.Abs(value); + field = Math.Abs(value); - if (_distance > 2000) { - _distance = 2000; + if (field > 2000) { + field = 2000; return; } } - } + } = 5; public int SpatialReference { get; set; } = 26912; diff --git a/src/api/Features/Geocoding/SingleGeocodeRequestOptionsContract.cs b/src/api/Features/Geocoding/SingleGeocodeRequestOptionsContract.cs index a0449867..ff756a98 100644 --- a/src/api/Features/Geocoding/SingleGeocodeRequestOptionsContract.cs +++ b/src/api/Features/Geocoding/SingleGeocodeRequestOptionsContract.cs @@ -8,8 +8,6 @@ namespace ugrc.api.Features.Geocoding; /// The options available for geocoding /// public class SingleGeocodeRequestOptionsContract : IProjectable, IOutputConvertible { - private int _acceptScore = 70; - private int _suggest = 0; /// /// Every street zone geocode will return a score for the match on a scale from 0-100. The score is a rating of @@ -21,15 +19,15 @@ public class SingleGeocodeRequestOptionsContract : IProjectable, IOutputConverti /// [DefaultValue(70)] public int AcceptScore { - get => _acceptScore; + get; set { - _acceptScore = Math.Abs(value); + field = Math.Abs(value); - if (_acceptScore > 100) { - _acceptScore = 100; + if (field > 100) { + field = 100; } } - } + } = 70; /// /// The **default** value of `0` will return the highest match. To include the other candidates, set this value @@ -40,14 +38,14 @@ public int AcceptScore { /// [DefaultValue(0)] public int Suggest { - get => _suggest; + get; set { - _suggest = Math.Abs(value); - if (_suggest > 5) { - _suggest = 5; + field = Math.Abs(value); + if (field > 5) { + field = 5; } } - } + } = 0; /// /// The locators are the search engine for address data. There are three options, The **default** value of `all` diff --git a/src/api/Features/Geocoding/SingleGeocodeResponseContract.cs b/src/api/Features/Geocoding/SingleGeocodeResponseContract.cs index 0f086edb..d1083668 100644 --- a/src/api/Features/Geocoding/SingleGeocodeResponseContract.cs +++ b/src/api/Features/Geocoding/SingleGeocodeResponseContract.cs @@ -8,7 +8,6 @@ namespace ugrc.api.Features.Geocoding; public class SingleGeocodeResponseContract : Suggestable, IConvertible { - private double? _scoreDifference; /// /// The geographic coordinates for where the system thinks the input address exists. @@ -66,8 +65,8 @@ public class SingleGeocodeResponseContract : Suggestable, IConvertible public double? ScoreDifference { - get => _scoreDifference; - set => _scoreDifference = value.HasValue ? Math.Round(value.Value, 2) : null; + get; + set => field = value.HasValue ? Math.Round(value.Value, 2) : null; } [JsonIgnore] diff --git a/src/api/Features/Information/InformationRequestOptionsContract.cs b/src/api/Features/Information/InformationRequestOptionsContract.cs index 1445e4e3..bc1c53f6 100644 --- a/src/api/Features/Information/InformationRequestOptionsContract.cs +++ b/src/api/Features/Information/InformationRequestOptionsContract.cs @@ -2,8 +2,6 @@ namespace ugrc.api.Features.Information; public class InformationRequestOptionsContract { - private string? _sgidCategory = string.Empty; - /// /// The SGID category. All values will be returned if it is omitted. /// @@ -11,9 +9,9 @@ public class InformationRequestOptionsContract { /// boundaries /// public string? SgidCategory { - get => _sgidCategory; - set => _sgidCategory = value?.ToLowerInvariant().Trim() ?? string.Empty; - } + get; + set => field = value?.ToLowerInvariant().Trim() ?? string.Empty; + } = string.Empty; public static ValueTask BindAsync(HttpContext context) { var keyValueModel = QueryHelpers.ParseQuery(context.Request.QueryString.Value); diff --git a/src/api/Features/Milepost/ReverseRouteMilepostRequestOptionsContract.cs b/src/api/Features/Milepost/ReverseRouteMilepostRequestOptionsContract.cs index d9bfa38f..cf7a999b 100644 --- a/src/api/Features/Milepost/ReverseRouteMilepostRequestOptionsContract.cs +++ b/src/api/Features/Milepost/ReverseRouteMilepostRequestOptionsContract.cs @@ -3,8 +3,6 @@ namespace ugrc.api.Features.Milepost; public class ReverseRouteMilepostRequestOptionsContract : IProjectable { - private double _buffer = 100; - private int _suggest = 0; /// /// The radius around the input location in meters. @@ -14,17 +12,17 @@ public class ReverseRouteMilepostRequestOptionsContract : IProjectable { /// [DefaultValue(100)] public double Buffer { - get => _buffer; + get; set { - _buffer = Math.Abs(value); + field = Math.Abs(value); - if (_buffer > 200) { - _buffer = 200; + if (field > 200) { + field = 200; return; } } - } + } = 100; /// /// Include ramps in the results @@ -43,14 +41,14 @@ public double Buffer { /// [DefaultValue(0)] public int Suggest { - get => _suggest; + get; set { - _suggest = Math.Abs(value); - if (_suggest > 5) { - _suggest = 5; + field = Math.Abs(value); + if (field > 5) { + field = 5; } } - } + } = 0; public int SpatialReference { get; set; } = 26912; public static ValueTask BindAsync(HttpContext context) { diff --git a/src/api/Features/Milepost/ReverseRouteMilepostResponseContract.cs b/src/api/Features/Milepost/ReverseRouteMilepostResponseContract.cs index 5a2c8cbd..309a4f63 100644 --- a/src/api/Features/Milepost/ReverseRouteMilepostResponseContract.cs +++ b/src/api/Features/Milepost/ReverseRouteMilepostResponseContract.cs @@ -1,8 +1,6 @@ namespace ugrc.api.Features.Milepost; public class ReverseRouteMilepostResponseContract { private string _routeName = string.Empty; - private double _distance; - private double _milepost; /// /// Gets or sets the name of the route. @@ -28,8 +26,8 @@ public string Route { /// The distance away from the input point in meters. -1 for not found. Rounded to two decimal places /// public double OffsetMeters { - get => Math.Round(_distance, 2); - set => _distance = value; + get => Math.Round(field, 2); + set; } /// @@ -39,8 +37,8 @@ public double OffsetMeters { /// The closest milepost value rounded to three decimal places. /// public double Milepost { - get => Math.Round(_milepost, 3); - set => _milepost = value; + get => Math.Round(field, 3); + set; } /// diff --git a/src/api/Features/Searching/SearchRequestOptionsContract.cs b/src/api/Features/Searching/SearchRequestOptionsContract.cs index 07ffd002..4775bb28 100644 --- a/src/api/Features/Searching/SearchRequestOptionsContract.cs +++ b/src/api/Features/Searching/SearchRequestOptionsContract.cs @@ -5,7 +5,6 @@ namespace ugrc.api.Features.Searching; public class SearchRequestOptionsContract : IProjectable { - private double _buffer = 0; /// /// The where clause to be evaluated @@ -31,17 +30,17 @@ public class SearchRequestOptionsContract : IProjectable { /// 500 /// public double Buffer { - get => _buffer; + get; set { - _buffer = Math.Abs(value); + field = Math.Abs(value); - if (_buffer > 2000) { - _buffer = 2000; + if (field > 2000) { + field = 2000; return; } } - } + } = 0; /// /// Determines how attributes will be formatted in the response. diff --git a/src/api/Models/ApiKey.cs b/src/api/Models/ApiKey.cs index ff28dac6..0fd29807 100644 --- a/src/api/Models/ApiKey.cs +++ b/src/api/Models/ApiKey.cs @@ -3,8 +3,6 @@ namespace ugrc.api.Models; [FirestoreData] public class ApiKey { - private string _key = string.Empty; - [FirestoreData(ConverterType = typeof(FirestoreEnumIgnoreCaseNameConverter))] public enum ApplicationStatus { Development, @@ -34,7 +32,7 @@ public ApiKey() { } public string Id { get; set; } = string.Empty; [FirestoreProperty("accountId")] public string AccountId { get; set; } = string.Empty; - [FirestoreProperty("key")] public string Key { get => _key.ToLowerInvariant(); set => _key = value; } + [FirestoreProperty("key")] public string Key { get => field.ToLowerInvariant(); set; } = string.Empty; public long CreatedAtTicks { get; set; } [FirestoreProperty("created")] public DateTime CreatedAt => new DateTime(CreatedAtTicks).ToUniversalTime(); [FirestoreProperty("pattern")] public string? Pattern { get; set; } diff --git a/src/api/Models/ArcGis/Candidate.cs b/src/api/Models/ArcGis/Candidate.cs index ae4d2a9b..eb0127d4 100644 --- a/src/api/Models/ArcGis/Candidate.cs +++ b/src/api/Models/ArcGis/Candidate.cs @@ -2,9 +2,6 @@ namespace ugrc.api.Models.ArcGis; public class Candidate { - private string _address = string.Empty; - private string _addressGrid = string.Empty; - public Candidate(string address, string grid, Point location, double score, string locator, int weight) { Address = address; AddressGrid = grid; @@ -35,24 +32,24 @@ private static string ParseAddressGrid(string address) { // TODO: figure out what is going on with the splitting public string Address { - get => _address; + get; set { - _address = value; + field = value; - if (string.IsNullOrEmpty(_address)) { + if (string.IsNullOrEmpty(field)) { return; } - var parts = _address.Split([',']); + var parts = field.Split([',']); if (parts.Length != 3) { return; } AddressGrid = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(parts[1].Trim().ToLowerInvariant()); - _address = string.Join(",", parts[0], parts[2]).Trim(); + field = string.Join(",", parts[0], parts[2]).Trim(); } - } + } = string.Empty; public Point Location { get; set; } = default!; @@ -62,7 +59,7 @@ public string Address { public string Locator { get; set; } - public string AddressGrid { get => _addressGrid; set => _addressGrid = value.ToUpperInvariant(); } + public string AddressGrid { get; set => field = value.ToUpperInvariant(); } = string.Empty; [JsonIgnore] public int Weight { get; set; } diff --git a/src/api/Models/ArcGis/RoadsAndHighways/GeometryToMeasure.cs b/src/api/Models/ArcGis/RoadsAndHighways/GeometryToMeasure.cs index 28ad8953..b8abb16b 100644 --- a/src/api/Models/ArcGis/RoadsAndHighways/GeometryToMeasure.cs +++ b/src/api/Models/ArcGis/RoadsAndHighways/GeometryToMeasure.cs @@ -47,17 +47,15 @@ public record ResponseContract(ResponseLocation[] Locations, RestEndpointError? : RestErrorable(Error); public class ResponseLocation { - private double _measure; - public ResponseLocation[] Results { get; set; } = []; public Status Status { get; set; } public string RouteId { get; set; } = string.Empty; public double Measure { - get => _measure; + get; set { - _measure = Math.Round(value, 4); - if (_measure <= 0) { - _measure = 0.001D; + field = Math.Round(value, 4); + if (field <= 0) { + field = 0.001D; } } } diff --git a/src/api/Models/ArcGis/RoadsAndHighways/MeasureToGeometry.cs b/src/api/Models/ArcGis/RoadsAndHighways/MeasureToGeometry.cs index c0a55cff..f6275f9d 100644 --- a/src/api/Models/ArcGis/RoadsAndHighways/MeasureToGeometry.cs +++ b/src/api/Models/ArcGis/RoadsAndHighways/MeasureToGeometry.cs @@ -22,11 +22,10 @@ public record RequestLocation(string Measure, string RouteId) { } public record ResponseLocation(Status Status, ResponseLocation[] Results, string InputRouteId, GeometryType GeometryType, MeasurePoint? Geometry) { - private string _routeId = InputRouteId; public string RouteId { - get => string.IsNullOrEmpty(_routeId) ? "" : _routeId.TrimStart('0').TrimEnd('M'); - set => _routeId = value; - } + get => string.IsNullOrEmpty(field) ? "" : field.TrimStart('0').TrimEnd('M'); + set; + } = InputRouteId; } public record MeasurePoint(double X, double Y, double M);