Skip to content
Snippets Groups Projects
Commit 93df90f7 authored by Gisli Nielsen's avatar Gisli Nielsen
Browse files

Added route for getting user order and updated readme

parent d22d6087
No related branches found
No related tags found
No related merge requests found
from utils.application import app
from routes.category import get_category
from routes.home import get_home
from routes.order import post_create_order, pay_order
from routes.order import post_create_order, pay_order, get_all_orders
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
......@@ -23,6 +23,10 @@ def category(category_name=None):
def create_order():
return post_create_order()
@app.route('/order/', methods=['GET'])
def get_order():
return get_all_orders()
# Route for paying an order
@app.route('/order/payment/', methods=['POST'])
def pay():
......
......@@ -153,3 +153,31 @@ def pay_order():
# Dummy payment method
def vipps(amount, order_id):
return True
# Get all orders for a user
def get_all_orders():
# Get user from logged in cookie
userId = request.cookies.get('logged_in')
# Check if user is logged in
if userId is None:
return jsonify({"message": "You are not logged in"}), 401
# Get orders from database
cur = mysql.connection.cursor()
cur.execute('''SELECT user_order.order_id, user_order.order_date, user_order.total_amount, user_order.status FROM user_order WHERE user_id = %s''', (userId,))
ordersDb = cur.fetchall()
cur.close()
# Format orders
orders = []
for order in ordersDb:
orders.append({
"order_id": order[0],
"order_date": order[1].isoformat(),
"total_amount": order[2],
"status": order[3]
})
# Return orders
return jsonify(orders), 200
\ No newline at end of file
# idatg2204-project
# Electromart Database Implementation
## ElectroMart Website Database Implementation
This documentation will provide details about a simple backend implementation which is fully integrated with a relational database created in MariaDB.
Welcome to the ElectroMart Website Database Documentation!
- This documentation will provide details about a simple backend implementation which is fully integrated with a relational database created in MariaDB.
## Electromart
ElectroMart is an electronics store that sells a large variety of different electronic products.Product categories include phones, tablets, laptops, cameras, home
applications
# Deployment
The service can be hosted locally on your computer after running the code included in the `Backend` directory. The service can be accessed at the URL: `http://localhost:8080`
## Services being provided
## Homepage
http://localhost:8080/ Method = ["GET"]
## Category
http://localhost:8080/category Method = ["GET"]
http://localhost:8080/category/<string:category_name> Method = ["GET"]
## User
http://localhost:8080/register Method = ["POST"]
Example JSON data
```JSON
{
"firstname": "Ola",
"lastname": "Nordmann",
"address": "Tollbugata 2",
"email": "ola.nordmann@example.com",
"password": "Hemmelig"
}
```
What is ElectroMart?
- ElectroMart is an electronics store that sells a large variety of different electronic products.
- Example of some product categories that can be expected on the ElectroMart website:
- Phones
- Tablets
- laptops
- Cameras
- Home Appliances
- Various Electronic Gadgets
- etc.,
- ElectroMart aims to provide an efficient website experience for its users with focus on user friendliness
http://localhost:8080/login Method = ["POST"]
Example JSON data
```JSON
{
"email": "ola.nordmann@example.com",
"password": "Hemmelig"
}
```
http://localhost:8080/logout Method = ["POST"]
## Deployment
- This service can be hosted locally on a computer after running.
- After running the service on your computer you can access it through localhost with port: 8080
- http://localhost:8080/
## Product
http://localhost:8080/product Method = ["GET"]
## Services being provided
- Homepage
- http://localhost:8080/ Method = ["GET"]
- category
- http://localhost:8080/category Method = ["GET"]
- http://localhost:8080/category/<string:category_name Method = ["GET"]
- Login
- http://localhost:8080/login Method = ["POST"]
- Logout
- http://localhost:8080/logout Method = ["POST"]
- Register
- http://localhost:8080/Register Method = ["POST"]
- product
- http://localhost:8080/Product Method = ["GET"]
- http://localhost:8080/product/search/<string:search> Method = ["GET"]
- http://localhost:8080/product/<int:product_id> Method = ["GET"]
http://localhost:8080/product/search/<string:search> Method = ["GET"]
http://localhost:8080/product/<int:product_id> Method = ["GET"]
## Order
http://localhost:8080/order/ Method = ["GET"]
http://localhost:8080/order/ Method = ["POST"]
```JSON
{
"products": [
{"product_id": 1, "quantity": 2},
{"product_id": 2, "quantity": 1},
{"product_id": 3, "quantity": 3}
]
}
```
http://localhost:8080/order/payment Method = ["POST"]
```JSON
{
"order_id": 1,
"payment_method": "Vipps"
}
```
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment