Skip to content

Commit e8a025a

Browse files
committed
refactor: improved urls
1 parent d65b0f0 commit e8a025a

10 files changed

Lines changed: 33 additions & 32 deletions

File tree

server/exception.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class CustomAttributeException(AttributeError):
4747
def __init__(self, message):
4848
super().__init__(message)
4949

50+
5051
class DataNotFoundException(Exception):
5152
def __init__(self, message):
5253
super().__init__(message)

server/fields.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,3 @@ def to_representation(self, images):
2828
media=images.first().get_image()
2929
)
3030
return None
31-
32-
33-
class MainImagesURLField(CharField):
34-
def to_representation(self, images):
35-
pass

server/router.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from rest_framework.routers import DefaultRouter
2+
3+
router = DefaultRouter()

server/urls/__init__.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,36 @@
11
from django.contrib import admin
22
from django.conf.urls.static import static
3-
from django.urls import path
3+
from django.urls import path, include
44

55
from debug_toolbar.toolbar import debug_toolbar_urls
66

7-
from server.urls.auth import auth_urlpatterns
7+
from server.urls.auth import (
8+
auth_urlpatterns,
9+
jwt_urlpatterns
10+
)
811
from server.urls.category import category_urlpatterns
912
from server.urls.product import product_urlpatterns
1013
from server.urls.swagger import swagger_urlpatterns
1114
from server.urls.banner import banner_urlpatterns
1215
from server.urls.country import country_urlpatterns
1316
from server import settings
1417

18+
app_urlpatterns = [
19+
*auth_urlpatterns,
20+
*product_urlpatterns,
21+
*category_urlpatterns,
22+
*banner_urlpatterns,
23+
*country_urlpatterns
24+
]
25+
1526
urlpatterns = [
1627
path('admin/', admin.site.urls),
28+
path('api/v1/', include(app_urlpatterns))
1729
]
1830

1931
urlpatterns += [
20-
*auth_urlpatterns,
21-
*product_urlpatterns,
22-
*category_urlpatterns,
2332
*swagger_urlpatterns,
24-
*banner_urlpatterns,
25-
*country_urlpatterns
33+
*jwt_urlpatterns
2634
] + debug_toolbar_urls()
2735

2836

server/urls/auth.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
from django.urls import path, include
2-
from rest_framework.routers import DefaultRouter
32
from rest_framework_simplejwt.views import TokenVerifyView
43

54
from server.views.auth_view import (
65
CustomTokenObtainPairView,
76
CustomTokenRefreshView,
87
RegisterViewSet
98
)
9+
from server.router import router
1010

11-
router = DefaultRouter()
1211
router.register(r"auth", RegisterViewSet, basename="auth")
1312

1413
auth_urlpatterns = [
15-
path('api/v1/drf-auth/', include('rest_framework.urls')),
16-
17-
path('api/v1/', include(router.urls)),
14+
path('drf-auth/', include('rest_framework.urls')),
15+
path('', include(router.urls)),
16+
]
1817

18+
jwt_urlpatterns = [
1919
path('api/token/', CustomTokenObtainPairView.as_view(), name='token_obtain_pair'),
2020
path('api/token/refresh/', CustomTokenRefreshView.as_view(), name='token_refresh'),
2121
path('api/token/verify/', TokenVerifyView.as_view(), name='token_verify'),
22-
2322
]

server/urls/banner.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@
33
include
44
)
55

6-
from rest_framework.routers import DefaultRouter
7-
86
from server.views.banner_view import BannerViewSet
7+
from server.router import router
98

10-
router = DefaultRouter()
119
router.register(r"banners", BannerViewSet, basename="banner")
1210

1311
banner_urlpatterns = [
14-
path("api/v1/", include(router.urls))
12+
path("", include(router.urls))
1513
]

server/urls/category.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
from django.urls import path, include
22

3-
from rest_framework.routers import DefaultRouter
4-
53
from server.views.category_view import CategoryViewSet
4+
from server.router import router
65

7-
router = DefaultRouter()
86
router.register(r"categories", CategoryViewSet, basename="categories")
97

108
category_urlpatterns = [
11-
path("api/v1/", include(router.urls))
9+
path("", include(router.urls))
1210
]

server/urls/country.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
from server.views.country_view import CountryView
33

44
country_urlpatterns = [
5-
path("api/v1/country/", CountryView.as_view()),
6-
path("api/v1/country/<str:name>/", CountryView.as_view()),
5+
path("country/", CountryView.as_view()),
6+
path("country/<str:name>/", CountryView.as_view()),
77
]

server/urls/product.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
from django.urls import path, include
22

3-
from rest_framework.routers import DefaultRouter
4-
53
from server.views.product_view import ProductViewSet
64
from server.views.search_view import SearchViewSet
5+
from server.router import router
76

8-
router = DefaultRouter()
97
router.register(r'search', SearchViewSet, basename='search')
108
router.register(r'products', ProductViewSet, basename='product')
119

1210
product_urlpatterns = [
13-
path("api/v1/", include(router.urls))
11+
path("", include(router.urls))
1412
]

server/views/search_view.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from server.models import PopularSearch
77
from server.serializers.search_serializers import PopularSearchSerializer
88

9+
910
class SearchViewSet(ViewSet):
1011
@action(detail=False, methods=["get"])
1112
def suggestions(self, request):

0 commit comments

Comments
 (0)