|
@@ -1,6 +1,4 @@
|
|
|
import json
|
|
|
-from django.shortcuts import render
|
|
|
-from django.shortcuts import get_object_or_404
|
|
|
|
|
|
from rest_framework import viewsets
|
|
|
# Create your views here.
|
|
@@ -10,7 +8,7 @@ from rest_framework.parsers import JSONParser
|
|
|
from django.contrib.auth.models import User
|
|
|
from rest_framework import serializers
|
|
|
from rest_framework.response import Response
|
|
|
-
|
|
|
+from .models import UserProfile
|
|
|
|
|
|
from .serializer import UserProfileSerializer, UserSerializer
|
|
|
|
|
@@ -39,3 +37,24 @@ def user_details(request, pk):
|
|
|
return JsonResponse(serializer.data, safe=False)
|
|
|
except:
|
|
|
return JsonResponse({"error":"User does not exist"})
|
|
|
+
|
|
|
+def log_or_create(request, wallet):
|
|
|
+ if request.method == 'POST':
|
|
|
+ if UserProfile.objects.filter(wallet = wallet).exists():
|
|
|
+ queryset = UserProfile.objects.get(wallet = wallet)
|
|
|
+ queryset.visits += 1
|
|
|
+ queryset.save()
|
|
|
+ serializer = UserProfileSerializer(queryset)
|
|
|
+ return JsonResponse(serializer.data, safe=False)
|
|
|
+ else:
|
|
|
+ UserProfile.objects.create(wallet = wallet, user="NOT_SET", visits = 1)
|
|
|
+ queryset = UserProfile.objects.get(wallet = wallet)
|
|
|
+ serializer = UserProfileSerializer(queryset)
|
|
|
+ return JsonResponse(serializer.data, safe=False)
|
|
|
+ # verific daca exista cont+ chia wallet
|
|
|
+ # if exista return modelul userului
|
|
|
+ # altfel create si return model user
|
|
|
+ return JsonResponse({"error":"Work in progress"})
|
|
|
+
|
|
|
+
|
|
|
+#def change_name_user(request, wallet, nickname):
|