Skip to content

Commit 964cdf1

Browse files
authored
Merge pull request #122 from TheSwerik/main
1.3.0 Remove Alternate Quality (#121)
2 parents 632885a + 3d84255 commit 964cdf1

8 files changed

Lines changed: 47 additions & 55 deletions

File tree

src/Api/Controllers/HttpUtilFunctions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public static class HttpUtilFunctions
44
{
55
public static string? GetRealIpAddress(this HttpRequest httpRequest)
66
{
7-
var forwardedChain = httpRequest.HttpContext.Request.Headers["X-Forwarded-For"].First();
7+
var forwardedChain = httpRequest.HttpContext.Request.Headers["X-Forwarded-For"].FirstOrDefault();
88
if (string.IsNullOrEmpty(forwardedChain)) return httpRequest.HttpContext.Connection.RemoteIpAddress?.ToString();
99
var clientIp = forwardedChain.Split(',').First();
1010
return clientIp;

src/Application/Services/GemService.cs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,13 @@ private GemData[] FilterGemData(GemDataQuery query)
6868

6969
private static string PreFilterGemDataQuery(GemDataQuery query)
7070
{
71-
const string isAlternateQuality = """
72-
(LOWER("Name") LIKE 'anomalous%'
73-
OR LOWER("Name") LIKE 'divergent%'
74-
OR LOWER("Name") LIKE 'phantasmal%')
75-
""";
7671
const string isVaal = """LOWER("Name") LIKE 'vaal%' """;
7772

7873
const string isExceptional = """
79-
(LOWER("Name") LIKE '%enhance%'
80-
OR LOWER("Name") LIKE '%empower%'
81-
OR LOWER("Name") LIKE '%enlighten%')
82-
""";
74+
(LOWER("Name") LIKE '%enhance%'
75+
OR LOWER("Name") LIKE '%empower%'
76+
OR LOWER("Name") LIKE '%enlighten%')
77+
""";
8378
const string isAwakened = """LOWER("Name") LIKE 'awakened%' """;
8479
const string isSupport = """LOWER("Name") LIKE '%support' """;
8580
var isGemTypeMatching = query.GemType switch
@@ -93,12 +88,11 @@ OR LOWER("Name") LIKE '%enlighten%')
9388
};
9489

9590
return $"""
96-
SELECT * FROM "GemData"
97-
WHERE LOWER("Name") LIKE '%{query.SearchText}%'
98-
AND ({query.ShowAlternateQuality} OR NOT {isAlternateQuality})
99-
AND ({query.ShowVaal} OR NOT {isVaal})
100-
AND {isGemTypeMatching}
101-
""";
91+
SELECT * FROM "GemData"
92+
WHERE LOWER("Name") LIKE '%{query.SearchText}%'
93+
AND ({query.ShowVaal} OR NOT {isVaal})
94+
AND {isGemTypeMatching}
95+
""";
10296
}
10397

10498
private static bool PostFilterGemData(GemData gemData, GemDataQuery query, decimal averageTempleCost)
@@ -122,5 +116,6 @@ private static decimal OrderGemData(GemData gemData, Sort sort, decimal averageT
122116
};
123117
}
124118

125-
[GeneratedRegex("[^a-z ]")] private static partial Regex SqlSanitizeRegex();
119+
[GeneratedRegex("[^a-z ]")]
120+
private static partial Regex SqlSanitizeRegex();
126121
}

src/Domain/QueryParameters/GemDataQuery.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ public class GemDataQuery
66
public Sort Sort { get; init; } = Sort.AverageProfitPerTryDesc;
77
public GemType GemType { get; init; } = GemType.All;
88
public bool OnlyShowProfitable { get; init; }
9-
public bool ShowAlternateQuality { get; init; }
109
public bool ShowVaal { get; set; } = false;
1110
public decimal? PricePerTryFrom { get; set; }
1211
public decimal? PricePerTryTo { get; set; }

src/Web/Shared/Components/Filter.razor

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,7 @@
9999
</div>
100100
</div>
101101
<div class="w-100 mt-2 d-flex justify-content-between">
102-
<div class="form-check ps-0 m-0 w-50">
103-
<input class="form-check-input" type="checkbox" id="showAlternateQuality" checked="@FilterValues.ShowAlternateQuality" @onchange="UpdateShowAlternateQuality">
104-
<label class="form-check-label" for="showAlternateQuality">
105-
Alternate Quality
106-
</label>
107-
</div>
108-
<div class="form-check ps-0 m-0 w-50 d-flex justify-content-end">
102+
<div class="form-check ps-0 m-0 w-100 d-flex justify-content-end">
109103
<input class="form-check-input" type="checkbox" id="onlyProfitable" checked="@FilterValues.OnlyShowProfitable" @onchange="UpdateOnlyShowProfitable">
110104
<label class="form-check-label" for="onlyProfitable">
111105
Only Profitable

src/Web/Shared/Components/Filter.razor.cs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,34 @@ private string TempleCostString()
4141
private string CurrencyValueString()
4242
{
4343
return FilterValues.CurrencyValue is null && FilterValues.Currency is not null
44-
? ToStringOrBlank(FilterValues.Currency.ChaosEquivalent)
45-
: ToStringOrBlank(FilterValues.CurrencyValue);
44+
? ToStringOrBlank(FilterValues.Currency.ChaosEquivalent)
45+
: ToStringOrBlank(FilterValues.CurrencyValue);
4646
}
4747

48-
private void ToggleFilters() { FiltersExpanded = !FiltersExpanded; }
48+
private void ToggleFilters()
49+
{
50+
FiltersExpanded = !FiltersExpanded;
51+
}
4952

5053
private static string ToStringOrBlank(decimal? value)
5154
{
5255
return value is null or decimal.MinValue or decimal.MaxValue ? "" : value.Round(2)!;
5356
}
5457

55-
private string CurrencyValue(decimal? value) { return ToStringOrBlank(value / ConversionRatio()); }
58+
private string CurrencyValue(decimal? value)
59+
{
60+
return ToStringOrBlank(value / ConversionRatio());
61+
}
62+
63+
private static IEnumerable<GemType> GemTypes()
64+
{
65+
return Enum.GetValues<GemType>();
66+
}
5667

57-
private static IEnumerable<GemType> GemTypes() { return Enum.GetValues<GemType>(); }
58-
private static IEnumerable<Sort> Sorts() { return Enum.GetValues<Sort>(); }
68+
private static IEnumerable<Sort> Sorts()
69+
{
70+
return Enum.GetValues<Sort>();
71+
}
5972

6073
private string TempleTradeUrl()
6174
{
@@ -103,7 +116,8 @@ private decimal ConversionRatio()
103116
return FilterValues.CurrencyValue ?? FilterValues.Currency?.ChaosEquivalent ?? 1;
104117
}
105118

106-
[GeneratedRegex("(\"(?:[^\"\\\\]|\\\\.)*\")|\\s+")] private static partial Regex JsonMinifyRegex();
119+
[GeneratedRegex("(\"(?:[^\"\\\\]|\\\\.)*\")|\\s+")]
120+
private static partial Regex JsonMinifyRegex();
107121

108122
#region Update Callback
109123

@@ -157,13 +171,6 @@ private async Task UpdateCurrency(string id)
157171
await SaveFilterValues();
158172
}
159173

