Skip to content

Commit c2b4856

Browse files
authored
Merge pull request #2 from Spoomer/9capi
Add 9capi Endpoint
2 parents 814c2d0 + a2a53d0 commit c2b4856

40 files changed

Lines changed: 1210 additions & 251 deletions

.github/workflows/publish_github_pages.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ on:
55
branches:
66
- main
77
pull_request:
8+
types: [closed]
89
branches:
9-
- main
10-
10+
- main
1111
permissions:
1212
contents: write
1313

1414
jobs:
1515
deploy-to-github-pages:
16+
if: github.event.pull_request.merged == true
1617
runs-on: ubuntu-latest
1718
steps:
1819
# Checkout the code

9cWebMarket.Frontend/9cWebMarket.Frontend.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<PackageReference Include="Lib9c" Version="1.29.0" />
1818
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="9.0.8" />
1919
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="9.0.8" PrivateAssets="all"/>
20+
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="9.0.9" />
2021
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.8" />
2122
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" Version="9.0.8" />
2223
</ItemGroup>

9cWebMarket.Frontend/Api/MimirEnums.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// ReSharper disable InconsistentNaming
12
namespace NineCWebMarket.Frontend.Api;
23

34
public enum ProductSortBy
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using Microsoft.Extensions.Options;
2+
using NineCWebMarket.Frontend.Configuration;
3+
4+
namespace NineCWebMarket.Frontend.Api;
5+
6+
public class NineCapiClient
7+
{
8+
private readonly IOptions<NineChroniclesEndpoints> _configuration;
9+
private readonly IHttpClientFactory _httpClientFactory;
10+
11+
12+
public NineCapiClient(IOptions<NineChroniclesEndpoints> configuration, IHttpClientFactory httpClientFactory)
13+
{
14+
_configuration = configuration;
15+
_httpClientFactory = httpClientFactory;
16+
}
17+
18+
public HttpClient GetClient(string planet)
19+
{
20+
if (!_configuration.Value.NineCapi.TryGetValue(planet, out var endpoint))
21+
{
22+
throw new ArgumentException($"Invalid planet:{planet}");
23+
}
24+
25+
var client = _httpClientFactory.CreateClient();
26+
client.BaseAddress = new Uri(endpoint);
27+
28+
return client;
29+
}
30+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// ReSharper disable InconsistentNaming
2+
namespace NineCWebMarket.Frontend.Api;
3+
4+
public class NineCapiEnums
5+
{
6+
public enum MarketOrderType
7+
{
8+
cp,
9+
cp_desc,
10+
price,
11+
price_desc,
12+
grade,
13+
grade_desc,
14+
crystal,
15+
crystal_desc,
16+
crystal_per_price,
17+
crystal_per_price_desc,
18+
level,
19+
level_desc,
20+
opt_count,
21+
opt_count_desc,
22+
unit_price,
23+
unit_price_desc
24+
}
25+
26+
27+
public static MarketOrderType FromMimirEnums(ProductSortBy productSortBy, SortDirection sortDirection)
28+
{
29+
return productSortBy switch
30+
{
31+
ProductSortBy.CP => sortDirection switch
32+
{
33+
SortDirection.ASCENDING => MarketOrderType.cp,
34+
SortDirection.DESCENDING => MarketOrderType.cp_desc,
35+
_ => throw new ArgumentOutOfRangeException(nameof(sortDirection), sortDirection, null)
36+
},
37+
ProductSortBy.CRYSTAL => sortDirection switch
38+
{
39+
SortDirection.ASCENDING => MarketOrderType.crystal,
40+
SortDirection.DESCENDING => MarketOrderType.crystal_desc,
41+
_ => throw new ArgumentOutOfRangeException(nameof(sortDirection), sortDirection, null)
42+
},
43+
ProductSortBy.GRADE => sortDirection switch
44+
{
45+
SortDirection.ASCENDING => MarketOrderType.grade,
46+
SortDirection.DESCENDING => MarketOrderType.grade_desc,
47+
_ => throw new ArgumentOutOfRangeException(nameof(sortDirection), sortDirection, null)
48+
},
49+
ProductSortBy.PRICE => sortDirection switch
50+
{
51+
SortDirection.ASCENDING => MarketOrderType.price,
52+
SortDirection.DESCENDING => MarketOrderType.price_desc,
53+
_ => throw new ArgumentOutOfRangeException(nameof(sortDirection), sortDirection, null)
54+
},
55+
ProductSortBy.UNIT_PRICE => sortDirection switch
56+
{
57+
SortDirection.ASCENDING => MarketOrderType.unit_price,
58+
SortDirection.DESCENDING => MarketOrderType.unit_price_desc,
59+
_ => throw new ArgumentOutOfRangeException(nameof(sortDirection), sortDirection, null)
60+
},
61+
ProductSortBy.CRYSTAL_PER_PRICE => sortDirection switch
62+
{
63+
SortDirection.ASCENDING => MarketOrderType.crystal_per_price,
64+
SortDirection.DESCENDING => MarketOrderType.crystal_per_price_desc,
65+
_ => throw new ArgumentOutOfRangeException(nameof(sortDirection), sortDirection, null)
66+
},
67+
_ => throw new ArgumentOutOfRangeException(nameof(productSortBy), productSortBy, null)
68+
};
69+
}
70+
}

9cWebMarket.Frontend/Configuration/NineChroniclesEndpoints.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ public record NineChroniclesEndpoints
66
public string? Planets { get; init; }
77
public string? ItemName { get; init; }
88
public string? RuneSheet { get; init; }
9+
public string? EquipmentItem { get; init; }
910
public Dictionary<string, string> Mimir { get; set; } = new();
11+
public Dictionary<string, string> NineCapi { get; set; } = new();
1012
}

