Explorar el Código

added endpoint for change username

Apostol Mihai hace 2 años
padre
commit
efc2cf4106

+ 3 - 3
NFTmarket/NFTmarket/settings.py

@@ -137,6 +137,6 @@ STATIC_URL = 'static/'
 
 DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
 
-STATICFILES_DIRS = [
-    os.path.join(BASE_DIR, 'static'),
-]
+#STATICFILES_DIRS = [
+#    os.path.join(BASE_DIR, 'static'),
+#]

+ 2 - 1
NFTmarket/NFTmarket/urls.py

@@ -19,7 +19,7 @@ from django.urls import include, path
 
 from rest_framework import routers
 
-from userprofile.views import (user_list, user_details, log_or_create)
+from userprofile.views import (user_list, user_details, log_or_create, change_username)
 
 router = routers.DefaultRouter()
 
@@ -33,4 +33,5 @@ urlpatterns = [
     path('userlist/', user_list, name='user-list'),
     #path('userdetails/<int:pk>', user_details, name='user-details'),
     path('userdetails/<str:wallet>', log_or_create, name='user-details'),
+    path('changeusername/<str:wallet>/<str:nickname>', change_username, name="change_username")
 ]

+ 8 - 1
NFTmarket/userprofile/views.py

@@ -57,4 +57,11 @@ def log_or_create(request, wallet):
     return JsonResponse({"error":"Work in progress"})
 
 
-#def change_name_user(request, wallet, nickname):
+def change_username(request, wallet, nickname):
+    if request.method == 'POST':
+        if UserProfile.objects.filter(wallet = wallet).exists():
+            queryset = UserProfile.objects.get(wallet = wallet)
+            queryset.user = nickname
+            queryset.save()
+            serializer = UserProfileSerializer(queryset)
+            return JsonResponse(serializer.data, safe=False)