Skip to content
Snippets Groups Projects
Commit edceeb7f authored by Marc Taylor's avatar Marc Taylor
Browse files

rm console logs, add functionality frontend to add Order and Orderitems

parent 725ddbd3
Branches orders
No related tags found
1 merge request!14Orders
...@@ -156,7 +156,7 @@ class ProductView(APIView): ...@@ -156,7 +156,7 @@ class ProductView(APIView):
class OrderView(APIView): class OrderView(APIView):
permission_classes = [permissions.IsAdminUser] permission_classes = [permissions.IsAuthenticated]
def get(self, request): def get(self, request):
orders = Order.objects.all() orders = Order.objects.all()
...@@ -186,7 +186,7 @@ class OrderItemView(APIView): ...@@ -186,7 +186,7 @@ class OrderItemView(APIView):
order_item = OrderItem( order_item = OrderItem(
order_id=order, order_id=order,
product_id=product, product_id=product,
orderType=data['order_type'], orderType=data['orderType'],
days=data['days'] days=data['days']
) )
order_item.save() order_item.save()
......
...@@ -146,7 +146,6 @@ const [loadingUser, setLoadingUser] = useState(true); ...@@ -146,7 +146,6 @@ const [loadingUser, setLoadingUser] = useState(true);
const fetchUser = async () => { const fetchUser = async () => {
try { try {
const result = await getLoggedInUser(); const result = await getLoggedInUser();
console.log('userrrr:', result.id);
setUser(result.id); setUser(result.id);
// You can perform additional actions here, like updating the UI // You can perform additional actions here, like updating the UI
} catch (error) { } catch (error) {
...@@ -164,12 +163,9 @@ const [loadingUser, setLoadingUser] = useState(true); ...@@ -164,12 +163,9 @@ const [loadingUser, setLoadingUser] = useState(true);
const fetchProducts = async () => { const fetchProducts = async () => {
try { try {
const result = await getAllProducts(); const result = await getAllProducts();
console.log('All Products:', result);
if (user) { if (user) {
console.log('User ID:', user);
const filteredProducts = result.data.filter(product => product.user_id === user); const filteredProducts = result.data.filter(product => product.user_id === user);
console.log('Filtered Products:', filteredProducts);
setProducts(filteredProducts); setProducts(filteredProducts);
} else { } else {
console.warn('User ID is null or undefined'); console.warn('User ID is null or undefined');
......
...@@ -47,7 +47,6 @@ export const addProduct = async (img, price, rentPrice, name, size, userID) => { ...@@ -47,7 +47,6 @@ export const addProduct = async (img, price, rentPrice, name, size, userID) => {
'Authorization': `Bearer ${TOKEN}` 'Authorization': `Bearer ${TOKEN}`
}, },
}); });
console.log('Added product successfully:', response.data);
return response.status return response.status
} catch (error) { } catch (error) {
console.error('Error in adding product:', error) console.error('Error in adding product:', error)
...@@ -105,4 +104,47 @@ export const getAllProducts = async () => { ...@@ -105,4 +104,47 @@ export const getAllProducts = async () => {
console.log('not auth', e) console.log('not auth', e)
return false; return false;
} }
} }
\ No newline at end of file
export const createOrder = async (totalPrice) => {
const user = await getLoggedInUser();
try {
const result = await axios.post('http://127.0.0.1:8000/themeApp/order/', {
'user_id': user.id,
'total_price': totalPrice,
},{
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${TOKEN}`
}
});
console.log('Result: ', result);
return result;
} catch (e) {
console.error('Error: ', e)
}
}
// createOrder(170);
export const orderItem = async (orderID, productID, orderType, days=0) => {
try {
const result = await axios.post(`${API_BASE_URL}/themeApp/orderItem/`, {
'order_id': orderID,
'product_id': productID,
'orderType': orderType,
'days': days,
}, {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${TOKEN}`,
}
}
);
console.log('orderItem result:', result);
return result
} catch (e) {
console.error('Error: ', e);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment