Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TDDD27_2024
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Marc Taylor
TDDD27_2024
Commits
edceeb7f
Commit
edceeb7f
authored
9 months ago
by
Marc Taylor
Browse files
Options
Downloads
Patches
Plain Diff
rm console logs, add functionality frontend to add Order and Orderitems
parent
725ddbd3
No related branches found
Branches containing commit
No related tags found
1 merge request
!14
Orders
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
mysite/themeApp/views.py
+2
-2
2 additions, 2 deletions
mysite/themeApp/views.py
theme-costume-app/src/Profile.js
+0
-4
0 additions, 4 deletions
theme-costume-app/src/Profile.js
theme-costume-app/src/utils/api.js
+44
-2
44 additions, 2 deletions
theme-costume-app/src/utils/api.js
with
46 additions
and
8 deletions
mysite/themeApp/views.py
+
2
−
2
View file @
edceeb7f
...
...
@@ -156,7 +156,7 @@ class ProductView(APIView):
class
OrderView
(
APIView
):
permission_classes
=
[
permissions
.
IsA
dminUser
]
permission_classes
=
[
permissions
.
IsA
uthenticated
]
def
get
(
self
,
request
):
orders
=
Order
.
objects
.
all
()
...
...
@@ -186,7 +186,7 @@ class OrderItemView(APIView):
order_item
=
OrderItem
(
order_id
=
order
,
product_id
=
product
,
orderType
=
data
[
'
order
_t
ype
'
],
orderType
=
data
[
'
order
T
ype
'
],
days
=
data
[
'
days
'
]
)
order_item
.
save
()
...
...
This diff is collapsed.
Click to expand it.
theme-costume-app/src/Profile.js
+
0
−
4
View file @
edceeb7f
...
...
@@ -146,7 +146,6 @@ const [loadingUser, setLoadingUser] = useState(true);
const
fetchUser
=
async
()
=>
{
try
{
const
result
=
await
getLoggedInUser
();
console
.
log
(
'
userrrr:
'
,
result
.
id
);
setUser
(
result
.
id
);
// You can perform additional actions here, like updating the UI
}
catch
(
error
)
{
...
...
@@ -164,12 +163,9 @@ const [loadingUser, setLoadingUser] = useState(true);
const
fetchProducts
=
async
()
=>
{
try
{
const
result
=
await
getAllProducts
();
console
.
log
(
'
All Products:
'
,
result
);
if
(
user
)
{
console
.
log
(
'
User ID:
'
,
user
);
const
filteredProducts
=
result
.
data
.
filter
(
product
=>
product
.
user_id
===
user
);
console
.
log
(
'
Filtered Products:
'
,
filteredProducts
);
setProducts
(
filteredProducts
);
}
else
{
console
.
warn
(
'
User ID is null or undefined
'
);
...
...
This diff is collapsed.
Click to expand it.
theme-costume-app/src/utils/api.js
+
44
−
2
View file @
edceeb7f
...
...
@@ -47,7 +47,6 @@ export const addProduct = async (img, price, rentPrice, name, size, userID) => {
'
Authorization
'
:
`Bearer
${
TOKEN
}
`
},
});
console
.
log
(
'
Added product successfully:
'
,
response
.
data
);
return
response
.
status
}
catch
(
error
)
{
console
.
error
(
'
Error in adding product:
'
,
error
)
...
...
@@ -105,4 +104,47 @@ export const getAllProducts = async () => {
console
.
log
(
'
not auth
'
,
e
)
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
);
}
}
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