Gemini did alot of things
This commit is contained in:
@@ -235,7 +235,9 @@ class CLI:
|
||||
print("2. Adjust user debt")
|
||||
print("3. Clear user debt")
|
||||
print("4. View transaction history")
|
||||
print("5. Logout")
|
||||
print("5. Manage users")
|
||||
print("6. Manage items")
|
||||
print("7. Logout")
|
||||
print()
|
||||
|
||||
choice = input("Choose option: ").strip()
|
||||
@@ -249,6 +251,10 @@ class CLI:
|
||||
elif choice == "4":
|
||||
self._view_transaction_history()
|
||||
elif choice == "5":
|
||||
self._manage_users()
|
||||
elif choice == "6":
|
||||
self._manage_items()
|
||||
elif choice == "7":
|
||||
break
|
||||
else:
|
||||
self._invalid_choice()
|
||||
@@ -357,9 +363,10 @@ class CLI:
|
||||
else:
|
||||
for t in sorted(transactions, key=lambda x: x.timestamp, reverse=True):
|
||||
user = self.tracker.get_user_by_id(t.user_id)
|
||||
item = self.tracker.get_items()[t.item_id]
|
||||
item = self.tracker.get_items().get(t.item_id)
|
||||
item_name = item.name if item else ("Adjustment" if t.item_id == "adjustment" else "Deleted Item")
|
||||
print(
|
||||
f"{t.timestamp[:10]} | {user.name:.<20} {item.name:.<15} ${t.amount:.2f}"
|
||||
f"{t.timestamp[:10]} | {user.name:.<20} {item_name:.<15} ${t.amount:.2f}"
|
||||
)
|
||||
|
||||
print()
|
||||
@@ -368,3 +375,226 @@ class CLI:
|
||||
def _invalid_choice(self):
|
||||
print("Invalid choice. Please try again.")
|
||||
input("Press Enter to continue...")
|
||||
|
||||
def _manage_users(self):
|
||||
while True:
|
||||
self._clear_screen()
|
||||
print("=" * 50)
|
||||
print("MANAGE USERS")
|
||||
print("=" * 50)
|
||||
print()
|
||||
print("1. Add user")
|
||||
print("2. Edit user")
|
||||
print("3. Remove user")
|
||||
print("4. Back to admin panel")
|
||||
print()
|
||||
choice = input("Choose option: ").strip()
|
||||
if choice == "1":
|
||||
self._cli_add_user()
|
||||
elif choice == "2":
|
||||
self._cli_edit_user()
|
||||
elif choice == "3":
|
||||
self._cli_remove_user()
|
||||
elif choice == "4":
|
||||
break
|
||||
else:
|
||||
self._invalid_choice()
|
||||
|
||||
def _cli_add_user(self):
|
||||
self._clear_screen()
|
||||
print("=" * 50)
|
||||
print("ADD USER")
|
||||
print("=" * 50)
|
||||
print()
|
||||
name = input("Enter new user's name: ").strip()
|
||||
if not name:
|
||||
print("Name cannot be empty!")
|
||||
input("Press Enter to continue...")
|
||||
return
|
||||
import uuid
|
||||
user_id = f"user_{uuid.uuid4().hex[:8]}"
|
||||
res = self.tracker.add_user(user_id, name)
|
||||
print(res["message"])
|
||||
input("Press Enter to continue...")
|
||||
|
||||
def _cli_edit_user(self):
|
||||
self._clear_screen()
|
||||
print("=" * 50)
|
||||
print("EDIT USER")
|
||||
print("=" * 50)
|
||||
print()
|
||||
users = self.tracker.get_all_users()
|
||||
user_list = list(users.items())
|
||||
for i, (user_id, user) in enumerate(user_list, 1):
|
||||
print(f"{i}. {user.name} (PIN: {user.pin})")
|
||||
print(f"{len(user_list) + 1}. Cancel")
|
||||
print()
|
||||
try:
|
||||
choice = int(input("Choose user to edit: ").strip())
|
||||
if choice == len(user_list) + 1:
|
||||
return
|
||||
if 1 <= choice <= len(user_list):
|
||||
user_id = user_list[choice - 1][0]
|
||||
user = users[user_id]
|
||||
new_name = input(f"Enter new name (leave empty to keep '{user.name}'): ").strip()
|
||||
new_pin = input(f"Enter new PIN (leave empty to keep '{user.pin}'): ").strip()
|
||||
name = new_name if new_name else user.name
|
||||
pin = new_pin if new_pin else user.pin
|
||||
if len(pin) < 4:
|
||||
print("PIN must be at least 4 digits!")
|
||||
input("Press Enter to continue...")
|
||||
return
|
||||
res = self.tracker.edit_user(user_id, name, pin)
|
||||
print(res["message"])
|
||||
input("Press Enter to continue...")
|
||||
else:
|
||||
self._invalid_choice()
|
||||
except ValueError:
|
||||
self._invalid_choice()
|
||||
|
||||
def _cli_remove_user(self):
|
||||
self._clear_screen()
|
||||
print("=" * 50)
|
||||
print("REMOVE USER")
|
||||
print("=" * 50)
|
||||
print()
|
||||
users = self.tracker.get_all_users()
|
||||
user_list = list(users.items())
|
||||
for i, (user_id, user) in enumerate(user_list, 1):
|
||||
print(f"{i}. {user.name}")
|
||||
print(f"{len(user_list) + 1}. Cancel")
|
||||
print()
|
||||
try:
|
||||
choice = int(input("Choose user to remove: ").strip())
|
||||
if choice == len(user_list) + 1:
|
||||
return
|
||||
if 1 <= choice <= len(user_list):
|
||||
user_id = user_list[choice - 1][0]
|
||||
confirm = input(f"Are you sure you want to delete {users[user_id].name}? (y/n): ").strip().lower()
|
||||
if confirm == "y":
|
||||
res = self.tracker.remove_user(user_id)
|
||||
print(res["message"])
|
||||
input("Press Enter to continue...")
|
||||
else:
|
||||
self._invalid_choice()
|
||||
except ValueError:
|
||||
self._invalid_choice()
|
||||
|
||||
def _manage_items(self):
|
||||
while True:
|
||||
self._clear_screen()
|
||||
print("=" * 50)
|
||||
print("MANAGE ITEMS")
|
||||
print("=" * 50)
|
||||
print()
|
||||
print("1. Add item")
|
||||
print("2. Edit item")
|
||||
print("3. Remove item")
|
||||
print("4. Back to admin panel")
|
||||
print()
|
||||
choice = input("Choose option: ").strip()
|
||||
if choice == "1":
|
||||
self._cli_add_item()
|
||||
elif choice == "2":
|
||||
self._cli_edit_item()
|
||||
elif choice == "3":
|
||||
self._cli_remove_item()
|
||||
elif choice == "4":
|
||||
break
|
||||
else:
|
||||
self._invalid_choice()
|
||||
|
||||
def _cli_add_item(self):
|
||||
self._clear_screen()
|
||||
print("=" * 50)
|
||||
print("ADD ITEM")
|
||||
print("=" * 50)
|
||||
print()
|
||||
name = input("Enter item name: ").strip()
|
||||
if not name:
|
||||
print("Name cannot be empty!")
|
||||
input("Press Enter to continue...")
|
||||
return
|
||||
price_str = input("Enter price ($): ").strip()
|
||||
try:
|
||||
price = float(price_str)
|
||||
if price < 0:
|
||||
raise ValueError
|
||||
except ValueError:
|
||||
print("Invalid price!")
|
||||
input("Press Enter to continue...")
|
||||
return
|
||||
import uuid
|
||||
item_id = f"item_{uuid.uuid4().hex[:8]}"
|
||||
res = self.tracker.add_item(item_id, name, price)
|
||||
print(res["message"])
|
||||
input("Press Enter to continue...")
|
||||
|
||||
def _cli_edit_item(self):
|
||||
self._clear_screen()
|
||||
print("=" * 50)
|
||||
print("EDIT ITEM")
|
||||
print("=" * 50)
|
||||
print()
|
||||
items = self.tracker.get_items()
|
||||
item_list = list(items.items())
|
||||
for i, (item_id, item) in enumerate(item_list, 1):
|
||||
print(f"{i}. {item.name} (${item.price:.2f})")
|
||||
print(f"{len(item_list) + 1}. Cancel")
|
||||
print()
|
||||
try:
|
||||
choice = int(input("Choose item to edit: ").strip())
|
||||
if choice == len(item_list) + 1:
|
||||
return
|
||||
if 1 <= choice <= len(item_list):
|
||||
item_id = item_list[choice - 1][0]
|
||||
item = items[item_id]
|
||||
new_name = input(f"Enter new name (leave empty to keep '{item.name}'): ").strip()
|
||||
new_price_str = input(f"Enter new price (leave empty to keep '${item.price:.2f}'): ").strip()
|
||||
name = new_name if new_name else item.name
|
||||
price = item.price
|
||||
if new_price_str:
|
||||
try:
|
||||
price = float(new_price_str)
|
||||
if price < 0:
|
||||
raise ValueError
|
||||
except ValueError:
|
||||
print("Invalid price!")
|
||||
input("Press Enter to continue...")
|
||||
return
|
||||
res = self.tracker.edit_item(item_id, name, price)
|
||||
print(res["message"])
|
||||
input("Press Enter to continue...")
|
||||
else:
|
||||
self._invalid_choice()
|
||||
except ValueError:
|
||||
self._invalid_choice()
|
||||
|
||||
def _cli_remove_item(self):
|
||||
self._clear_screen()
|
||||
print("=" * 50)
|
||||
print("REMOVE ITEM")
|
||||
print("=" * 50)
|
||||
print()
|
||||
items = self.tracker.get_items()
|
||||
item_list = list(items.items())
|
||||
for i, (item_id, item) in enumerate(item_list, 1):
|
||||
print(f"{i}. {item.name} (${item.price:.2f})")
|
||||
print(f"{len(item_list) + 1}. Cancel")
|
||||
print()
|
||||
try:
|
||||
choice = int(input("Choose item to remove: ").strip())
|
||||
if choice == len(item_list) + 1:
|
||||
return
|
||||
if 1 <= choice <= len(item_list):
|
||||
item_id = item_list[choice - 1][0]
|
||||
confirm = input(f"Are you sure you want to delete {items[item_id].name}? (y/n): ").strip().lower()
|
||||
if confirm == "y":
|
||||
res = self.tracker.remove_item(item_id)
|
||||
print(res["message"])
|
||||
input("Press Enter to continue...")
|
||||
else:
|
||||
self._invalid_choice()
|
||||
except ValueError:
|
||||
self._invalid_choice()
|
||||
|
||||
|
||||
+1956
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user