Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…etplace into GEN-97-Twitter-Account-Details-API
  • Loading branch information
Parikshit85 committed Jan 3, 2024
2 parents b92d030 + 70dc833 commit 992df3f
Show file tree
Hide file tree
Showing 19 changed files with 386 additions and 124 deletions.
16 changes: 15 additions & 1 deletion src/api/marketplace/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Meta:
db_table = "twitter_account"

def __str__(self):
return self.name
return self.user_name

class CategoryMaster(models.Model):
id = models.UUIDField(primary_key=True, verbose_name='Category Master ID', default=uuid.uuid4, editable=False)
Expand All @@ -38,6 +38,9 @@ class CategoryMaster(models.Model):
class Meta:
db_table = "category_master"

def __str__(self):
return self.name

class AccountCategory(models.Model):
id = models.UUIDField(primary_key=True, verbose_name='Account Category ID', default=uuid.uuid4, editable=False)
twitter_account = models.ForeignKey(TwitterAccount, related_name='cat_twitter_account_id', on_delete=SET_NULL,
Expand All @@ -57,6 +60,9 @@ class Role(models.Model):
class Meta:
db_table = "role"

def __str__(self):
return self.name

class User(AbstractUser):

STATUS_CHOICES = (
Expand Down Expand Up @@ -126,12 +132,17 @@ class WalletProvider(models.Model):
primary_key=True, verbose_name='Wallet Provider ID', default=uuid.uuid4, editable=False)
wallet_provider = models.CharField(max_length=100, blank=True, null=True)

def __str__(self):
return self.wallet_provider

class WalletNetwork(models.Model):
id = models.UUIDField(
primary_key=True, verbose_name='Wallet Network ID', default=uuid.uuid4, editable=False)
wallet_network = models.CharField(max_length=100, blank=True, null=True)

def __str__(self):
return self.wallet_network


class Wallet(models.Model):
id = models.UUIDField(
Expand All @@ -144,3 +155,6 @@ class Wallet(models.Model):
WalletProvider, related_name='wallet_provider_id', on_delete=SET_NULL, null=True)
is_primary = models.BooleanField(default=True, blank=True, null=True)
wallet_address_id = models.CharField(max_length=255, blank=True, null=True)

def __str__(self):
return self.wallet_address_id
4 changes: 2 additions & 2 deletions src/api/marketplace/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ def post(self, request):
)
response.data = {
"isSuccess": True,
"data": None,
"data": UserSerializer(user).data,
"message": "Logged in successfully",
}
response.status_code = status.HTTP_200_OK
Expand Down Expand Up @@ -1262,7 +1262,7 @@ def post(self, request):
)
response.data = {
"isSuccess": True,
"data": None,
"data": UserSerializer(user).data,
"message": "Logged in successfully",
}
response.status_code = status.HTTP_200_OK
Expand Down
9 changes: 9 additions & 0 deletions src/api/marketplace/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ class Country(models.Model):
class Meta:
db_table = "country"

def __str__(self):
return self.name


class Currency(models.Model):
id = models.UUIDField(primary_key=True, verbose_name='Currency', default=uuid.uuid4, editable=False)
Expand All @@ -22,6 +25,9 @@ class Currency(models.Model):
class Meta:
db_table = "currency"

def __str__(self):
return self.name


class LanguageMaster(models.Model):
id = models.UUIDField(primary_key=True, verbose_name='Language Master', default=uuid.uuid4, editable=False)
Expand All @@ -31,3 +37,6 @@ class LanguageMaster(models.Model):

class Meta:
db_table = "language_master"