9cWebMarket.Frontend/Layout/NavMenu.razor

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
<NavLink class="nav-link" href="Market" Match="NavLinkMatch.All">
3939
<span class="bi bi-plus-square-fill-nav-menu" aria-hidden="true"></span> Market
4040
</NavLink>
41-
@* <NavLink class="nav-link" href="MarketHistory" Match="NavLinkMatch.All"> *@
42-
@* <span class="bi bi-plus-square-fill-nav-menu" aria-hidden="true"></span> Market History *@
43-
@* </NavLink> *@
41+
<NavLink class="nav-link" href="MarketPerAccount" Match="NavLinkMatch.All">
42+
<span class="bi bi-plus-square-fill-nav-menu" aria-hidden="true"></span> Market per Account
43+
</NavLink>
4444
</div>
4545
</nav>
4646
</div>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace NineCWebMarket.Frontend.Models.Api;
4+
5+
public record FungibleAssetValueProduct(
6+
[property: JsonPropertyName("productId")] string ProductId,
7+
[property: JsonPropertyName("sellerAgentAddress")] string SellerAgentAddress,
8+
[property: JsonPropertyName("sellerAvatarAddress")] string SellerAvatarAddress,
9+
[property: JsonPropertyName("price")] int Price,
10+
[property: JsonPropertyName("quantity")] int Quantity,
11+
[property: JsonPropertyName("registeredBlockIndex")] int RegisteredBlockIndex,
12+
[property: JsonPropertyName("exist")] bool Exist,
13+
[property: JsonPropertyName("legacy")] bool Legacy,
14+
[property: JsonPropertyName("unitPrice")] double UnitPrice,
15+
[property: JsonPropertyName("decimalPlaces")] int DecimalPlaces,
16+
[property: JsonPropertyName("ticker")] string Ticker
17+
);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Text.Json.Serialization;
2+
3+
namespace NineCWebMarket.Frontend.Models.Api;
4+
5+
public record NineCapiMarketProviderResponse(
6+
[property: JsonPropertyName("totalCount")]
7+
int TotalCount,
8+
[property: JsonPropertyName("limit")] int Limit,
9+
[property: JsonPropertyName("offset")] int Offset,
10+
[property: JsonPropertyName("itemProducts")]
11+
IReadOnlyList<TradeItem> ItemProducts,
12+
[property: JsonPropertyName("fungibleAssetValueProducts")]
13+
IReadOnlyList<FungibleAssetValueProduct> FungibleAssetValueProducts
14+
)
15+
{
16+
public static NineCapiMarketProviderResponse Empty { get; } = new(0, 0, 0, [], []);
17+
};

9cWebMarket.Frontend/Models/Api/TradeItem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ public record TradeItem(
4343
int? CombatPoint,
4444
[property: JsonPropertyName("grade")] int? Grade,
4545
[property: JsonPropertyName("elementalType")]
46-
int? ElementalType,
46+
int ElementalType,
4747
[property: JsonPropertyName("setId")] int? SetId
4848
);

0 commit comments

Comments
 (0)