| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Artifacts is an e-commerce site, themed around time travelers selling artifacts from across time.
https://artifacts-app.herokuapp.com/
The team needed to decide on logic for adding an item to the cart, if the cart already contained that item
# If the item does not exist, add it to the database
if cart_item is None:
item = ShoppingCartItem()
item.userId = data['userId']
item.productId = data['productId']
item.quantity = data['quantity']
db.session.add(item)
db.session.commit()
return item.to_dict()
# If item does exist update quantity
else:
cart_item.quantity += data['quantity']
db.session.add(cart_item)
db.session.commit()
return cart_item.to_dict()The team needed to decide on where to save cart data. With help from the instructional staff, the team discussed choices:
The team needed to decide on logic on the shopping cart:
try:
for item in cart_items:
curr_product = Product.query.get(item['productId'])
if curr_product is None:
errors.append('Product no longer exists')
elif item['quantity'] > curr_product.quantity:
errors.append('Not enough inventory in store')
list_of_data.append(
(curr_product,
item['quantity'] if curr_product is not None else None)
)
order.products.append(curr_product)
# process order after for loop
if errors:
raise ValueError(errors)
db.session.add(order)
# update quantity of each product
for data in list_of_data:
data[0].quantity -= data[1]
db.session.add(data[0])
# clear shopping cart
shopping_cart_items = ShoppingCartItem.query.filter(ShoppingCartItem.userId == userId).all()
for item in shopping_cart_items:
db.session.delete(item)
db.session.commit()
return jsonify([])
except ValueError:
return jsonify(errors)The team had trouble with certain routes, that would function in the development environment, but not the production environment. With the help of instructional staff, it was found that in the development environment, Flask would redirect "/route" to "/route/" via a HTTP request. In the production environment, Flask's HTTP request would not be allowed as HTTPS is required. This issue was resolved by specifying the correct strings for routes.
The team had trouble showing the site logo in the production environment, while there were no issues in the development environment. With the help of instructional staff, it was found that the logo image was best imported into a component. Link to outside resource for the syntax: https://create-react-app.dev/docs/adding-images-fonts-and-files/
| Back | FazBrowse Home | New Git URL |