def __str__(self):
return self.langEnglishName
6 changes: 6 additions & 0 deletions src/api/marketplace/marketplace/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.shortcuts import redirect, render
from accounts.serializers import UserSerializer
from tweepy import Client, OAuth2UserHandler
from django.http import (
JsonResponse,
Expand Down Expand Up @@ -187,6 +188,11 @@ def createJWT(userData, access_token):
response = JWTOperations.setJwtToken(
response, cookie_name="jwt", payload=payload
)
response.data = {
"isSuccess": True,
"data": UserSerializer(current_user).data,
"message": "Logged in successfully",
}
logger.info("JWT created successfully")
return response
except Exception as e:
Expand Down
3 changes: 2 additions & 1 deletion src/api/marketplace/packages/admin.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from django.contrib import admin

from .models import Package, ServiceMaster, Service
from .models import Package, ServiceMaster, Service, ServiceMasterMetaData

# Register your models here.
admin.site.register(Package)
admin.site.register(ServiceMaster)
admin.site.register(Service)
admin.site.register(ServiceMasterMetaData)
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Generated by Django 4.2.7 on 2023-12-28 11:43

from django.db import migrations, models
import django.db.models.deletion
import uuid


class Migration(migrations.Migration):

dependencies = [
('packages', '0007_remove_service_is_duration_based_and_more'),
]

operations = [
migrations.CreateModel(
name='ServiceMasterMetaData',
fields=[
('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False, verbose_name='ServiceMasterMetaData')),
('field_name', models.CharField(blank=True, max_length=100, null=True)),
('label', models.CharField(blank=True, max_length=100, null=True)),
('placeholder', models.CharField(blank=True, max_length=100, null=True)),
('min', models.CharField(blank=True, max_length=100, null=True)),
('max', models.CharField(blank=True, max_length=100, null=True)),
('span', models.IntegerField(blank=True, null=True)),
('field_type', models.CharField(choices=[('text', 'text'), ('long_text', 'long_text'), ('date_time', 'date_time'), ('media', 'media')], default='text', max_length=50)),
('service_master_id', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='service_master_meta_data_id', to='packages.servicemaster')),
],
options={
'db_table': 'service_master_meta_data',
},
),
]
37 changes: 35 additions & 2 deletions src/api/marketplace/packages/models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from datetime import *
from django.utils import timezone
from unicodedata import name
from django.db import models
import uuid
from django.contrib.auth import get_user_model
from django.contrib.auth.models import User
from django.db.models import SET_NULL
from django.conf import settings
Expand Down Expand Up @@ -44,6 +42,9 @@ def delete (self, *args, **kwargs):
self.deleted_at = timezone.now()
self.save()

def __str__(self):
return self.name

class ServiceMaster(models.Model):

TYPE_CHOICES = (
Expand All @@ -70,6 +71,9 @@ def delete (self, *args, **kwargs):
self.deleted_at = timezone.now()
self.save()

def __str__(self):
return self.name

class Service(models.Model):
id = models.UUIDField(primary_key=True, verbose_name='Service', default=uuid.uuid4, editable=False)
service_master = models.ForeignKey(ServiceMaster, related_name='service_master_id', on_delete=SET_NULL, null=True)
Expand All @@ -88,3 +92,32 @@ class Meta:
def delete (self, *args, **kwargs):
self.deleted_at = timezone.now()
self.save()

def __str__(self):
return self.package.name


class ServiceMasterMetaData(models.Model):

TYPE_CHOICES = (
('text', 'text'),
('long_text', 'long_text'),
('date_time', 'date_time'),
('media', 'media'),
)

id = models.UUIDField(
primary_key=True, verbose_name='ServiceMasterMetaData', default=uuid.uuid4, editable=False)
field_name = models.CharField(max_length=100, blank=True, null=True)
label = models.CharField(max_length=100, blank=True, null=True)
placeholder = models.CharField(max_length=100, blank=True, null=True)
min = models.CharField(max_length=100, blank=True, null=True)
max = models.CharField(max_length=100, blank=True, null=True)
span = models.IntegerField(blank=True, null=True)
field_type = models.CharField(choices=TYPE_CHOICES,
max_length=50, default='text')
service_master_id = models.ForeignKey(
ServiceMaster, related_name='service_master_meta_data_id', on_delete=models.SET_NULL, null=True)

class Meta:
db_table = "service_master_meta_data"
9 changes: 8 additions & 1 deletion src/api/marketplace/packages/serializers.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
# import serializers
from locale import currency
from rest_framework import serializers
from .models import ServiceMaster, Service, Package
from .models import ServiceMaster, Service, Package, ServiceMasterMetaData
from core.serializers import CurrencySerializer
from uuid import UUID


class ServiceMasterMetaDataSerilizer(serializers.ModelSerializer):
class Meta:
model = ServiceMasterMetaData
fields = '__all__'

class ServiceMasterSerializer(serializers.ModelSerializer):
service_master_meta_data = ServiceMasterMetaDataSerilizer(
source='service_master_meta_data_id', many=True, read_only=True)
class Meta:
model = ServiceMaster
fields = '__all__'
Expand Down
85 changes: 63 additions & 22 deletions src/ui/app/components/navbar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,77 @@
import React, { useEffect } from "react";
import React, { useEffect, useState } from "react";
import { Toolbar, AppBar, Button, Box } from "@mui/material";
import Image from "next/image";
import { useRouter, usePathname } from "next/navigation";
import { useRouter, usePathname, useSearchParams } from "next/navigation";
import LoginMenu from "../loginMenu";
import useTwitterAuth from "@/src/hooks/useTwitterAuth";
import { LOGIN_STATUS_SUCCESS, LOGIN_STATUS_FAILED } from "@/src/utils/consts";
import { loginStatusType } from "@/app/utils/types";
import { useAppSelector } from "@/src/hooks/useRedux";

type Props = {
authUser: () => {};
logout: () => {};
loginStatus: Boolean;
type NavbarProps = {
setLoginStatus: React.Dispatch<React.SetStateAction<loginStatusType>>;
setEmailOpen: React.Dispatch<React.SetStateAction<boolean>>;
setWalletOpen: React.Dispatch<React.SetStateAction<boolean>>;
setCategoryOpen: React.Dispatch<React.SetStateAction<boolean>>;
emailOpen: boolean;
walletOpen: boolean;
};

export default function Navbar({
authUser,
logout,
loginStatus,
setLoginStatus,
setEmailOpen,
setWalletOpen,
}: Props) {
setCategoryOpen,
emailOpen,
walletOpen,
}: NavbarProps) {
const {
isTwitterUserLoggedIn,
startTwitterAuthentication,
logoutTwitterUser,
checkTwitterUserAuthentication,
isAccountSsetupComplete,
} = useTwitterAuth();
const router = useRouter();
const pathname = usePathname();
const [currentUser, setCurrentUser] = React.useState<UserType | null>(null);
const currentUser = useAppSelector((state) => state.user?.user);
// const [currentUser, setCurrentUser] = React.useState<UserType | null>(null);

const params = useSearchParams();

useEffect(() => {
if (!emailOpen) {
checkTwitterUserAuthentication();
}
}, [emailOpen]);

useEffect(() => {
if (!walletOpen) {
checkTwitterUserAuthentication();
}
}, [walletOpen]);

useEffect(() => {
const status = params.get("authenticationStatus");
if (status) {
setLoginStatus({
status,
message:
status == "success" ? LOGIN_STATUS_SUCCESS : LOGIN_STATUS_FAILED,
});
}
}, [isTwitterUserLoggedIn]);

useEffect(() => {
if (loginStatus) {
const user = localStorage.getItem("user");
if (user) {
setCurrentUser(JSON.parse(user));
}
const status = params.get("authenticationStatus");
if (
isTwitterUserLoggedIn &&
!isAccountSsetupComplete &&
status === "success"
) {
setCategoryOpen(true);
}
}, [loginStatus]);
}, [isTwitterUserLoggedIn, isAccountSsetupComplete]);

return (
<AppBar position="static" sx={{ boxShadow: "none" }}>
Expand All @@ -46,7 +87,7 @@ export default function Navbar({
alt="bgimg"
/>
</Box>
{loginStatus ? null : (
{isTwitterUserLoggedIn ? null : (
<Box
sx={{
display: "flex",
Expand Down Expand Up @@ -102,7 +143,7 @@ export default function Navbar({
<Button color="inherit" sx={{ fontSize: "16px" }}>
About
</Button>
{loginStatus ? (
{isTwitterUserLoggedIn ? (
<>
{pathname.includes("business") ? null : (
<Button
Expand All @@ -128,7 +169,7 @@ export default function Navbar({
},
}}
onClick={() => {
logout();
logoutTwitterUser();
if (pathname.includes("influencer")) {
router.push("/influencer");
} else if (pathname.includes("business")) {
Expand All @@ -153,14 +194,14 @@ export default function Navbar({
border: "1px solid black",
borderRadius: "20px",
}}
onClick={authUser}
onClick={startTwitterAuthentication}
>
Login
</Button>
) : (
<>
<LoginMenu
twitterLogin={authUser}
twitterLogin={startTwitterAuthentication}
setEmailOpen={setEmailOpen}
setWalletOpen={setWalletOpen}
/>
Expand Down
Loading

0 comments on commit 992df3f

Please sign in to comment.