forked from 2023-Winter-Bootcamp-TeamH/buyself-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
views.py
37 lines (34 loc) · 1.16 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from app import db
from models.products import Products
# DB에 있는 products id 리스트 받아오기
def get_products_id_list(products_id):
p = db.session.query(Products).filter(Products.id == products_id).first()
product = {'id': p.id,
'class_name': p.class_name,
'price': p.price,
'img_url': p.img_url}
return product
# 전체 상품 리스트 반환
def get_product_all_list(page):
products = []
pagination = Products.query.paginate(page=page, per_page=6, error_out=False)
for p in pagination.items:
product = {'id': p.id,
'class_name': p.class_name,
'price': p.price,
'img_url': p.img_url}
products.append(product)
meta = get_page_list(pagination)
return products, meta
# 페이지 정보 반환
def get_page_list(pagination):
meta = {
"page": pagination.page,
"pages": pagination.pages,
"total_count": pagination.total,
"prev_page": pagination.prev_num,
"next_page": pagination.next_num,
"has_next": pagination.has_next,
"has_prev": pagination.has_prev
}
return meta