Skip to content

Commit

Permalink
remove Mimir.Enums.CollectionNames
Browse files Browse the repository at this point in the history
  • Loading branch information
boscohyun committed Sep 13, 2024
1 parent 770087c commit b72770c
Show file tree
Hide file tree
Showing 40 changed files with 346 additions and 484 deletions.
4 changes: 3 additions & 1 deletion Mimir.MongoDB/Bson/ActionPointDocument.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Libplanet.Crypto;
using MongoDB.Bson.Serialization.Attributes;

namespace Mimir.MongoDB.Bson;

public record ActionPointDocument(Address Address, int Object) : MimirBsonDocument(Address) { }
[BsonIgnoreExtraElements]
public record ActionPointDocument(Address Address, int Object) : MimirBsonDocument(Address);
3 changes: 1 addition & 2 deletions Mimir.MongoDB/Bson/AgentDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
namespace Mimir.MongoDB.Bson;

[BsonIgnoreExtraElements]
public record AgentDocument(Address Address, AgentState Object)
: MimirBsonDocument(Address);
public record AgentDocument(Address Address, AgentState Object) : MimirBsonDocument(Address);
5 changes: 3 additions & 2 deletions Mimir.MongoDB/Bson/AllRuneDocument.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Lib9c.Models.States;
using Libplanet.Crypto;
using MongoDB.Bson.Serialization.Attributes;

namespace Mimir.MongoDB.Bson;

public record AllRuneDocument(Address Address, AllRuneState Object)
: MimirBsonDocument(Address) { }
[BsonIgnoreExtraElements]
public record AllRuneDocument(Address Address, AllRuneState Object) : MimirBsonDocument(Address);
3 changes: 1 addition & 2 deletions Mimir.MongoDB/Bson/ArenaRankingDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ public record ArenaRankingDocument(
int Round,
ArenaInformation ArenaInformation,
ArenaScore ArenaScore,
SimplifiedAvatarState SimpleAvatar
)
SimplifiedAvatarState SimpleAvatar)
{
public int Rank { get; set; }
}
5 changes: 3 additions & 2 deletions Mimir.MongoDB/Bson/BalanceDocument.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Libplanet.Crypto;
using Libplanet.Types.Assets;
using MongoDB.Bson.Serialization.Attributes;

namespace Mimir.MongoDB.Bson;

public record BalanceDocument(Address Address, FungibleAssetValue Object)
: MimirBsonDocument(Address) { }
[BsonIgnoreExtraElements]
public record BalanceDocument(Address Address, FungibleAssetValue Object) : MimirBsonDocument(Address);
5 changes: 3 additions & 2 deletions Mimir.MongoDB/Bson/CollectionDocument.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using Lib9c.Models.States;
using Libplanet.Crypto;
using MongoDB.Bson.Serialization.Attributes;

namespace Mimir.MongoDB.Bson;

/// <summary>
/// Not MongoDB collection, it is a NineChronicles' collection state.
/// </summary>
/// <param name="Object"></param>
public record CollectionDocument(Address Address, CollectionState Object)
: MimirBsonDocument(Address) { }
[BsonIgnoreExtraElements]
public record CollectionDocument(Address Address, CollectionState Object) : MimirBsonDocument(Address);
6 changes: 4 additions & 2 deletions Mimir.MongoDB/Bson/CombinationSlotStateDocument.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using Lib9c.Models.States;
using Libplanet.Crypto;
using MongoDB.Bson.Serialization.Attributes;

namespace Mimir.MongoDB.Bson;

[BsonIgnoreExtraElements]
public record CombinationSlotStateDocument(
Address Address,
Address AvatarAddress,
int SlotIndex,
CombinationSlotState Object
) : MimirBsonDocument(Address) { }
CombinationSlotState Object)
: MimirBsonDocument(Address);
4 changes: 3 additions & 1 deletion Mimir.MongoDB/Bson/DailyRewardDocument.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Libplanet.Crypto;
using MongoDB.Bson.Serialization.Attributes;

namespace Mimir.MongoDB.Bson;

public record DailyRewardDocument(Address Address, long Object) : MimirBsonDocument(Address) { }
[BsonIgnoreExtraElements]
public record DailyRewardDocument(Address Address, long Object) : MimirBsonDocument(Address);
4 changes: 3 additions & 1 deletion Mimir.MongoDB/Bson/InventoryDocument.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Lib9c.Models.Items;
using Libplanet.Crypto;
using MongoDB.Bson.Serialization.Attributes;

