Skip to content

Commit

Permalink
refactor(api): use dotnet 9 auto properties
Browse files Browse the repository at this point in the history
  • Loading branch information
steveoh committed Dec 17, 2024
1 parent d36ab81 commit b9bab62
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

namespace ugrc.api.Features.Geocoding;
public class ReverseGeocodeRequestOptionsContract : IProjectable {
private double _distance = 5;

/// <summary>
/// The distance in meters from the input location to look for an address. Max value is 2000.
/// </summary>
Expand All @@ -13,17 +11,17 @@ public class ReverseGeocodeRequestOptionsContract : IProjectable {
/// </example>
[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;

Expand Down
22 changes: 10 additions & 12 deletions src/api/Features/Geocoding/SingleGeocodeRequestOptionsContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ namespace ugrc.api.Features.Geocoding;
/// The options available for geocoding
/// </summary>
public class SingleGeocodeRequestOptionsContract : IProjectable, IOutputConvertible {
private int _acceptScore = 70;
private int _suggest = 0;

/// <summary>
/// Every street zone geocode will return a score for the match on a scale from 0-100. The score is a rating of
Expand All @@ -21,15 +19,15 @@ public class SingleGeocodeRequestOptionsContract : IProjectable, IOutputConverti
/// </summary>
[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;

/// <summary>
/// The **default** value of `0` will return the highest match. To include the other candidates, set this value
Expand All @@ -40,14 +38,14 @@ public int AcceptScore {
/// </example>
[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;

/// <summary>
/// The locators are the search engine for address data. There are three options, The **default** value of `all`
Expand Down
5 changes: 2 additions & 3 deletions src/api/Features/Geocoding/SingleGeocodeResponseContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

namespace ugrc.api.Features.Geocoding;
public class SingleGeocodeResponseContract : Suggestable, IConvertible<SingleGeocodeRequestOptionsContract> {
private double? _scoreDifference;

/// <summary>
/// The geographic coordinates for where the system thinks the input address exists.
Expand Down Expand Up @@ -66,8 +65,8 @@ public class SingleGeocodeResponseContract : Suggestable, IConvertible<SingleGeo
/// the same score.
/// </summary>
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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@

namespace ugrc.api.Features.Information;
public class InformationRequestOptionsContract {
private string? _sgidCategory = string.Empty;

/// <summary>
/// The SGID category. All values will be returned if it is omitted.
/// </summary>
/// <example>
/// boundaries
/// </example>
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<InformationRequestOptionsContract> BindAsync(HttpContext context) {
var keyValueModel = QueryHelpers.ParseQuery(context.Request.QueryString.Value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

namespace ugrc.api.Features.Milepost;
public class ReverseRouteMilepostRequestOptionsContract : IProjectable {
private double _buffer = 100;
private int _suggest = 0;

/// <summary>
/// The radius around the input location in meters.
Expand All @@ -14,17 +12,17 @@ public class ReverseRouteMilepostRequestOptionsContract : IProjectable {
/// </example>
[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;

/// <summary>
/// Include ramps in the results
Expand All @@ -43,14 +41,14 @@ public double Buffer {
/// </example>
[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<ReverseRouteMilepostRequestOptionsContract> BindAsync(HttpContext context) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
namespace ugrc.api.Features.Milepost;
public class ReverseRouteMilepostResponseContract {
private string _routeName = string.Empty;
private double _distance;
private double _milepost;

/// <summary>
/// Gets or sets the name of the route.
Expand All @@ -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
/// </value>
public double OffsetMeters {
get => Math.Round(_distance, 2);
set => _distance = value;
get => Math.Round(field, 2);
set;
}

/// <summary>
Expand All @@ -39,8 +37,8 @@ public double OffsetMeters {
/// The closest milepost value rounded to three decimal places.
/// </value>
public double Milepost {
get => Math.Round(_milepost, 3);
set => _milepost = value;
get => Math.Round(field, 3);
set;
}

/// <summary>
Expand Down
11 changes: 5 additions & 6 deletions src/api/Features/Searching/SearchRequestOptionsContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

namespace ugrc.api.Features.Searching;
public class SearchRequestOptionsContract : IProjectable {
private double _buffer = 0;

/// <summary>
/// The where clause to be evaluated
Expand All @@ -31,17 +30,17 @@ public class SearchRequestOptionsContract : IProjectable {
/// 500
/// </example>
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;

/// <summary>
/// Determines how attributes will be formatted in the response.
Expand Down
4 changes: 1 addition & 3 deletions src/api/Models/ApiKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
namespace ugrc.api.Models;
[FirestoreData]
public class ApiKey {
private string _key = string.Empty;

[FirestoreData(ConverterType = typeof(FirestoreEnumIgnoreCaseNameConverter<ApplicationStatus>))]
public enum ApplicationStatus {
Development,
Expand Down Expand Up @@ -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; }
Expand Down
17 changes: 7 additions & 10 deletions src/api/Models/ArcGis/Candidate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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!;

Expand All @@ -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; }
Expand Down
10 changes: 4 additions & 6 deletions src/api/Models/ArcGis/RoadsAndHighways/GeometryToMeasure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/api/Models/ArcGis/RoadsAndHighways/MeasureToGeometry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b9bab62

Please sign in to comment.