From c12c952b99a45ae663639bd53cf3b041c7d23a03 Mon Sep 17 00:00:00 2001 From: nn2-minh <Nguyen12.Minh@live.uwe.ac.uk> Date: Sat, 15 Mar 2025 17:34:06 +0700 Subject: [PATCH] Add shop and product --- app/frontend/components/auth/login.py | 4 ++-- app/frontend/components/auth/register.py | 4 ++-- app/frontend/components/shop/create_shop.py | 4 ++-- app/frontend/components/shop/view_shop.py | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/frontend/components/auth/login.py b/app/frontend/components/auth/login.py index 8f2b656..b0290cc 100644 --- a/app/frontend/components/auth/login.py +++ b/app/frontend/components/auth/login.py @@ -2,7 +2,7 @@ import customtkinter as ctk from tkinter import messagebox import requests -def login_frame(parent, switch_func, api_url): +def login_frame(parent, switch_func, API_URL): frame = ctk.CTkFrame(parent) def login(): @@ -14,7 +14,7 @@ def login_frame(parent, switch_func, api_url): return response = requests.post( - f"{api_url}/auth/login", json={"email": email, "password": password} + f"{API_URL}/auth/login", json={"email": email, "password": password} ) try: diff --git a/app/frontend/components/auth/register.py b/app/frontend/components/auth/register.py index 3223abf..64b238b 100644 --- a/app/frontend/components/auth/register.py +++ b/app/frontend/components/auth/register.py @@ -2,7 +2,7 @@ import customtkinter as ctk from tkinter import messagebox import requests -def register_frame(parent, switch_func, api_url): +def register_frame(parent, switch_func, API_URL): frame = ctk.CTkFrame(parent) def register(): @@ -21,7 +21,7 @@ def register_frame(parent, switch_func, api_url): return response = requests.post( - f"{api_url}/auth/signup", + f"{API_URL}/auth/signup", json={"username": username, "email": email, "phone_number": phone_number, "password": password}, ) diff --git a/app/frontend/components/shop/create_shop.py b/app/frontend/components/shop/create_shop.py index 14a44a3..d7ac4e3 100644 --- a/app/frontend/components/shop/create_shop.py +++ b/app/frontend/components/shop/create_shop.py @@ -4,7 +4,7 @@ import requests import os -def create_shop_frame(parent, switch_func, api_url, token): +def create_shop_frame(parent, switch_func, API_URL, token): frame = ctk.CTkFrame(parent) selected_file_path = [None] @@ -26,7 +26,7 @@ def create_shop_frame(parent, switch_func, api_url, token): messagebox.showwarning("Input Error", "Shop name is required!") return - url = f"{api_url}/shops" + url = f"{API_URL}/shops" data = {"name": name, "description": description} files = {} diff --git a/app/frontend/components/shop/view_shop.py b/app/frontend/components/shop/view_shop.py index 960fec4..2c10314 100644 --- a/app/frontend/components/shop/view_shop.py +++ b/app/frontend/components/shop/view_shop.py @@ -4,7 +4,7 @@ from tkinter import messagebox from PIL import Image, ImageTk import io -def view_shop_frame(parent, switch_func, api_url, token): +def view_shop_frame(parent, switch_func, API_URL, token): frame = ctk.CTkFrame(parent) # Title @@ -29,7 +29,7 @@ def view_shop_frame(parent, switch_func, api_url, token): """ Fetch the shop created by the logged-in user """ headers = {"Authorization": f"Bearer {token}"} try: - response = requests.get(f"{api_url}/shops/my-shop", headers=headers) # Adjust the endpoint as needed + response = requests.get(f"{API_URL}/shops/my-shop", headers=headers) # Adjust the endpoint as needed if response.status_code == 200: shop_data = response.json() shop_name_label.configure(text=f"Shop Name: {shop_data['name']}") @@ -58,7 +58,7 @@ def view_shop_frame(parent, switch_func, api_url, token): """ Fetch products that belong to the user's shop """ headers = {"Authorization": f"Bearer {token}"} try: - response = requests.get(f"{api_url}/products?shop_id={shop_id}", headers=headers) + response = requests.get(f"{API_URL}/products?shop_id={shop_id}", headers=headers) if response.status_code == 200: products = response.json() display_products(products) -- GitLab