Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
I
idatg2204-project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Steffen Martinsen
idatg2204-project
Commits
7a0fa9ab
Commit
7a0fa9ab
authored
1 year ago
by
Knut Fineid
Browse files
Options
Downloads
Patches
Plain Diff
add brand to rest of product queries
parent
26996619
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
Backend/main.py
+1
-1
1 addition, 1 deletion
Backend/main.py
Backend/routes/product.py
+7
-3
7 additions, 3 deletions
Backend/routes/product.py
Backend/utils/helpers.py
+4
-2
4 additions, 2 deletions
Backend/utils/helpers.py
with
12 additions
and
6 deletions
Backend/main.py
+
1
−
1
View file @
7a0fa9ab
from
utils.application
import
app
from
utils.application
import
app
from
routes.category
import
get_category
from
routes.category
import
get_category
from
routes.home
import
get_home
from
routes.home
import
get_home
from
routes.order
import
post_pay_products
#
from routes.order import post_pay_products
#from routes.cart import get_cart
#from routes.cart import get_cart
from
routes.login
import
post_login
,
post_logout
,
post_register
from
routes.login
import
post_login
,
post_logout
,
post_register
from
routes.product
import
get_product_by_id
,
get_product_all
,
get_products_by_search
from
routes.product
import
get_product_by_id
,
get_product_all
,
get_products_by_search
...
...
This diff is collapsed.
Click to expand it.
Backend/routes/product.py
+
7
−
3
View file @
7a0fa9ab
...
@@ -22,8 +22,10 @@ def get_product_by_id(product_id):
...
@@ -22,8 +22,10 @@ def get_product_by_id(product_id):
if
len
(
products
)
>
1
:
if
len
(
products
)
>
1
:
return
jsonify
({
"
message
"
:
"
Database error
"
}),
500
return
jsonify
({
"
message
"
:
"
Database error
"
}),
500
print
(
products
)
# Use function to turn it into a json style object
# Use function to turn it into a json style object
jsonProduct
=
sql_product_to_json
(
products
)
[
0
]
jsonProduct
=
sql_product_to_json
(
products
)
return
jsonify
(
jsonProduct
)
return
jsonify
(
jsonProduct
)
...
@@ -31,7 +33,8 @@ def get_product_all():
...
@@ -31,7 +33,8 @@ def get_product_all():
# Get all the products
# Get all the products
cur
=
mysql
.
connection
.
cursor
()
cur
=
mysql
.
connection
.
cursor
()
cur
.
execute
(
'''
cur
.
execute
(
'''
SELECT product.product_id, product.name, product.description, product.price, product.stock_quantity FROM product
SELECT product.product_id, product.name, product.description, product.price, product.stock_quantity, brand.name, brand.description
FROM product INNER JOIN brand ON product.brand_id = brand.brand_id
'''
)
'''
)
products
=
cur
.
fetchall
()
products
=
cur
.
fetchall
()
...
@@ -46,7 +49,8 @@ def get_products_by_search(search):
...
@@ -46,7 +49,8 @@ def get_products_by_search(search):
cur
=
mysql
.
connection
.
cursor
()
cur
=
mysql
.
connection
.
cursor
()
# Search in product name and description
# Search in product name and description
cur
.
execute
(
'''
cur
.
execute
(
'''
SELECT product.product_id, product.name, product.description, product.price, product.stock_quantity FROM product
SELECT product.product_id, product.name, product.description, product.price, product.stock_quantity, brand.name, brand.description
FROM product INNER JOIN brand ON product.brand_id = brand.brand_id
WHERE product.name LIKE %s OR product.description LIKE %s
WHERE product.name LIKE %s OR product.description LIKE %s
'''
,
(
'
%
'
+
search
+
'
%
'
,
'
%
'
+
search
+
'
%
'
))
'''
,
(
'
%
'
+
search
+
'
%
'
,
'
%
'
+
search
+
'
%
'
))
...
...
This diff is collapsed.
Click to expand it.
Backend/utils/helpers.py
+
4
−
2
View file @
7a0fa9ab
def
sql_product_to_json
(
products
):
def
sql_product_to_json
(
products
):
jsonProducts
=
[]
jsonProducts
=
[]
for
product
in
products
:
for
product
in
products
:
product_id
,
name
,
description
,
price
,
stock_quantity
=
product
product_id
,
name
,
description
,
price
,
stock_quantity
,
brand_name
,
brand_desc
=
product
jsonProducts
.
append
({
jsonProducts
.
append
({
"
product_id
"
:
product_id
,
"
product_id
"
:
product_id
,
"
name
"
:
name
,
"
name
"
:
name
,
"
description
"
:
description
,
"
description
"
:
description
,
"
price
"
:
price
,
"
price
"
:
price
,
"
stock_quantity
"
:
stock_quantity
"
stock_quantity
"
:
stock_quantity
,
"
brand_name
"
:
brand_name
,
"
brand_description
"
:
brand_desc
})
})
return
jsonProducts
return
jsonProducts
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment