Skip to content

Commit

Permalink
fix item search query
Browse files Browse the repository at this point in the history
  • Loading branch information
tyrosine1153 committed Oct 21, 2024
1 parent 3569529 commit c910c2b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions MarketService.Tests/MarketControllerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public async void GetItemProducts()
SizeLimit = null,
});
var controller = new MarketController(_logger, _context, cache);
var response = await controller.GetItemProducts((int) ItemSubType.Armor, null, null, null, null, Array.Empty<int>());
var response = await controller.GetItemProducts((int) ItemSubType.Armor, null, null, null, null, Array.Empty<int>(), false);
var result = Assert.Single(response.ItemProducts);
Assert.IsType<ItemProductResponseModel>(result);
Assert.Equal(product.ProductId, result.ProductId);
Expand Down Expand Up @@ -227,14 +227,14 @@ public async void GetItemProductsByStat()
var controller = new MarketController(_logger, _context, cache);
foreach (var stat in new [] {"atk", "ATK", "HP", "hp", "Hp", "Atk", null })
{
var response = await controller.GetItemProducts((int) ItemSubType.Armor, null, null, null, stat, Array.Empty<int>());
var response = await controller.GetItemProducts((int) ItemSubType.Armor, null, null, null, stat, Array.Empty<int>(), false);
var result = Assert.Single(response.ItemProducts);
Assert.IsType<ItemProductResponseModel>(result);
Assert.Equal(product.ProductId, result.ProductId);
Assert.Equal(2, result.Quantity);
Assert.Equal(3, result.Price);
}
var response2 = await controller.GetItemProducts((int) ItemSubType.Armor, null, null, null, "DEF", Array.Empty<int>());
var response2 = await controller.GetItemProducts((int) ItemSubType.Armor, null, null, null, "DEF", Array.Empty<int>(), false);
Assert.Empty(response2.ItemProducts);
await _context.Database.EnsureDeletedAsync();
}
Expand Down
8 changes: 4 additions & 4 deletions MarketService/Controllers/MarketController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ public MarketController(ILogger<MarketController> logger, MarketContext marketCo
}

[HttpGet("products/items/{type}")]
public async Task<MarketProductResponse> GetItemProducts(int type, int? limit, int? offset, string? order, string? stat, [FromQuery] int[] itemIds)
public async Task<MarketProductResponse> GetItemProducts(int type, int? limit, int? offset, string? order, string? stat, [FromQuery] int[] iconIds, bool isCustom)
{
var itemSubType = (ItemSubType) type;
var queryOffset = offset ?? 0;
var queryLimit = limit ?? 100;
var sort = string.IsNullOrEmpty(order) ? "cp_desc" : order;
var statType = string.IsNullOrEmpty(stat) ? StatType.NONE : Enum.Parse<StatType>(stat, true);
var queryResult = await Get(itemSubType, queryLimit, queryOffset, sort, statType, itemIds);
var queryResult = await Get(itemSubType, queryLimit, queryOffset, sort, statType, iconIds, isCustom);
var totalCount = queryResult.Count;
return new MarketProductResponse(
totalCount,
Expand All @@ -47,10 +47,10 @@ public async Task<MarketProductResponse> GetItemProducts(int type, int? limit, i
}

private async Task<List<ItemProductModel>> Get(ItemSubType itemSubType, int queryLimit, int queryOffset,
string sort, StatType statType, int[] iconIds, bool isCustom = false)
string sort, StatType statType, int[] iconIds, bool isCustom)
{
var ids = string.Join("_", iconIds.OrderBy(i => i));
var cacheKey = $"{itemSubType}_{queryLimit}_{queryOffset}_{sort}_{statType}_{ids}";
var cacheKey = $"{itemSubType}_{queryLimit}_{queryOffset}_{sort}_{statType}_{ids}_{isCustom}";
if (!_memoryCache.TryGetValue(cacheKey, out List<ItemProductModel>? queryResult))
{
var query = _dbContext.ItemProducts
Expand Down

0 comments on commit c910c2b

Please sign in to comment.