Skip to content

Commit

Permalink
Merge pull request #63 from Build-Squad/GEN-85.1-Continuation-Landing…
Browse files Browse the repository at this point in the history
…-Page

Integrating landing page with API
  • Loading branch information
Parikshit85 authored Jan 3, 2024
2 parents 87c8db0 + c066888 commit f5fcd08
Show file tree
Hide file tree
Showing 28 changed files with 534 additions and 211 deletions.
70 changes: 53 additions & 17 deletions src/api/marketplace/accounts/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,81 @@
from uuid import UUID

from core.serializers import LanguageMasterSerializer
from .models import AccountLanguage, TwitterAccount, CategoryMaster, AccountCategory, User, BankAccount, Role
from packages.models import Service
from .models import (
AccountLanguage,
TwitterAccount,
CategoryMaster,
AccountCategory,
User,
BankAccount,
Role,
)


class CategoryMasterSerializer(serializers.ModelSerializer):
class Meta:
model = CategoryMaster
fields = "__all__"


class AccountCategorySerializer(serializers.ModelSerializer):
category = CategoryMasterSerializer(read_only=True)

class Meta:
model = AccountCategory
fields = "__all__"


class CreateAccountCategorySerializer(serializers.ModelSerializer):
category_ids = serializers.ListField(
child=serializers.UUIDField(),
write_only=True
)
category_ids = serializers.ListField(child=serializers.UUIDField(), write_only=True)

class Meta:
model = AccountCategory
fields = ['category_ids']
fields = ["category_ids"]

def create(self, validated_data):
category_ids = validated_data.pop('category_ids', [])
twitter_account = self.context['request'].user_account.twitter_account
category_ids = validated_data.pop("category_ids", [])
twitter_account = self.context["request"].user_account.twitter_account
for category_id in category_ids:
AccountCategory.objects.get_or_create(
twitter_account=twitter_account, category_id=category_id)
twitter_account=twitter_account, category_id=category_id
)
return {"account_id": twitter_account, "category_ids": category_ids}


class DeleteAccountCategorySerializer(serializers.ModelSerializer):
account_category_ids = serializers.ListField(
child=serializers.UUIDField(),
write_only=True
child=serializers.UUIDField(), write_only=True
)

class Meta:
model = AccountCategory
fields = ['account_category_ids']
fields = ["account_category_ids"]


class TwitterAccountSerializer(serializers.ModelSerializer):
account_categories = AccountCategorySerializer(
source='cat_twitter_account_id', many=True, read_only=True)
source="cat_twitter_account_id", many=True, read_only=True
)
service_types = serializers.SerializerMethodField()

class Meta:
model = TwitterAccount
exclude = ("access_token", )
exclude = ("access_token",)

def get_service_types(self, twitter_account):
services = Service.objects.filter(
package__influencer__twitter_account=twitter_account
)

# Extract service types and prices
service_data = [
{"serviceType": service.service_master.name, "price": service.price}
for service in services
]

return service_data


class RoleSerializer(serializers.ModelSerializer):
Expand All @@ -69,15 +93,27 @@ class Meta:
model = AccountLanguage
fields = "__all__"


class UserSerializer(serializers.ModelSerializer):
twitter_account = TwitterAccountSerializer(read_only=True)
role = RoleSerializer(read_only=True)
account_languages = AccountLanguageSerializer(many=True, read_only=True, source='acc_user_account_id')
account_languages = AccountLanguageSerializer(
many=True, read_only=True, source="acc_user_account_id"
)

class Meta:
model = User
exclude = ("password", "otp", "otp_expiration", "is_superuser",
"is_staff", "is_active", "groups", "user_permissions", "jwt")
exclude = (
"password",
"otp",
"otp_expiration",
"is_superuser",
"is_staff",
"is_active",
"groups",
"user_permissions",
"jwt",
)


class UserCreateSerializer(serializers.ModelSerializer):
Expand Down
38 changes: 22 additions & 16 deletions src/api/marketplace/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,21 @@ def get(self, request, pk):
class TwitterAccountList(APIView):
def get(self, request):
try:
languages = request.GET.getlist("languages", [])
serviceTypes = request.GET.getlist("serviceTypes", [])
categories = request.GET.getlist("categories", [])
languages_string = request.GET.get("languages", "")
languages = languages_string.split(",") if languages_string else []

upperPriceLimit = request.GET.get("upperPriceLimit", None)
lowerPriceLimit = request.GET.get("lowerPriceLimit", None)
upperFollowerLimit = request.GET.get("upperFollowerLimit", None)
lowerFollowerLimit = request.GET.get("lowerFollowerLimit", None)
service_types_string = request.GET.get("serviceTypes", "")
serviceTypes = (
service_types_string.split(",") if service_types_string else []
)

categories_string = request.GET.get("categories", "")
categories = categories_string.split(",") if categories_string else []

upperPriceLimit = request.GET.get("upperPriceLimit", "")
lowerPriceLimit = request.GET.get("lowerPriceLimit", "")
upperFollowerLimit = request.GET.get("upperFollowerLimit", "")
lowerFollowerLimit = request.GET.get("lowerFollowerLimit", "")

searchString = request.GET.get("searchString", "")
isVerified_str = request.GET.get("isVerified", "false")
Expand All @@ -120,17 +127,17 @@ def get(self, request):
twitterAccount = TwitterAccount.objects.all()

