From f41bfff798cb476cb1bac2d5d191defb3742dac0 Mon Sep 17 00:00:00 2001 From: Junwei Zhao Date: Mon, 4 Nov 2024 22:04:41 +1100 Subject: [PATCH] Fix api endpoints routes --- links/api_urls.py | 10 ++++++++++ links/serializers.py | 6 ++++-- links/urls.py | 12 +----------- 3 files changed, 15 insertions(+), 13 deletions(-) create mode 100644 links/api_urls.py diff --git a/links/api_urls.py b/links/api_urls.py new file mode 100644 index 0000000..1f3d613 --- /dev/null +++ b/links/api_urls.py @@ -0,0 +1,10 @@ +from django.urls import path, include +from rest_framework.routers import DefaultRouter +from . import page_views + +router = DefaultRouter(trailing_slash=False) +router.register('pages', page_views.PageViewSet, basename='api-pages') + +urlpatterns = [ + path('', include(router.urls)), +] diff --git a/links/serializers.py b/links/serializers.py index b6fc78a..14d990d 100644 --- a/links/serializers.py +++ b/links/serializers.py @@ -4,5 +4,7 @@ from .models import Page class PageSerializer(serializers.ModelSerializer): class Meta: model = Page - fields = ['id', 'url', 'title', 'summary', 'content', 'created_at', 'updated_at'] - read_only_fields = ['created_at', 'updated_at'] + fields = ['id', 'url', 'title', 'summary', 'content', 'screenshot_path', + 'process_status', 'created_at', 'updated_at'] + read_only_fields = ['id', 'screenshot_path', 'process_status', + 'created_at', 'updated_at'] diff --git a/links/urls.py b/links/urls.py index a2ac91b..01d12ad 100644 --- a/links/urls.py +++ b/links/urls.py @@ -1,12 +1,7 @@ from django.urls import path, include -from rest_framework.routers import DefaultRouter -from django.urls import re_path from . import views from . import page_views -router = DefaultRouter(trailing_slash=False) -router.register(r'pages', views.PageViewSet, basename='api-page') - urlpatterns = [ # Regular UI URLs path('', views.LinkListView.as_view(), name='link_list'), @@ -32,13 +27,8 @@ urlpatterns = [ path('fetch-page-info/', page_views.fetch_page_info, name='fetch-page-info'), path('ui/screenshots/', page_views.ScreenshotGalleryView.as_view(), name='screenshot-gallery'), - # API URLs - place before catch-all alias routes - path('api/', include(router.urls)), - - # Aliases - these should always be last as they're catch-all routes + # Aliases - these should always be last path('/', views.redirect_to_original, name='redirect_to_original'), path('//', views.redirect_to_original, name='redirect_to_original_with_param'), path('alias//', views.LinkDetailView.as_view(), name='link_detail_by_alias'), - - ]