Skip to content

Commit

Permalink
feat: Add shop kitchen equipment list query
Browse files Browse the repository at this point in the history
  • Loading branch information
upa-r-upa committed Aug 20, 2023
1 parent 957acc0 commit a4fe29f
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 0 deletions.
1 change: 1 addition & 0 deletions backend/app/Savor22b/GraphTypes/Query/Query.cs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ swarm is null

AddField(new CalculateRelocationCostQuery());
AddField(new VillagesQuery(blockChain));
AddField(new ShopQuery());
}

private List<RecipeResponse> combineRecipeData()
Expand Down
43 changes: 43 additions & 0 deletions backend/app/Savor22b/GraphTypes/Query/ShopQuery.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace Savor22b.GraphTypes.Query;

using System.Collections.Immutable;
using System.Linq;
using GraphQL;
using GraphQL.Resolvers;
using GraphQL.Types;
using Savor22b.GraphTypes.Types;

public class ShopQuery : FieldType
{
public ShopQuery()
: base()
{
Name = "shop";
Type = typeof(NonNullGraphType<ShopType>);
Description = "This contains information about the items sold in the shop.";
Resolver = new FuncFieldResolver<Shop>(context =>
{
try
{
Shop shop = GetShop();
return shop;
}
catch (Exception e)
{
throw new ExecutionError(e.Message);
}
});
}

private static Shop GetShop()
{
var kitchenEquipmentCSVData = CsvDataHelper.GetKitchenEquipmentCSVData().ToArray();
var shopKitchenEquipments = kitchenEquipmentCSVData
.Select(kitchenEquipment => new ShopKitchenEquipment(kitchenEquipment))
.ToImmutableList();

Shop shop = new Shop(shopKitchenEquipments);

return shop;
}
}
13 changes: 13 additions & 0 deletions backend/app/Savor22b/GraphTypes/Types/Shop.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Collections.Immutable;

namespace Savor22b.GraphTypes.Types;

public class Shop
{
public ImmutableList<ShopKitchenEquipment> KitchenEquipments { get; private set; }

public Shop(ImmutableList<ShopKitchenEquipment> kitchenEquipments)
{
KitchenEquipments = kitchenEquipments;
}
}
51 changes: 51 additions & 0 deletions backend/app/Savor22b/GraphTypes/Types/ShopKitchEquipmentType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
namespace Savor22b.GraphTypes.Types;

using GraphQL.Types;

public class ShopKitchenEquipmentType : ObjectGraphType<ShopKitchenEquipment>
{
public ShopKitchenEquipmentType()
{
Field<NonNullGraphType<IntGraphType>>(
name: "id",
description: "This is the ID of the kitchen equipment",
resolve: context => context.Source.ID
);

Field<NonNullGraphType<IntGraphType>>(
name: "categoryID",
description: "This is the ID of the kitchen equipment category",
resolve: context => context.Source.CategoryID
);

Field<NonNullGraphType<StringGraphType>>(
name: "categoryLabel",
description: "This is the label of the kitchen equipment category",
resolve: context => context.Source.CategoryLabel
);

Field<NonNullGraphType<StringGraphType>>(
name: "categoryType",
description: "This is the type of the kitchen equipment category",
resolve: context => context.Source.CategoryType
);

Field<NonNullGraphType<StringGraphType>>(
name: "name",
description: "This is the name of the kitchen equipment",
resolve: context => context.Source.Name
);

Field<NonNullGraphType<FloatGraphType>>(
name: "blockTimeReductionPercent",
description: "This is the reduction percentage of block time when using the tool.",
resolve: context => context.Source.BlockTimeReductionPercent
);

Field<NonNullGraphType<StringGraphType>>(
name: "price",
description: "This is the price of the kitchen equipment",
resolve: context => context.Source.Price
);
}
}
41 changes: 41 additions & 0 deletions backend/app/Savor22b/GraphTypes/Types/ShopKitchenEquipment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Collections.Immutable;
using Savor22b.Model;

namespace Savor22b.GraphTypes.Types;

public class ShopKitchenEquipment
{
public ShopKitchenEquipment(KitchenEquipment kitchenEquipment)
{
ID = kitchenEquipment.ID;
CategoryID = kitchenEquipment.KitchenEquipmentCategoryID;
Name = kitchenEquipment.Name;
BlockTimeReductionPercent = kitchenEquipment.BlockTimeReductionPercent;
Price = kitchenEquipment.Price;

KitchenEquipmentCategory? kitchenEquipmentCategory =
CsvDataHelper.GetKitchenEquipmentCategoryByID(CategoryID);

if (kitchenEquipmentCategory == null)
{
throw new Exception($"KitchenEquipmentCategory not found. ID: {CategoryID}");
}

CategoryLabel = kitchenEquipmentCategory.Name;
CategoryType = kitchenEquipmentCategory.Category;
}

public int ID { get; private set; }

public int CategoryID { get; private set; }

public string CategoryLabel { get; private set; }

public string CategoryType { get; private set; }

public string Name { get; private set; }

public double BlockTimeReductionPercent { get; private set; }

public string Price { get; private set; }
}
15 changes: 15 additions & 0 deletions backend/app/Savor22b/GraphTypes/Types/ShopType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Savor22b.GraphTypes.Types;

using GraphQL.Types;

public class ShopType : ObjectGraphType<Shop>
{
public ShopType()
{
Field<NonNullGraphType<ListGraphType<ShopKitchenEquipmentType>>>(
name: "kitchenEquipments",
description: "This is a list of kitchen equipments that exist within the shop",
resolve: context => context.Source.KitchenEquipments
);
}
}

0 comments on commit a4fe29f

Please sign in to comment.