namespace Mimir.MongoDB.Bson;

public record InventoryDocument(Address Address, Inventory Object) : MimirBsonDocument(Address) { }
[BsonIgnoreExtraElements]
public record InventoryDocument(Address Address, Inventory Object) : MimirBsonDocument(Address);
5 changes: 3 additions & 2 deletions Mimir.MongoDB/Bson/ItemSlotDocument.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Lib9c.Models.States;
using Libplanet.Crypto;
using MongoDB.Bson.Serialization.Attributes;

namespace Mimir.MongoDB.Bson;

public record ItemSlotDocument(Address Address, ItemSlotState Object)
: MimirBsonDocument(Address) { }
[BsonIgnoreExtraElements]
public record ItemSlotDocument(Address Address, ItemSlotState Object) : MimirBsonDocument(Address);
4 changes: 3 additions & 1 deletion Mimir.MongoDB/Bson/PetStateDocument.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Lib9c.Models.States;
using Libplanet.Crypto;
using MongoDB.Bson.Serialization.Attributes;

namespace Mimir.MongoDB.Bson;

public record PetStateDocument(Address Address, PetState Object) : MimirBsonDocument(Address) { }
[BsonIgnoreExtraElements]
public record PetStateDocument(Address Address, PetState Object) : MimirBsonDocument(Address);
2 changes: 2 additions & 0 deletions Mimir.MongoDB/Bson/ProductDocument.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using Lib9c.Models.Market;
using Libplanet.Crypto;
using MongoDB.Bson.Serialization.Attributes;

namespace Mimir.MongoDB.Bson;

[BsonIgnoreExtraElements]
public record ProductDocument : MimirBsonDocument
{
public Address AvatarAddress { get; init; }
Expand Down
4 changes: 3 additions & 1 deletion Mimir.MongoDB/Bson/ProductsStateDocument.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using Lib9c.Models.States;
using Libplanet.Crypto;
using MongoDB.Bson.Serialization.Attributes;

namespace Mimir.MongoDB.Bson;

[BsonIgnoreExtraElements]
public record ProductsStateDocument(Address Address, ProductsState Object, Address AvatarAddress)
: MimirBsonDocument(Address) { }
: MimirBsonDocument(Address);
2 changes: 2 additions & 0 deletions Mimir.MongoDB/Bson/QuestListDocument.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// using Libplanet.Crypto;
// using Nekoyume.Model.Quest;
// using MongoDB.Bson.Serialization.Attributes;

// namespace Mimir.MongoDB.Bson;

// [BsonIgnoreExtraElements]
// public record QuestListDocument(Address Address, QuestList Object) : IMimirBsonDocument(Address) { }
4 changes: 3 additions & 1 deletion Mimir.MongoDB/Bson/RaiderStateDocument.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Lib9c.Models.States;
using Libplanet.Crypto;
using MongoDB.Bson.Serialization.Attributes;

namespace Mimir.MongoDB.Bson;

public record RaiderStateDocument(Address Address, RaiderState Object) : MimirBsonDocument(Address) { }
[BsonIgnoreExtraElements]
public record RaiderStateDocument(Address Address, RaiderState Object) : MimirBsonDocument(Address);
5 changes: 3 additions & 2 deletions Mimir.MongoDB/Bson/RuneSlotDocument.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Lib9c.Models.States;
using Libplanet.Crypto;
using MongoDB.Bson.Serialization.Attributes;

namespace Mimir.MongoDB.Bson;

public record RuneSlotDocument(Address Address, RuneSlotState Object)
: MimirBsonDocument(Address) { }
[BsonIgnoreExtraElements]
public record RuneSlotDocument(Address Address, RuneSlotState Object) : MimirBsonDocument(Address);
6 changes: 4 additions & 2 deletions Mimir.MongoDB/Bson/SheetDocument.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using Bencodex.Types;
using Libplanet.Crypto;
using MongoDB.Bson.Serialization.Attributes;
using Nekoyume.TableData;

namespace Mimir.MongoDB.Bson;

[BsonIgnoreExtraElements]
public record SheetDocument(
Address Address,
ISheet Object,
string Name,
IValue RawState
) : MimirBsonDocument(Address);
IValue RawState)
: MimirBsonDocument(Address);
10 changes: 6 additions & 4 deletions Mimir.MongoDB/Bson/StakeDocument.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// using Libplanet.Crypto;
// using Nekoyume.Model.Stake;
using Libplanet.Crypto;
using MongoDB.Bson.Serialization.Attributes;
using Nekoyume.Model.Stake;

