Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introduce GraphQL query for "inventory" #417

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Lib9c.GraphQL/Types/Items/InventoryItemType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using HotChocolate.Types;
using Lib9c.Models.Items;

namespace Lib9c.GraphQL.Types.Items;

public class InventoryItemType : ObjectType<InventoryItem>
{
protected override void Configure(IObjectTypeDescriptor<InventoryItem> descriptor)
{
descriptor.Ignore(f => f.Lock);
}
}
6 changes: 3 additions & 3 deletions Mimir.MongoDB/Repositories/InventoryRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ namespace Mimir.MongoDB.Repositories;

public class InventoryRepository(MongoDbService dbService)
{
public async Task<InventoryDocument> GetByAddressAsync(Address avatarAddress)
public async Task<InventoryDocument> GetByAddressAsync(Address address)
{
var collectionName = CollectionNames.GetCollectionName<InventoryDocument>();
var collection = dbService.GetCollection<InventoryDocument>(collectionName);
var filter = Builders<InventoryDocument>.Filter.Eq("Address", avatarAddress.ToHex());
var filter = Builders<InventoryDocument>.Filter.Eq("Address", address.ToHex());
var document = await collection.Find(filter).FirstOrDefaultAsync();
if (document is null)
{
throw new DocumentNotFoundInMongoCollectionException(
collection.CollectionNamespace.CollectionName,
$"'Address' equals to '{avatarAddress.ToHex()}'");
$"'Address' equals to '{address.ToHex()}'");
}

return document;
Expand Down
9 changes: 9 additions & 0 deletions Mimir/GraphQL/Queries/Query.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using HotChocolate.AspNetCore;
using Lib9c.GraphQL.Extensions;
using Lib9c.GraphQL.InputObjects;
using Lib9c.Models.Items;
using Lib9c.Models.Market;
using Lib9c.Models.States;
using Libplanet.Crypto;
Expand Down Expand Up @@ -100,6 +101,14 @@ public async Task<Dictionary<int, CombinationSlotState>> GetCombinationSlotsAsyn
public async Task<long> GetDailyRewardReceivedBlockIndexAsync(Address address, [Service] DailyRewardRepository repo)
=> (await repo.GetByAddressAsync(address)).Object;

/// <summary>
/// Get the inventory state by avatar address.
/// </summary>
/// <param name="address">The address of the avatar.</param>
/// <returns>The inventory state for the specified avatar address.</returns>
public async Task<Inventory> GetInventoryAsync(Address address, [Service] InventoryRepository repo) =>
(await repo.GetByAddressAsync(address)).Object;

/// <summary>
/// Get metadata by collection name.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion Mimir/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
builder.Services.AddSingleton<BalanceRepository>();
builder.Services.AddSingleton<CollectionRepository>();
builder.Services.AddSingleton<DailyRewardRepository>();
// builder.Services.AddSingleton<InventoryRepository>();
builder.Services.AddSingleton<InventoryRepository>();
builder.Services.AddSingleton<ItemSlotRepository>();
builder.Services.AddSingleton<MetadataRepository>();
builder.Services.AddSingleton<PetRepository>();
Expand Down
Loading