From 9842199c15561b27f29a549da52eb4222c121f86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Gim=C3=A9nez?= Date: Tue, 3 Sep 2024 20:39:32 +0900 Subject: [PATCH] add items FindByID --- pkg/data/items.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkg/data/items.go b/pkg/data/items.go index 2a02368..c09a50b 100644 --- a/pkg/data/items.go +++ b/pkg/data/items.go @@ -33,6 +33,16 @@ func (i Inventory) Find(name item.Name, locations ...item.LocationType) (Item, b return Item{}, false } +func (i Inventory) FindByID(unitID UnitID) (Item, bool) { + for _, it := range i.AllItems { + if it.UnitID == unitID { + return it, true + } + } + + return Item{}, false +} + func (i Inventory) ByLocation(locations ...item.LocationType) []Item { var items []Item