feat: UI profile
This commit is contained in:
parent
e2c4bf6563
commit
6db6dba13d
|
@ -3,6 +3,7 @@ import re
|
||||||
import flet as ft
|
import flet as ft
|
||||||
from flet.core.page import RouteChangeEvent
|
from flet.core.page import RouteChangeEvent
|
||||||
|
|
||||||
|
from pages.profile import profile
|
||||||
from requests.board_games import get_sections, get_games
|
from requests.board_games import get_sections, get_games
|
||||||
from requests.auth import login as login_req, registration
|
from requests.auth import login as login_req, registration
|
||||||
|
|
||||||
|
@ -248,10 +249,6 @@ def register(page):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def profile(page):
|
|
||||||
page.add(ft.Text("uwu"))
|
|
||||||
|
|
||||||
|
|
||||||
def main(page: ft.Page):
|
def main(page: ft.Page):
|
||||||
def route_change(e):
|
def route_change(e):
|
||||||
route = e.route
|
route = e.route
|
||||||
|
@ -273,3 +270,4 @@ def main(page: ft.Page):
|
||||||
|
|
||||||
|
|
||||||
ft.app(main)
|
ft.app(main)
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
class Game:
|
class Game:
|
||||||
def __init__(self, board_game_id, name, genre, publisher, price):
|
def __init__(self, board_game_id, name, genre, publisher, price, count = None):
|
||||||
self.board_game_id = board_game_id
|
self.board_game_id = board_game_id
|
||||||
self.name = name
|
self.name = name
|
||||||
self.genre = genre
|
self.genre = genre
|
||||||
self.publisher = publisher
|
self.publisher = publisher
|
||||||
self.price = price
|
self.price = price
|
||||||
|
self.count = count
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.name}\nЖанр: {self.genre}\nИздатель: {self.publisher}\n{self.price}"
|
return f"{self.name}\nЖанр: {self.genre}\nИздатель: {self.publisher}\n{self.price}" + (f"\n{self.count} шт." if self.count is not None else "")
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
class Order:
|
||||||
|
def __init__(self, id, pick_up, date, cost, games = []):
|
||||||
|
self.id = id
|
||||||
|
self.pick_up = pick_up
|
||||||
|
self.date = str(date)[:-7]
|
||||||
|
self.cost = cost
|
||||||
|
self.games = games
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return f"{self.pick_up}\n{self.date}\n{self.cost}"
|
|
@ -0,0 +1,9 @@
|
||||||
|
class User:
|
||||||
|
def __init__(self, id, surname, forename, patronymic, age, phone_number, email):
|
||||||
|
self.id = id
|
||||||
|
self.surname = surname
|
||||||
|
self.forename = forename
|
||||||
|
self.patronymic = patronymic
|
||||||
|
self.age = age
|
||||||
|
self.phone_number = phone_number
|
||||||
|
self.email = email
|
|
@ -0,0 +1,61 @@
|
||||||
|
import flet as ft
|
||||||
|
from alembic.command import history
|
||||||
|
|
||||||
|
from requests.auth import get_user
|
||||||
|
from requests.clients import get_wishlist, get_cart, get_history
|
||||||
|
|
||||||
|
|
||||||
|
def profile(page: ft.Page):
|
||||||
|
def back_clicked(e):
|
||||||
|
page.go("/")
|
||||||
|
page.update()
|
||||||
|
|
||||||
|
def order_clicked(e):
|
||||||
|
pass
|
||||||
|
|
||||||
|
user = get_user(page.client_storage.get("user_id"))
|
||||||
|
wishlist = get_wishlist(user.id)
|
||||||
|
cart = get_cart(user.id)
|
||||||
|
history = get_history(user.id)
|
||||||
|
|
||||||
|
page.add(ft.Column([
|
||||||
|
ft.TextButton("Назад", on_click=back_clicked),
|
||||||
|
ft.Text(f"Здравствуйте, {user.forename} {user.patronymic}!", size=24),
|
||||||
|
ft.Text(f"Список желаний", size=20),
|
||||||
|
ft.Row([
|
||||||
|
ft.Column([
|
||||||
|
ft.Text(str(game)),
|
||||||
|
ft.Row([
|
||||||
|
ft.IconButton(
|
||||||
|
icon=ft.Icons.SHOPPING_CART
|
||||||
|
),
|
||||||
|
ft.IconButton(
|
||||||
|
icon=ft.Icons.DELETE
|
||||||
|
)
|
||||||
|
])
|
||||||
|
]) for game in wishlist
|
||||||
|
]),
|
||||||
|
ft.Text(f"Корзина", size=20),
|
||||||
|
ft.Row([
|
||||||
|
ft.Column([
|
||||||
|
ft.Text(str(game)),
|
||||||
|
ft.Row([
|
||||||
|
ft.IconButton(
|
||||||
|
icon=ft.Icons.DELETE
|
||||||
|
)
|
||||||
|
])
|
||||||
|
]) for game in cart
|
||||||
|
]),
|
||||||
|
ft.Button("Заказать"),
|
||||||
|
ft.Text(f"История заказов", size=20),
|
||||||
|
ft.Row([
|
||||||
|
ft.Column([
|
||||||
|
ft.Text(f"Заказ №{order.id}", size=20),
|
||||||
|
ft.Text(str(order)),
|
||||||
|
ft.Text(f"Состав:", size=18),
|
||||||
|
ft.Row([
|
||||||
|
ft.Text(str(game)) for game in order.games
|
||||||
|
])
|
||||||
|
]) for order in history
|
||||||
|
])
|
||||||
|
]))
|
|
@ -1,3 +1,4 @@
|
||||||
|
from models.user import User
|
||||||
from requests.connection import get_cursor
|
from requests.connection import get_cursor
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,5 +27,19 @@ def registration(first_name, last_name, middle_name, age, phone, email, password
|
||||||
insert into auth (client_id, password)
|
insert into auth (client_id, password)
|
||||||
values ('{user_id}', '{password}');
|
values ('{user_id}', '{password}');
|
||||||
""")
|
""")
|
||||||
|
cursor.execute(f"""
|
||||||
|
insert into bags (client_id)
|
||||||
|
values ('{user_id}');
|
||||||
|
""")
|
||||||
|
cursor.execute(f"""
|
||||||
|
insert into wishlists (client_id)
|
||||||
|
values ('{user_id}');
|
||||||
|
""")
|
||||||
conn.commit()
|
conn.commit()
|
||||||
return user_id
|
return user_id
|
||||||
|
|
||||||
|
def get_user(user_id):
|
||||||
|
(cursor, conn) = get_cursor()
|
||||||
|
cursor.execute(f"select * from clients where client_id={user_id}")
|
||||||
|
res = cursor.fetchone()
|
||||||
|
return User(res[0], res[1], res[2], res[3], res[4], res[5], res[6])
|
|
@ -0,0 +1,67 @@
|
||||||
|
from models.game import Game
|
||||||
|
from models.order import Order
|
||||||
|
from requests.connection import get_cursor
|
||||||
|
|
||||||
|
|
||||||
|
def get_wishlist(user_id):
|
||||||
|
(cursor, conn) = get_cursor()
|
||||||
|
|
||||||
|
cursor.execute("SET lc_monetary TO 'ru_RU.UTF-8'")
|
||||||
|
|
||||||
|
cursor.execute(f"""
|
||||||
|
select *
|
||||||
|
from wishlists_games join wishlists using(wishlist_id) join board_games using(board_game_id)
|
||||||
|
where client_id = {user_id}
|
||||||
|
""")
|
||||||
|
|
||||||
|
res = cursor.fetchall()
|
||||||
|
parsed = []
|
||||||
|
|
||||||
|
for game in res:
|
||||||
|
parsed.append(Game(game[0], game[3], game[4], game[5], game[6]))
|
||||||
|
|
||||||
|
return parsed
|
||||||
|
|
||||||
|
|
||||||
|
def get_cart(user_id):
|
||||||
|
(cursor, conn) = get_cursor()
|
||||||
|
|
||||||
|
cursor.execute("SET lc_monetary TO 'ru_RU.UTF-8'")
|
||||||
|
|
||||||
|
cursor.execute(f"""
|
||||||
|
select *
|
||||||
|
from bags_board_games join bags using(bag_id) join board_games using(board_game_id)
|
||||||
|
where client_id = {user_id}
|
||||||
|
""")
|
||||||
|
|
||||||
|
res = cursor.fetchall()
|
||||||
|
parsed = []
|
||||||
|
|
||||||
|
for game in res:
|
||||||
|
parsed.append(Game(game[0], game[4], game[5], game[6], game[7], game[2]))
|
||||||
|
|
||||||
|
return parsed
|
||||||
|
|
||||||
|
def get_history(user_id):
|
||||||
|
(cursor, conn) = get_cursor()
|
||||||
|
|
||||||
|
cursor.execute("SET lc_monetary TO 'ru_RU.UTF-8'")
|
||||||
|
|
||||||
|
cursor.execute(f"select * from orders where client_id = {user_id}")
|
||||||
|
|
||||||
|
res = [Order(o[0], o[2], o[3], o[4]) for o in cursor.fetchall()]
|
||||||
|
|
||||||
|
for order in res:
|
||||||
|
cursor.execute("SET lc_monetary TO 'ru_RU.UTF-8'")
|
||||||
|
|
||||||
|
cursor.execute(f"""
|
||||||
|
select *
|
||||||
|
from orders_games join board_games using(board_game_id)
|
||||||
|
where order_id = {order.id}
|
||||||
|
""")
|
||||||
|
|
||||||
|
games = [Game(g[0], g[4], g[5], g[6], g[7], g[3]) for g in cursor.fetchall()]
|
||||||
|
|
||||||
|
order.games = games
|
||||||
|
|
||||||
|
return res
|
Loading…
Reference in New Issue