-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
330 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using HotChocolate.Language; | ||
using Libplanet.Crypto; | ||
|
||
namespace MarketService.GraphTypes; | ||
|
||
public class AddressType : ScalarType<Address, StringValueNode> | ||
{ | ||
public AddressType() : base("address") | ||
{ | ||
} | ||
|
||
public override IValueNode ParseResult(object? resultValue) | ||
{ | ||
return ParseValue(resultValue); | ||
} | ||
|
||
protected override Address ParseLiteral(StringValueNode valueSyntax) | ||
{ | ||
return new Address(valueSyntax.Value); | ||
} | ||
|
||
protected override StringValueNode ParseValue(Address runtimeValue) | ||
{ | ||
return new(Serialize(runtimeValue)); | ||
} | ||
|
||
private static string Serialize(Address runtimeValue) | ||
{ | ||
return runtimeValue.ToString(); | ||
} | ||
|
||
public override bool TrySerialize(object? runtimeValue, out object? resultValue) | ||
{ | ||
if (runtimeValue is null) | ||
{ | ||
resultValue = null; | ||
return true; | ||
} | ||
|
||
if (runtimeValue is Address a) | ||
{ | ||
resultValue = Serialize(a); | ||
return true; | ||
} | ||
|
||
resultValue = null; | ||
return false; | ||
} | ||
|
||
public override bool TryDeserialize(object? resultValue, out object? runtimeValue) | ||
{ | ||
if (resultValue is null) | ||
{ | ||
runtimeValue = null; | ||
return true; | ||
} | ||
|
||
if (resultValue is Address) | ||
{ | ||
runtimeValue = resultValue; | ||
return true; | ||
} | ||
|
||
runtimeValue = null; | ||
return false; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
MarketService/GraphTypes/FungibleAssetValueProductFilterType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using HotChocolate.Data.Filters; | ||
using MarketService.Models; | ||
|
||
namespace MarketService.GraphTypes; | ||
|
||
public class FungibleAssetValueProductFilterType: FilterInputType<FungibleAssetValueProductModel> | ||
{ | ||
protected override void Configure(IFilterInputTypeDescriptor<FungibleAssetValueProductModel> descriptor) | ||
{ | ||
descriptor.Field(f => f.SellerAgentAddress).Type<ProductFilterType.CustomAddressOperationFilterInputType>(); | ||
descriptor.Field(f => f.SellerAvatarAddress).Type<ProductFilterType.CustomAddressOperationFilterInputType>(); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
MarketService/GraphTypes/FungibleAssetValueProductModelType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using MarketService.Models; | ||
|
||
namespace MarketService.GraphTypes; | ||
|
||
public class FungibleAssetValueProductModelType : ObjectType<FungibleAssetValueProductModel> | ||
{ | ||
protected override void Configure(IObjectTypeDescriptor<FungibleAssetValueProductModel> descriptor) | ||
{ | ||
descriptor.BindFieldsExplicitly(); | ||
descriptor | ||
.Field(f => f.ProductId) | ||
.Type<UuidType>(); | ||
descriptor | ||
.Field(f => f.SellerAgentAddress) | ||
.Type<AddressType>(); | ||
descriptor | ||
.Field(f => f.SellerAvatarAddress) | ||
.Type<AddressType>(); | ||
descriptor | ||
.Field(f => f.Price) | ||
.Type<DecimalType>(); | ||
descriptor | ||
.Field(f => f.Quantity) | ||
.Type<DecimalType>(); | ||
descriptor | ||
.Field(f => f.RegisteredBlockIndex) | ||
.Type<LongType>(); | ||
descriptor | ||
.Field(f => f.Exist) | ||
.Type<BooleanType>(); | ||
descriptor | ||
.Field(f => f.Legacy) | ||
.Type<BooleanType>(); | ||
descriptor | ||
.Field(f => f.CreatedAt) | ||
.Type<DateTimeType>(); | ||
descriptor | ||
.Field(f => f.UnitPrice) | ||
.Type<DecimalType>(); | ||
descriptor.Field(f => f.DecimalPlaces) | ||
.Type<NonNullType<ByteType>>(); | ||
descriptor.Field(f => f.Ticker) | ||
.Type<StringType>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using HotChocolate.Data.Filters; | ||
using MarketService.Models; | ||
|
||
namespace MarketService.GraphTypes; | ||
|
||
public class ItemProductFilterType : FilterInputType<ItemProductModel> | ||
{ | ||
protected override void Configure(IFilterInputTypeDescriptor<ItemProductModel> descriptor) | ||
{ | ||
descriptor.Field(f => f.SellerAgentAddress).Type<ProductFilterType.CustomAddressOperationFilterInputType>(); | ||
descriptor.Field(f => f.SellerAvatarAddress).Type<ProductFilterType.CustomAddressOperationFilterInputType>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using MarketService.Models; | ||
|
||
namespace MarketService.GraphTypes; | ||
|
||
public class ItemProductModelType : ObjectType<ItemProductModel> | ||
{ | ||
protected override void Configure(IObjectTypeDescriptor<ItemProductModel> descriptor) | ||
{ | ||
descriptor.BindFieldsExplicitly(); | ||
descriptor | ||
.Field(f => f.ProductId) | ||
.Type<UuidType>(); | ||
descriptor | ||
.Field(f => f.SellerAgentAddress) | ||
.Type<AddressType>(); | ||
descriptor | ||
.Field(f => f.SellerAvatarAddress) | ||
.Type<AddressType>(); | ||
descriptor | ||
.Field(f => f.Price) | ||
.Type<DecimalType>(); | ||
descriptor | ||
.Field(f => f.Quantity) | ||
.Type<DecimalType>(); | ||
descriptor | ||
.Field(f => f.RegisteredBlockIndex) | ||
.Type<LongType>(); | ||
descriptor | ||
.Field(f => f.Exist) | ||
.Type<BooleanType>(); | ||
descriptor | ||
.Field(f => f.Legacy) | ||
.Type<BooleanType>(); | ||
descriptor | ||
.Field(f => f.CreatedAt) | ||
.Type<DateTimeType>(); | ||
descriptor | ||
.Field(f => f.UnitPrice) | ||
.Type<DecimalType>(); | ||
descriptor.Field(f => f.ItemId) | ||
.Type<NonNullType<IntType>>(); | ||
descriptor.Field(f => f.Grade) | ||
.Type<NonNullType<IntType>>(); | ||
descriptor | ||
.Field(f => f.CreatedAt) | ||
.Type<DateTimeType>(); | ||
descriptor.Field(f => f.ItemType); | ||
descriptor.Field(f => f.ItemSubType); | ||
descriptor.Field(f => f.ElementalType); | ||
descriptor.Field(f => f.SetId); | ||
descriptor.Field(f => f.CombatPoint); | ||
descriptor.Field(f => f.Level); | ||
descriptor.Field(f => f.Crystal); | ||
descriptor.Field(f => f.CrystalPerPrice); | ||
descriptor.Field(f => f.OptionCountFromCombination); | ||
descriptor | ||
.Field(f => f.Skills) | ||
.Type<ListType<SkillModelType>>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using HotChocolate.Data.Filters; | ||
using Libplanet.Crypto; | ||
using MarketService.Models; | ||
|
||
namespace MarketService.GraphTypes; | ||
|
||
public class ProductFilterType : FilterInputType<ProductModel> | ||
{ | ||
protected override void Configure(IFilterInputTypeDescriptor<ProductModel> descriptor) | ||
{ | ||
descriptor.Field(f => f.SellerAgentAddress).Type<CustomAddressOperationFilterInputType>(); | ||
descriptor.Field(f => f.SellerAvatarAddress).Type<CustomAddressOperationFilterInputType>(); | ||
} | ||
|
||
public class CustomAddressOperationFilterInputType : StringOperationFilterInputType | ||
{ | ||
protected override void Configure(IFilterInputTypeDescriptor descriptor) | ||
{ | ||
descriptor.Operation(DefaultFilterOperations.Equals).Type<AddressType>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using MarketService.Models; | ||
|
||
namespace MarketService.GraphTypes; | ||
|
||
public class ProductModelType : UnionType<ProductModel> | ||
{ | ||
protected override void Configure(IUnionTypeDescriptor descriptor) | ||
{ | ||
descriptor.Type<FungibleAssetValueProductModelType>(); | ||
descriptor.Type<ItemProductModelType>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
namespace MarketService.GraphTypes; | ||
|
||
public class QueryType : ObjectType<Query> | ||
{ | ||
protected override void Configure(IObjectTypeDescriptor<Query> descriptor) | ||
{ | ||
descriptor | ||
.Field(f => Query.GetProducts(default!)) | ||
.Type<ListType<ProductModelType>>() | ||
.UsePaging<ProductModelType>() | ||
.UseProjection() | ||
.UseFiltering<ProductFilterType>() | ||
.UseSorting(); | ||
|
||
descriptor | ||
.Field(f => Query.GetFavProducts(default!)) | ||
.Type<ListType<FungibleAssetValueProductModelType>>() | ||
.UsePaging<FungibleAssetValueProductModelType>() | ||
.UseProjection() | ||
.UseFiltering<FungibleAssetValueProductFilterType>() | ||
.UseSorting(); | ||
|
||
descriptor | ||
.Field(f => Query.GetItemProducts(default!)) | ||
.Type<ListType<ItemProductModelType>>() | ||
.UsePaging<ItemProductModelType>() | ||
.UseProjection() | ||
.UseFiltering<ItemProductFilterType>() | ||
.UseSorting(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using MarketService.Models; | ||
|
||
namespace MarketService.GraphTypes; | ||
|
||
public class SkillModelType : ObjectType<SkillModel> | ||
{ | ||
protected override void Configure(IObjectTypeDescriptor<SkillModel> descriptor) | ||
{ | ||
descriptor.Ignore(f => f.ToResponse()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using MarketService.Models; | ||
|
||
namespace MarketService.GraphTypes; | ||
|
||
public class StatModelType: ObjectType<StatModel> | ||
{ | ||
protected override void Configure(IObjectTypeDescriptor<StatModel> descriptor) | ||
{ | ||
descriptor.Ignore(f => f.ToResponse()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using MarketService.Models; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace MarketService; | ||
|
||
public class Query | ||
{ | ||
public static IQueryable<ProductModel> GetProducts([Service] MarketContext dbContext) | ||
{ | ||
return dbContext.Products.AsNoTracking().AsQueryable(); | ||
} | ||
|
||
public static IQueryable<FungibleAssetValueProductModel> GetFavProducts([Service] MarketContext dbContext) | ||
{ | ||
return dbContext.FungibleAssetValueProducts.AsNoTracking().AsQueryable(); | ||
} | ||
|
||
public static IQueryable<ItemProductModel> GetItemProducts([Service] MarketContext dbContext) | ||
{ | ||
return dbContext.ItemProducts.AsNoTracking().AsQueryable(); | ||
} | ||
} |