devnamdev2003 commited on
Commit ·
2bb9fdd
1
Parent(s): 037a72d
uodated
Browse files- api/urls.py +1 -1
- api/views.py +8 -2
api/urls.py
CHANGED
|
@@ -3,6 +3,6 @@ from .views import UserDataPostView, GetFieldView, ContactList1
|
|
| 3 |
|
| 4 |
urlpatterns = [
|
| 5 |
path("post/", UserDataPostView.as_view(), name="post_user_data"),
|
| 6 |
-
path("<str:field>/<str:
|
| 7 |
path('contact/', ContactList1.as_view()),
|
| 8 |
]
|
|
|
|
| 3 |
|
| 4 |
urlpatterns = [
|
| 5 |
path("post/", UserDataPostView.as_view(), name="post_user_data"),
|
| 6 |
+
path("<str:field>/<str:identifier>/", GetFieldView.as_view(), name="get_field_data"),
|
| 7 |
path('contact/', ContactList1.as_view()),
|
| 8 |
]
|
api/views.py
CHANGED
|
@@ -57,8 +57,14 @@ class UserDataPostView(APIView):
|
|
| 57 |
|
| 58 |
|
| 59 |
class GetFieldView(APIView):
|
| 60 |
-
def get(self, request, field,
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
if field == "all":
|
| 63 |
data = {
|
| 64 |
"userData": obj.user_data,
|
|
|
|
| 57 |
|
| 58 |
|
| 59 |
class GetFieldView(APIView):
|
| 60 |
+
def get(self, request, field, identifier):
|
| 61 |
+
# identifier can be user_id OR data_backup_key
|
| 62 |
+
obj = UserData.objects.filter(user_id=identifier).first() \
|
| 63 |
+
or UserData.objects.filter(data_backup_key=identifier).first()
|
| 64 |
+
|
| 65 |
+
if not obj:
|
| 66 |
+
return Response({"error": "User not found"}, status=404)
|
| 67 |
+
|
| 68 |
if field == "all":
|
| 69 |
data = {
|
| 70 |
"userData": obj.user_data,
|