// namespace Mimir.MongoDB.Bson;
namespace Mimir.MongoDB.Bson;

// public record StakeDocument(Address Address, StakeStateV2 Object) : IMimirBsonDocument(Address) { }
// [BsonIgnoreExtraElements]
// public record StakeDocument(Address Address, StakeStateV2 Object) : MimirBsonDocument(Address);
6 changes: 4 additions & 2 deletions Mimir.MongoDB/Bson/WorldBossKillRewardRecordDocument.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using Lib9c.Models.States;
using Libplanet.Crypto;
using MongoDB.Bson.Serialization.Attributes;

namespace Mimir.MongoDB.Bson;

[BsonIgnoreExtraElements]
public record WorldBossKillRewardRecordDocument(
Address Address,
Address AvatarAddress,
WorldBossKillRewardRecord Object
) : MimirBsonDocument(Address) { }
WorldBossKillRewardRecord Object)
: MimirBsonDocument(Address);
6 changes: 4 additions & 2 deletions Mimir.MongoDB/Bson/WorldBossStateDocument.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using Lib9c.Models.States;
using Libplanet.Crypto;
using MongoDB.Bson.Serialization.Attributes;

namespace Mimir.MongoDB.Bson;

[BsonIgnoreExtraElements]
public record WorldBossStateDocument(
Address Address,
int RaidId,
WorldBossState Object
) : MimirBsonDocument(Address) { }
WorldBossState Object)
: MimirBsonDocument(Address);
2 changes: 2 additions & 0 deletions Mimir.MongoDB/Bson/WorldInformationDocument.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using Bencodex.Types;
using Libplanet.Crypto;
using Lib9c.Models.Extensions;
using MongoDB.Bson.Serialization.Attributes;
using Nekoyume.Model;

namespace Mimir.MongoDB.Bson;

[BsonIgnoreExtraElements]
public record WorldInformationDocument : MimirBsonDocument
{
public IDictionary<int, WorldInformation.World> Object { get; init; }
Expand Down
19 changes: 0 additions & 19 deletions Mimir/Enums/CollectionNames.cs

This file was deleted.

50 changes: 19 additions & 31 deletions Mimir/GraphQL/Queries/Query.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,64 +9,52 @@ namespace Mimir.GraphQL.Queries;
public class Query
{
/// <summary>
/// Get a agent state by address.
/// Get metadata by collection name.
/// </summary>
/// <param name="collectionName">The name of the collection.</param>
/// <param name="repo"></param>
/// <returns>The metadata</returns>
public async Task<MetadataDocument> GetMetadataAsync(string collectionName, [Service] MetadataRepository repo)
=> await repo.GetByCollectionAsync(collectionName);

/// <summary>
/// Get an agent state by address.
/// </summary>
/// <param name="address">The address of the agent.</param>
/// <param name="repo"></param>
/// <returns>The agent state</returns>
public async Task<AgentState> GetAgentAsync(Address address, [Service] AgentRepository repo)
{
var doc = await repo.GetByAddressAsync(address);
return doc.Object;
}
public async Task<AgentState> GetAgentAsync(Address address, [Service] AgentRepository repo) =>
(await repo.GetByAddressAsync(address)).Object;

/// <summary>
/// Get a avatar state by address.
/// Get an avatar state by address.
/// </summary>
/// <param name="address">The address of the avatar.</param>
/// <param name="repo"></param>
/// <returns>The avatar state</returns>
public async Task<AvatarState> GetAvatarAsync(Address address, [Service] AvatarRepository repo)
{
var doc = await repo.GetByAddressAsync(address);
return doc.Object;
}
public async Task<AvatarState> GetAvatarAsync(Address address, [Service] AvatarRepository repo) =>
(await repo.GetByAddressAsync(address)).Object;

/// <summary>
/// Get an action point by address.
/// </summary>
/// <param name="address">The address of the avatar.</param>
/// <param name="repo"></param>
/// <returns>The action point.</returns>
public async Task<int> GetActionPointAsync(
Address address,
[Service] ActionPointRepository repo
) => await repo.GetByAddressAsync(address);
public async Task<int> GetActionPointAsync(Address address, [Service] ActionPointRepository repo) =>
(await repo.GetByAddressAsync(address)).Object;

/// <summary>
/// Get the daily reward received block index by address.
/// </summary>
/// <param name="address">The address of the avatar.</param>
/// <param name="repo"></param>
/// <returns>The daily reward received block index.</returns>
public async Task<long> GetDailyRewardReceivedBlockIndexAsync(
Address address,
[Service] DailyRewardRepository repo
) => await repo.GetByAddressAsync(address);
public async Task<long> GetDailyRewardReceivedBlockIndexAsync(Address address, [Service] DailyRewardRepository repo)
=> (await repo.GetByAddressAsync(address)).Object;

/// <summary>
/// Get arena sub-fields.
/// </summary>
public ArenaObject GetArena() => new();

/// <summary>
/// Get metadata by collection name.
/// </summary>
/// <param name="collectionName">The name of the collection.</param>
/// <param name="repo"></param>
/// <returns>The metadata</returns>
public async Task<MetadataDocument> GetMetadataAsync(
string collectionName,
[Service] MetadataRepository repo
) => await repo.GetByCollectionAsync(collectionName);
}
14 changes: 9 additions & 5 deletions Mimir/GraphQL/Resolvers/ArenaResolver.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using HotChocolate.Resolvers;
using Libplanet.Crypto;
using Mimir.Enums;
using Mimir.MongoDB;
using Mimir.MongoDB.Bson;
using Mimir.Repositories;
using Nekoyume.TableData;
Expand All @@ -20,7 +20,8 @@ public class ArenaResolver
return arenaRound;
}