# From the account model itself.
if upperFollowerLimit is not None:
if upperFollowerLimit or upperFollowerLimit.strip() != "":
twitterAccount = twitterAccount.filter(
followers_count__lte=upperFollowerLimit
)

if lowerFollowerLimit is not None:
if lowerFollowerLimit or lowerFollowerLimit.strip() != "":
twitterAccount = twitterAccount.filter(
followers_count__gte=lowerFollowerLimit
)

if searchString:
if searchString or searchString.strip() != "":
twitterAccount = twitterAccount.filter(
Q(user_name__icontains=searchString)
| Q(name__icontains=searchString)
Expand Down Expand Up @@ -180,7 +187,7 @@ def get(self, request):
id__in=twitter_accounts_to_exclude
)

if upperPriceLimit:
if upperPriceLimit or upperPriceLimit.strip() != "":
twitter_accounts_to_exclude = [
twitter_account.id
for twitter_account in twitterAccount
Expand All @@ -190,16 +197,16 @@ def get(self, request):
).exists()
or not Service.objects.filter(
package__influencer__twitter_account=twitter_account,
price__lte=upperPriceLimit
price__lte=upperPriceLimit,
).exists()
]

# Exclude undesired twitter accounts from the queryset
twitterAccount = twitterAccount.exclude(
id__in=twitter_accounts_to_exclude
)
if lowerPriceLimit:

if lowerPriceLimit or lowerPriceLimit.strip() != "":
twitter_accounts_to_exclude = [
twitter_account.id
for twitter_account in twitterAccount
Expand All @@ -209,7 +216,7 @@ def get(self, request):
).exists()
or not Service.objects.filter(
package__influencer__twitter_account=twitter_account,
price__gte=lowerPriceLimit
price__gte=lowerPriceLimit,
).exists()
]

Expand All @@ -218,7 +225,6 @@ def get(self, request):
id__in=twitter_accounts_to_exclude
)


# Paginate the results
pagination = Pagination(twitterAccount, request)
serializer = TwitterAccountSerializer(pagination.getData(), many=True)
Expand Down
41 changes: 37 additions & 4 deletions src/ui/app/business/components/banner/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";
import React from "react";
import { Box, Button, Grid, Typography } from "@mui/material";
import { Box, Button, Grid, Switch, Typography } from "@mui/material";
import { BannerFilterSchema, BannerFilterInitialValues } from "./validation";
import Image from "next/image";
import Arrow from "@/public/svg/Arrow.svg";
Expand All @@ -23,6 +23,7 @@ export default function Banner({}: Props) {
sx={{
border: "1px solid #000",
backgroundImage: "url(/Business_Landing_page.png)",
backgroundSize: "cover",
display: "flex",
alignItems: "center",
flexDirection: "column",
Expand Down Expand Up @@ -85,15 +86,40 @@ export default function Banner({}: Props) {
>
<form onSubmit={formik.handleSubmit}>
<Grid container spacing={2} justifyContent={"space-around"}>
<Grid item xs={4} sm={4} md={4} lg={4} sx={{ mb: 2 }}>
<Grid item xs={3} sm={3} md={3} lg={3} sx={{ mb: 2 }}>
<FiltersComponent formik={formik} type={"LANGUAGE"} />
</Grid>
<Grid item xs={4} sm={4} md={4} lg={4}>
<Grid item xs={3} sm={3} md={3} lg={3}>
<FiltersComponent formik={formik} type={"SERVICES"} />
</Grid>
<Grid item xs={4} sm={4} md={4} lg={4}>
<Grid item xs={3} sm={3} md={3} lg={3}>
<FiltersComponent formik={formik} type={"CATEGORIES"} />
</Grid>
<Grid
item
xs={3}
sm={3}
md={3}
lg={3}
sx={{
display: "flex",
alignItems: "center",
"&.MuiGrid-item": {
paddingTop: "0px",
},
}}
>
<Typography>Verified</Typography>
<Switch
color="secondary"
checked={formik.values.isVerified}
onChange={(e: any) => {
formik.setFieldValue("isVerified", e.target.checked);
}}
/>
</Grid>
</Grid>
<Grid container spacing={2} justifyContent={"space-around"}>
<Grid item xs={2.5} sm={2.5} md={2.5} lg={2.5}>
<FiltersComponent
formik={formik}
Expand Down Expand Up @@ -124,6 +150,13 @@ export default function Banner({}: Props) {
data={{ name: "upperPriceLimit", label: "Max. Followers" }}
/>
</Grid>
</Grid>
<Grid
container
spacing={2}
justifyContent={"space-around"}
sx={{ paddingTop: "16px" }}
>
<Grid item xs={12} sm={12} md={12} lg={12}>
<FiltersComponent formik={formik} type={"SEARCH"} />
</Grid>
Expand Down
2 changes: 2 additions & 0 deletions src/ui/app/business/components/banner/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface BannerFilterType {
upperFollowerLimit: number | null;
lowerFollowerLimit: number | null;
searchString: string;
isVerified: boolean;
}

const BannerFilterSchema = object({
Expand All @@ -28,6 +29,7 @@ const BannerFilterInitialValues: BannerFilterType = {
upperFollowerLimit: 50000,
lowerFollowerLimit: 0,
searchString: "",
isVerified: true,
};

export { BannerFilterSchema, BannerFilterInitialValues };
Loading

0 comments on commit f5fcd08

Please sign in to comment.