Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eng 245 Do not show interactive UI #336

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
58 changes: 57 additions & 1 deletion src/api/marketplace/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,63 @@ class Meta:

def __str__(self):
return self.username



class UserGuideMaster(models.Model):
GUIDE_CHOICES = (("BUSINESS_CHECKOUT", "BUSINESS_CHECKOUT"),
("BUSINESS_DASHBOARD", "BUSINESS_DASHBOARD"),
("BUSINESS_MESSAGE", "BUSINESS_MESSAGE"),
("INFLUENCER_PROFILE", "INFLUENCER_PROFILE"),
("INFLUENCER_ORDERS", "INFLUENCER_ORDERS"),
("INFLUENCER_DASHBOARD", "INFLUENCER_DASHBOARD"),
("INFLUENCER_MESSAGE", "INFLUENCER_MESSAGE"),
)
id = models.UUIDField(
primary_key=True,
verbose_name="User Guide Master ID",
default=uuid.uuid4,
editable=False,
)
name = models.CharField(max_length=255, blank=True, null=True)

key = models.CharField(
choices=GUIDE_CHOICES, max_length=25
)

class Meta:
db_table = "user_guide_master"

def __str__(self):
return self.key


class UserGuide(models.Model):
id = models.UUIDField(
primary_key=True,
verbose_name="User Guide ID",
default=uuid.uuid4,
editable=False,
)
user_account = models.ForeignKey(
User,
related_name="user_guide_user_account",
on_delete=SET_NULL,
null=True,
blank=True,
)
user_guide_master = models.ForeignKey(
UserGuideMaster,
related_name="user_guide_master",
on_delete=SET_NULL,
null=True,
blank=True,
)
dont_show_again = models.BooleanField(default=False, blank=True, null=True)

class Meta:
db_table = "user_guide"


class CategoryMaster(models.Model):
CATEGORY_CHOICES = (("custom", "custom"), ("standard", "standard"))
id = models.UUIDField(
Expand Down
3 changes: 2 additions & 1 deletion src/api/marketplace/accounts/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
AccountCategoryList,
AccountCategoryDetail,
TwitterPromotionView,
UserGuideDetail,
UserList,
UserDetail,
BankAccountList,
Expand Down Expand Up @@ -60,7 +61,7 @@
path("user/", UserList.as_view(), name="user-list"),
path("user/<uuid:pk>/", UserDetail.as_view(), name="user-detail"),


path("user-guide/", UserGuideDetail.as_view(), name="user-guide-detail"),

path("business-meta-data/<uuid:userId>/", BusinessAccountMetaDataDetail.as_view(), name="business-account-meta-data-detail"),

Expand Down
76 changes: 76 additions & 0 deletions src/api/marketplace/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
User,
BankAccount,
Role,
UserGuide,
UserGuideMaster,
Wallet,
WalletNetwork,
WalletNonce,
Expand Down Expand Up @@ -616,6 +618,80 @@ def post(self, request):
except Exception as e:
return handleServerException(e)

class UserGuideDetail(APIView):
def get_or_create_user_guide(self, key, user_account):
try:
user_guide_master = UserGuideMaster.objects.get(key=key)
user_guide = UserGuide.objects.filter(
user_account=user_account,
user_guide_master=user_guide_master
)

if user_guide.exists():
return user_guide.first()
else:
return UserGuide.objects.create(
user_account=user_account,
user_guide_master=user_guide_master,
)
except Exception as e:
return None


authentication_classes = [JWTAuthentication]
def get(self, request):
try:
master_key = request.GET.get("master_key", "")
user_account = request.user_account

user_guide = UserGuide.objects.filter(
user_guide_master__key=master_key,
user_account=user_account
).first()

dont_show_again = None
if user_guide:
dont_show_again = user_guide.dont_show_again
else:
dont_show_again = False

return Response(
{
"isSuccess": True,
"data": {
"dont_show_again": dont_show_again,
},
"message": "User Guide retrieved successfully",
},
status=status.HTTP_200_OK,
)

except Exception as e:
return handleServerException(e)

authentication_classes = [JWTAuthentication]
def post(self, request):
try:
do_not_show_again = request.data.get("do_not_show_again", None)
key = request.data.get("key", None)
user_account = request.user_account

if key:
user_guide = self.get_or_create_user_guide(key, user_account)
user_guide.dont_show_again = do_not_show_again
user_guide.save()

return Response(
{
"isSuccess": True,
"data": None,
"message": "User guide updated successfully.",
}
)

except Exception as e:
return handleServerException(e)


# Account Category API-Endpoint
# List-Create-API
Expand Down
Loading