160-
private async Task UpdateShowAlternateQuality(ChangeEventArgs args)
161-
{
162-
if (args.Value is null || !bool.TryParse(args.Value.ToString(), out var value)) return;
163-
FilterValues.ShowAlternateQuality = value;
164-
await SaveFilterValues();
165-
}
166-
167174
private async Task UpdateOnlyShowProfitable(ChangeEventArgs args)
168175
{
169176
if (args.Value is null || !bool.TryParse(args.Value.ToString(), out var value)) return;

src/Web/Shared/Model/FilterValues.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ public class FilterValues
1111
public decimal? PricePerTryFrom { get; set; }
1212
public decimal? PricePerTryTo { get; set; }
1313
public bool OnlyShowProfitable { get; set; }
14-
public bool ShowAlternateQuality { get; set; }
1514
public decimal? CurrencyValue { get; set; }
1615
public decimal? TempleCost { get; set; }
1716
public Currency? Currency { get; set; }
@@ -23,7 +22,6 @@ public GemDataQuery ToQuery()
2322
SearchText = Gem,
2423
Sort = Sort,
2524
GemType = GemType,
26-
ShowAlternateQuality = ShowAlternateQuality,
2725
OnlyShowProfitable = OnlyShowProfitable,
2826
PricePerTryFrom = PricePerTryFrom,
2927
PricePerTryTo = PricePerTryTo

src/Web/Util/ExtensionMethods.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,20 @@ public static string ToPrettyString(this GemType gemType)
5959
public static string ToQueryString(this GemDataQuery gemDataQuery, PageRequest? page)
6060
{
6161
return page is null
62-
? gemDataQuery.ToQueryString()
63-
: $"{page.ToQueryString()}{gemDataQuery.ToQueryString(false)}";
62+
? gemDataQuery.ToQueryString()
63+
: $"{page.ToQueryString()}{gemDataQuery.ToQueryString(false)}";
6464
}
6565

6666
public static string ToQueryString(this GemDataQuery gemDataQuery, bool questionMark = true)
6767
{
6868
var start = questionMark ? "?" : "&";
6969
var searchText = gemDataQuery.SearchText == string.Empty ? "" : $"&searchText={gemDataQuery.SearchText}";
7070
var pricePerTryFrom = gemDataQuery.PricePerTryFrom is null
71-
? ""
72-
: $"&pricePerTryFrom={gemDataQuery.PricePerTryFrom}";
71+
? ""
72+
: $"&pricePerTryFrom={gemDataQuery.PricePerTryFrom}";
7373
var pricePerTryTo = gemDataQuery.PricePerTryTo is null ? "" : $"&pricePerTryTo={gemDataQuery.PricePerTryTo}";
7474
return
75-
$"{start}sort={gemDataQuery.Sort}&gemType={gemDataQuery.GemType}&showAlternateQuality={gemDataQuery.ShowAlternateQuality}&onlyShowProfitable={gemDataQuery.OnlyShowProfitable}&showVaal={gemDataQuery.ShowVaal}{searchText}{pricePerTryFrom}{pricePerTryTo}";
75+
$"{start}sort={gemDataQuery.Sort}&gemType={gemDataQuery.GemType}&onlyShowProfitable={gemDataQuery.OnlyShowProfitable}&showVaal={gemDataQuery.ShowVaal}{searchText}{pricePerTryFrom}{pricePerTryTo}";
7676
}
7777

7878
public static string ToQueryString(this PageRequest pageRequest)
@@ -107,18 +107,18 @@ public static string TradeQuery(this GemTradeData gemTradeData, bool accurateLev
107107
var minGemLevel = accurateLevel ? gemTradeData.GemLevel : int.MinValue;
108108
var maxGemLevel = accurateLevel ? gemTradeData.GemLevel : int.MaxValue;
109109
var levelText = !accurateLevel
110-
? string.Empty
111-
: $@",""gem_level"": {{""min"": {minGemLevel},""max"": {maxGemLevel}}}";
110+
? string.Empty
111+
: $@",""gem_level"": {{""min"": {minGemLevel},""max"": {maxGemLevel}}}";
112112

113113
var minGemQuality = accurateQuality ? gemTradeData.GemQuality : int.MinValue;
114114
var maxGemQuality = accurateQuality ? gemTradeData.GemQuality : int.MaxValue;
115115
var qualityText = !accurateQuality
116-
? string.Empty
117-
: $@",""quality"": {{""min"": {minGemQuality},""max"": {maxGemQuality}}}";
116+
? string.Empty
117+
: $@",""quality"": {{""min"": {minGemQuality},""max"": {maxGemQuality}}}";
118118

119119
var gemAlternateQualityText = gemAlternateQuality < 0
120-
? string.Empty
121-
: $@",""gem_alternate_quality"": {{""option"": ""{gemAlternateQuality}""}},";
120+
? string.Empty
121+
: $@",""gem_alternate_quality"": {{""option"": ""{gemAlternateQuality}""}},";
122122

123123
return JsonMinifyRegex().Replace($@"
124124
{{
@@ -139,5 +139,6 @@ public static string TradeQuery(this GemTradeData gemTradeData, bool accurateLev
139139
", "$1");
140140
}
141141

142-
[GeneratedRegex("(\"(?:[^\"\\\\]|\\\\.)*\")|\\s+")] private static partial Regex JsonMinifyRegex();
142+
[GeneratedRegex("(\"(?:[^\"\\\\]|\\\\.)*\")|\\s+")]
143+
private static partial Regex JsonMinifyRegex();
143144
}

test/Web.Test/Shared/Model/FilterValuesTest.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ public void ToQuery()
1515
Sort = Sort.CostPerTryDesc,
1616
GemType = GemType.Exceptional,
1717
OnlyShowProfitable = true,
18-
ShowAlternateQuality = true,
1918
PricePerTryFrom = 0m,
2019
PricePerTryTo = 654m
2120
};
@@ -26,7 +25,6 @@ public void ToQuery()
2625
result.Sort.Should().Be(source.Sort);
2726
result.GemType.Should().Be(source.GemType);
2827
result.OnlyShowProfitable.Should().Be(source.OnlyShowProfitable);
29-
result.ShowAlternateQuality.Should().Be(source.ShowAlternateQuality);
3028
result.PricePerTryFrom.Should().Be(source.PricePerTryFrom);
3129
result.PricePerTryTo.Should().Be(source.PricePerTryTo);
3230
result.ShowVaal.Should().BeFalse();

0 commit comments

Comments
 (0)