Skip to content

Commit

Permalink
Merge pull request #18 from Build-Squad/GEN-65-List-APIs-Core-Modals
Browse files Browse the repository at this point in the history
Add core URLs and views for Country and Currency
  • Loading branch information
muditmahajan authored Dec 1, 2023
2 parents 73eb9d0 + d5cb46d commit f0f433b
Show file tree
Hide file tree
Showing 22 changed files with 1,847 additions and 137 deletions.
10 changes: 10 additions & 0 deletions src/api/marketplace/core/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.urls import path
from .views import CountryListView, CountryDetailView, CurrencyListView, CurrencyDetailView

urlpatterns = [
path('country/', CountryListView.as_view()),
path('country/<str:pk>/', CountryDetailView.as_view()),

path('currency/', CurrencyListView.as_view()),
path('currency/<str:pk>/', CurrencyDetailView.as_view()),
]
88 changes: 86 additions & 2 deletions src/api/marketplace/core/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,87 @@
from django.shortcuts import render
from marketplace.services import Pagination, handleServerException, handleNotFound
from rest_framework.response import Response
from rest_framework import status
from rest_framework.views import APIView
from .models import Country, Currency
from django.db.models import Q
from .serializers import CountrySerializer, CurrencySerializer

# Create your views here.

class CountryListView(APIView):
def get(self, request, format=None):
try:
search = request.GET.get('search', None)
order_by = request.GET.get('order_by', None)
if search:
countries = Country.objects.filter(
Q(name__icontains=search) | Q(country_code__icontains=search))
else:
countries = Country.objects.all()
if order_by:
countries = countries.order_by(order_by)
pagination = Pagination(countries, request)
serializer = CountrySerializer(pagination.getData(), many=True)
return Response({
'isSuccess': True,
'data': serializer.data,
'message': 'All Countries retrieved successfully',
'pagination': pagination.getPageInfo()
}, status=status.HTTP_200_OK)
except Exception as e:
return handleServerException(e)


class CountryDetailView(APIView):
def get(self, request, pk, format=None):
try:
country = Country.objects.get(pk=pk)
serializer = CountrySerializer(country)
return Response({
'isSuccess': True,
'data': serializer.data,
'message': 'Country retrieved successfully'
}, status=status.HTTP_200_OK)
except Country.DoesNotExist:
return handleNotFound()
except Exception as e:
return handleServerException(e)


class CurrencyListView(APIView):
def get(self, request, format=None):
try:
search = request.GET.get('search', None)
order_by = request.GET.get('order_by', None)
if search:
currencies = Currency.objects.filter(
Q(name__icontains=search) | Q(symbol__icontains=search))
else:
currencies = Currency.objects.all()
if order_by:
currencies = currencies.order_by(order_by)
pagination = Pagination(currencies, request)
serializer = CurrencySerializer(pagination.getData(), many=True)
return Response({
'isSuccess': True,
'data': serializer.data,
'message': 'All Currencies retrieved successfully',
'pagination': pagination.getPageInfo()
}, status=status.HTTP_200_OK)
except Exception as e:
return handleServerException(e)


class CurrencyDetailView(APIView):
def get(self, request, pk, format=None):
try:
currency = Currency.objects.get(pk=pk)
serializer = CurrencySerializer(currency)
return Response({
'isSuccess': True,
'data': serializer.data,
'message': 'Currency retrieved successfully'
}, status=status.HTTP_200_OK)
except Currency.DoesNotExist:
return handleNotFound()
except Exception as e:
return handleServerException(e)
2 changes: 2 additions & 0 deletions src/api/marketplace/marketplace/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
name="schema-swagger-ui",
),
path("admin/", admin.site.urls),
path('packages/', include('packages.urls'), name='packages'),
path('core/', include('core.urls'), name='core'),
path('packages/', include('packages.urls')),
path('orders/', include('orders.urls')),
path('account/', include('accounts.urls')),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 4.2.7 on 2023-11-30 09:46

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


class Migration(migrations.Migration):

dependencies = [
('packages', '0003_service_deleted_at'),
]

operations = [
migrations.AlterField(
model_name='service',
name='package',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, related_name='service_package_id', to='packages.package'),
),
migrations.AlterField(
model_name='service',
name='service_master',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, related_name='service_master_id', to='packages.servicemaster'),
),
]
19 changes: 17 additions & 2 deletions src/ui/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
"use client";

import type { Metadata } from "next";
import { Inter } from "next/font/google";
import "./globals.css";
import ThemeRegistry from "./ThemeRegistry";
import { SnackbarProvider } from "notistack";

const inter = Inter({ subsets: ["latin"] });

export const metadata: Metadata = {
const metadata: Metadata = {
title: "Influencer Marketplace",
description: "Influencer Marketplace",
};
Expand All @@ -18,7 +21,19 @@ export default function RootLayout({
return (
<html lang="en">
<body className={inter.className}>
<ThemeRegistry options={{ key: "mui-theme" }}>{children}</ThemeRegistry>
<SnackbarProvider
maxSnack={5}
autoHideDuration={2000}
anchorOrigin={{
vertical: "top",
horizontal: "right",
}}
preventDuplicate
>
<ThemeRegistry options={{ key: "mui-theme" }}>
{children}
</ThemeRegistry>
</SnackbarProvider>
</body>
</html>
);
Expand Down
19 changes: 17 additions & 2 deletions src/ui/app/profile/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";

import { Box, Grid, Typography, Tabs, Tab } from "@mui/material";
import { useRouter } from "next/navigation";
import { useRouter, useSearchParams, usePathname } from "next/navigation";
import React, { useEffect } from "react";

const tabs = [
Expand All @@ -18,9 +18,24 @@ const tabs = [
const ProfileLayout = ({ children }: { children: React.ReactNode }) => {
const [tab, setTab] = React.useState<string>("services");
const router = useRouter();
const pathname = usePathname();
const seearchParams = useSearchParams();

useEffect(() => {
router.push(`/profile/${tab}`);
const urlTab = pathname.split("/")[2]; // assuming the tab is the third part of the URL
if (urlTab && tabs.some((t) => t.value === urlTab)) {
if (urlTab !== tab) {
setTab(urlTab);
}
} else {
setTab(tabs[0].value);
}
}, [pathname, router]);

useEffect(() => {
if (tab) {
router.push(`/profile/${tab}`);
}
}, [tab]);

return (
Expand Down
Loading

0 comments on commit f0f433b

Please sign in to comment.