-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add shop kitchen equipment list query
- Loading branch information
Showing
6 changed files
with
164 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
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,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; | ||
} | ||
} |
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 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
51
backend/app/Savor22b/GraphTypes/Types/ShopKitchEquipmentType.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,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
41
backend/app/Savor22b/GraphTypes/Types/ShopKitchenEquipment.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,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; } | ||
} |
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,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 | ||
); | ||
} | ||
} |