var metadataDocument = await metadataRepo.GetByCollectionAsync(CollectionNames.Arena);
var collectionName = CollectionNames.GetCollectionName<ArenaDocument>();
var metadataDocument = await metadataRepo.GetByCollectionAsync(collectionName);
arenaRound = tableSheetsRepo.GetArenaRound(metadataDocument.LatestBlockIndex);
context.ScopedContextData = context.ScopedContextData.Add("arenaRound", arenaRound);
return arenaRound;
Expand Down Expand Up @@ -57,7 +58,8 @@ public static async Task<List<ArenaRankingDocument>> GetLeaderboardAsync(
);
}

var metadata = await metadataRepo.GetByCollectionAsync(CollectionNames.Arena);
var collectionName = CollectionNames.GetCollectionName<ArenaDocument>();
var metadata = await metadataRepo.GetByCollectionAsync(collectionName);
arenaRound ??= await GetRoundAsync(context, metadataRepo, tableSheetsRepo, arenaRound);
return await arenaRankingRepo.GetLeaderboardAsync(
metadata.LatestBlockIndex,
Expand All @@ -75,7 +77,8 @@ public static async Task<List<ArenaRankingDocument>> GetLeaderboardAsync(
[Service] TableSheetsRepository tableSheetsRepo,
[ScopedState("arenaRound")] ArenaSheet.RoundData? arenaRound)
{
var metadata = await metadataRepo.GetByCollectionAsync(CollectionNames.Arena);
var collectionName = CollectionNames.GetCollectionName<ArenaDocument>();
var metadata = await metadataRepo.GetByCollectionAsync(collectionName);
arenaRound ??= await GetRoundAsync(context, metadataRepo, tableSheetsRepo, arenaRound);
return await arenaRankingRepo.GetRankingByAvatarAddressAsync(
metadata.LatestBlockIndex,
Expand All @@ -92,7 +95,8 @@ public static async Task<List<ArenaRankingDocument>> GetLeaderboardByAvatarAddre
[Service] TableSheetsRepository tableSheetsRepo,
[ScopedState("arenaRound")] ArenaSheet.RoundData? arenaRound)
{
var metadata = await metadataRepo.GetByCollectionAsync(CollectionNames.Arena);
var collectionName = CollectionNames.GetCollectionName<ArenaDocument>();
var metadata = await metadataRepo.GetByCollectionAsync(collectionName);
arenaRound ??= await GetRoundAsync(context, metadataRepo, tableSheetsRepo, arenaRound);
return await arenaRankingRepo.GetLeaderboardByAvatarAddressAsync(
metadata.LatestBlockIndex,
Expand Down
Loading

0 comments on commit b72770c

Please sign in to comment.