Skip to content

Commit

Permalink
네이밍 수정 및 stateid 인자 수정 RemoveInstalled -> Uninstall, stateid -> space…
Browse files Browse the repository at this point in the history
…Number (#169)

* RemoveInstalled -> Uninstall, stateid -> spaceNumber

* Fix naming
  • Loading branch information
Atralupus authored May 11, 2024
1 parent e873459 commit fe3c28c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ namespace Savor22b.Tests.Action;
using Savor22b.States;
using Xunit;

public class RemoveInstalledKitchenEquipmentActionTests : ActionTests
public class UninstallKitchenEquipmentActionTests : ActionTests
{
public RemoveInstalledKitchenEquipmentActionTests() { }
public UninstallKitchenEquipmentActionTests() { }

private readonly Guid EquipmentStateId = new();

Expand All @@ -38,8 +38,8 @@ public void Execute_Success_Normal()

beforeState = beforeState.SetState(SignerAddress(), beforeRootState.Serialize());

var action = new RemoveInstalledKitchenEquipmentAction(
beforeRootState.InventoryState.KitchenEquipmentStateList[0].StateID
var action = new UninstallKitchenEquipmentAction(
1
);

var afterState = action.Execute(
Expand Down Expand Up @@ -87,7 +87,7 @@ public void Execute_Failure_NotInstalledKitchenEquipment()

beforeState = beforeState.SetState(SignerAddress(), beforeRootState.Serialize());

var action = new RemoveInstalledKitchenEquipmentAction(Guid.NewGuid());
var action = new UninstallKitchenEquipmentAction(1);

Assert.Throws<InvalidValueException>(() =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,27 @@ namespace Savor22b.Action;
using Libplanet.Headless.Extensions;
using Libplanet.State;

[ActionType(nameof(RemoveInstalledKitchenEquipmentAction))]
public class RemoveInstalledKitchenEquipmentAction : SVRAction
[ActionType(nameof(UninstallKitchenEquipmentAction))]
public class UninstallKitchenEquipmentAction : SVRAction
{
public RemoveInstalledKitchenEquipmentAction() { }
public UninstallKitchenEquipmentAction() { }

public RemoveInstalledKitchenEquipmentAction(Guid installedEquipmentStateId)
public UninstallKitchenEquipmentAction(int spaceNumber)
{
InstalledEquipmentStateId = installedEquipmentStateId;
SpaceNumber = spaceNumber;
}

public Guid InstalledEquipmentStateId { get; private set; }
public int SpaceNumber { get; private set; }

protected override IImmutableDictionary<string, IValue> PlainValueInternal =>
new Dictionary<string, IValue>()
{
[nameof(InstalledEquipmentStateId)] = InstalledEquipmentStateId.Serialize(),
[nameof(SpaceNumber)] = SpaceNumber.Serialize(),
}.ToImmutableDictionary();

protected override void LoadPlainValueInternal(IImmutableDictionary<string, IValue> plainValue)
{
InstalledEquipmentStateId = plainValue[nameof(InstalledEquipmentStateId)].ToGuid();
SpaceNumber = plainValue[nameof(SpaceNumber)].ToInteger();
}

public override IAccountStateDelta Execute(IActionContext ctx)
Expand All @@ -49,7 +49,7 @@ public override IAccountStateDelta Execute(IActionContext ctx)

KitchenState kitchenState = rootState.VillageState!.HouseState.KitchenState;

kitchenState.RemoveInstalledEquipment(InstalledEquipmentStateId);
kitchenState.UninstalledEquipment(SpaceNumber);

return states.SetState(ctx.Signer, rootState.Serialize());
}
Expand Down
2 changes: 1 addition & 1 deletion backend/app/Savor22b/GraphTypes/Query/Query.cs
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ swarm is null
AddField(new VillageField(blockChain, subject));
AddField(new ShowMeTheMoney(blockChain, swarm));
AddField(new ConquestDungeonActionQuery(blockChain, swarm));
AddField(new RemoveInstalledKitchenEquipmentActionQuery(blockChain, swarm));
AddField(new UninstallKitchenEquipmentActionQuery(blockChain, swarm));
AddField(new PeriodicDungeonRewardActionQuery(blockChain, swarm));

Field<NonNullGraphType<IntGraphType>>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ namespace Savor22b.GraphTypes.Query;
using Libplanet.Net;
using Savor22b.Action;

public class RemoveInstalledKitchenEquipmentActionQuery : FieldType
public class UninstallKitchenEquipmentActionQuery : FieldType
{
public RemoveInstalledKitchenEquipmentActionQuery(BlockChain blockChain, Swarm swarm)
public UninstallKitchenEquipmentActionQuery(BlockChain blockChain, Swarm swarm)
: base()
{
Name = "createAction_RemoveInstalledKitchenEquipmentActionQuery";
Name = "createAction_UninstallKitchenEquipmentActionQuery";
Type = typeof(NonNullGraphType<StringGraphType>);
Description = "설치된 큰 조리도구를 설치 제거합니다.";
Arguments = new QueryArguments(
Expand All @@ -22,10 +22,10 @@ public RemoveInstalledKitchenEquipmentActionQuery(BlockChain blockChain, Swarm s
Name = "publicKey",
Description = "대상 유저의 40-hex 형태의 address 입니다.",
},
new QueryArgument<NonNullGraphType<GuidGraphType>>
new QueryArgument<NonNullGraphType<IntGraphType>>
{
Name = "installedEquipmentStateId",
Description = "제거하려는 설치된 큰 조리도구의 State Id(Guid) 입니다.",
Name = "spaceNumber",
Description = "제거하려는 설치된 큰 조리도구의 설치공간 번호 입니다.",
}
);
Resolver = new FuncFieldResolver<string>(context =>
Expand All @@ -36,8 +36,8 @@ public RemoveInstalledKitchenEquipmentActionQuery(BlockChain blockChain, Swarm s
Libplanet.ByteUtil.ParseHex(context.GetArgument<string>("publicKey"))
);
var action = new RemoveInstalledKitchenEquipmentAction(
context.GetArgument<Guid>("installedEquipmentStateId")
var action = new UninstallKitchenEquipmentAction(
context.GetArgument<int>("spaceNumber")
);
return new GetUnsignedTransactionHex(
Expand Down
22 changes: 5 additions & 17 deletions backend/app/Savor22b/States/KitchenState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,27 +80,15 @@ int spaceNumber
}
}

public void RemoveInstalledEquipment(Guid stateId)
public void UninstalledEquipment(int spaceNumber)
{
if (FirstApplianceSpace.InstalledKitchenEquipmentStateId == stateId)
{
FirstApplianceSpace.UnInstallKitchenEquipment();
return;
}

if (SecondApplianceSpace.InstalledKitchenEquipmentStateId == stateId)
{
SecondApplianceSpace.UnInstallKitchenEquipment();
return;
}

if (ThirdApplianceSpace.InstalledKitchenEquipmentStateId == stateId)
var applianceSpace = GetApplianceSpaceStateByNumber(spaceNumber);
if (applianceSpace.InstalledKitchenEquipmentStateId is null)
{
ThirdApplianceSpace.UnInstallKitchenEquipment();
return;
throw new InvalidValueException($"The space {spaceNumber} is not installed any kitchen equipment.");
}

throw new InvalidValueException($"The equipment with the id {stateId} is not installed.");
applianceSpace.UnInstallKitchenEquipment();
}

public ApplianceSpaceState GetApplianceSpaceStateByNumber(int spaceNumber)
Expand Down

0 comments on commit fe3c28c

Please sign in to comment.