Skip to content

Commit e212ba4

Browse files
Added changes
1 parent c9fda6c commit e212ba4

File tree

6 files changed

+186
-5
lines changed

6 files changed

+186
-5
lines changed

Sep25/projects/approach2/warehouse/pyproject.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@ requires-python = ">=3.13"
1010
dependencies = []
1111

1212
[project.scripts]
13-
warehouse = "warehouse:main"
13+
warehouse = "warehouse.cli.main:main"
1414

1515
[build-system]
1616
requires = ["uv_build>=0.9.3,<0.10.0"]
1717
build-backend = "uv_build"
18+
19+
[dependency-groups]
20+
dev = [
21+
"pytest>=8.4.2",
22+
]
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
def main() -> None:
2-
print("Hello from warehouse!")
1+

Sep25/projects/approach2/warehouse/src/warehouse/cli/__init__.py

Whitespace-only changes.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
from warehouse.core.warehouse import WareHouse
2+
from warehouse.core.entities import WarehouseItem
3+
4+
def get_item_id() -> str:
5+
"""Prompts the user to enter a product ID.
6+
7+
Returns:
8+
str: The product ID entered by the user.
9+
"""
10+
wid = input("Enter the product id: ")
11+
return wid
12+
13+
def get_item_quantity() -> int:
14+
"""Prompts the user to enter the number of items (quantity).
15+
16+
Returns:
17+
int: The quantity entered by the user.
18+
"""
19+
quantity = int(input("Enter number of items: "))
20+
return quantity
21+
22+
def get_item_name() -> str:
23+
"""Prompts the user to enter a product name.
24+
25+
Returns:
26+
str: The product name entered by the user.
27+
"""
28+
name = input("Enter the product name: ")
29+
return name
30+
31+
def get_item_details() -> tuple[str, str, float, int]:
32+
"""Collects all necessary details for a new or existing warehouse item
33+
from the user: ID, name, price, and quantity.
34+
35+
Returns:
36+
tuple: A tuple containing the item ID (str), name (str), price (float),
37+
and quantity (int).
38+
"""
39+
wid: str = get_item_id()
40+
name: str = get_item_name()
41+
price: float = float(input("Enter the price of product: "))
42+
quantity: int = get_item_quantity()
43+
return wid,name,price,quantity
44+
45+
def main() -> None:
46+
"""Main function to run the warehouse management application.
47+
48+
Initializes a warehouse and runs a command-line interface loop
49+
to allow the user to add, procure, sell, and search for products.
50+
"""
51+
print("Welcome to warehouse")
52+
warehouse: WareHouse = WareHouse(
53+
wid="w1001",
54+
name="Hyd warehouse 1",
55+
location="Ameerpet")
56+
while True:
57+
print("1. Add a new product to Warehouse")
58+
print("2. Procure existing products")
59+
print("3. Sell Products")
60+
print("4. Get item by id")
61+
print("5. Get items by name")
62+
print("6. quit")
63+
choice: str = input("Enter your choice: ")
64+
if choice not in ("1", "2", "3", "4", "5", "6"):
65+
print("Invalid entry")
66+
elif choice == "1":
67+
wid: str
68+
name: str
69+
price: float
70+
quantity: int
71+
wid, name, price, quantity = get_item_details()
72+
warehouse.add_new_item(item_id= wid, name=name, price=price, quantity=quantity)
73+
elif choice == "2":
74+
wid: str = get_item_id()
75+
quantity: int = get_item_quantity()
76+
warehouse.procure_item(item_id=wid, quantity=quantity)
77+
elif choice == "3":
78+
wid: str = get_item_id()
79+
quantity: int = get_item_quantity()
80+
warehouse.sell_item(item_id=wid, quantity=quantity)
81+
elif choice == "4":
82+
wid: str = get_item_id()
83+
item: WarehouseItem | None = warehouse.find_item_by_id(item_id=wid)
84+
if item:
85+
print(item)
86+
else:
87+
print("Item not found")
88+
elif choice == "5":
89+
name: str = get_item_name()
90+
# Assuming find_item_by_name returns an iterable of WarehouseItem
91+
for item in warehouse.find_item_by_name(name=name):
92+
print(item)
93+
elif choice == "6":
94+
print("Bye................")
95+
break
96+
97+
if __name__ == "__main__":
98+
main()

Sep25/projects/approach2/warehouse/src/warehouse/core/warehouse.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ def find_item_by_id(self, item_id: str) -> WarehouseItem | None:
104104
Returns:
105105
The matching :class:`WarehouseItem` object, or None if the item is not found.
106106
"""
107-
pass
107+
if item_id in self.items:
108+
return self.items[item_id]
109+
else:
110+
print(f"item with {item_id} does not exist")
108111

109112
def find_item_by_name(self, name: str) -> list[WarehouseItem]:
110113
"""Finds items in the inventory that match the given name.
@@ -118,4 +121,9 @@ def find_item_by_name(self, name: str) -> list[WarehouseItem]:
118121
A list of matching :class:`WarehouseItem` objects. Returns an empty list
119122
if no matches are found.
120123
"""
121-
pass
124+
#selected_items = [ item for item in self.items if item.name == name ]
125+
selected_items: list[WarehouseItem] = []
126+
for item in self.items.values():
127+
if item.name == name:
128+
selected_items.append(item)
129+
return selected_items

Sep25/projects/approach2/warehouse/uv.lock

Lines changed: 71 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)