Skip to content

Commit

Permalink
api: create v2 endpoints in favor of the v1 endpoints currently used …
Browse files Browse the repository at this point in the history
…by Anthias from the Settings and home page (#2142)
  • Loading branch information
nicomiguelino authored Nov 26, 2024
1 parent cb7abc7 commit 1897046
Show file tree
Hide file tree
Showing 9 changed files with 408 additions and 290 deletions.
5 changes: 4 additions & 1 deletion anthias_django/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@

SPECTACULAR_SETTINGS = {
'TITLE': 'Anthias API',
'VERSION': '1.2.0',
'VERSION': '2.0.0',
'PREPROCESSING_HOOKS': [
'api.api_docs_filter_spec.preprocessing_filter_spec'
],
}

# `django-dbbackup` settings
Expand Down
6 changes: 6 additions & 0 deletions api/api_docs_filter_spec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def preprocessing_filter_spec(endpoints):
filtered = []
for (path, path_regex, method, callback) in endpoints:
if path.startswith("/api/v2"):
filtered.append((path, path_regex, method, callback))
return filtered
4 changes: 2 additions & 2 deletions api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def test_device_info(
self.assertEqual(data['viewlog'], 'Not yet implemented')

@mock.patch(
'api.views.v1.reboot_anthias.apply_async',
'api.views.mixins.reboot_anthias.apply_async',
side_effect=(lambda: None)
)
def test_reboot(self, reboot_anthias_mock):
Expand All @@ -303,7 +303,7 @@ def test_reboot(self, reboot_anthias_mock):
self.assertEqual(reboot_anthias_mock.call_count, 1)

@mock.patch(
'api.views.v1.shutdown_anthias.apply_async',
'api.views.mixins.shutdown_anthias.apply_async',
side_effect=(lambda: None)
)
def test_shutdown(self, shutdown_anthias_mock):
Expand Down
64 changes: 46 additions & 18 deletions api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
from .views.v1 import (
AssetViewV1,
AssetListViewV1,
AssetContentView,
FileAssetView,
PlaylistOrderView,
BackupView,
RecoverView,
AssetsControlView,
AssetContentViewV1,
FileAssetViewV1,
PlaylistOrderViewV1,
BackupViewV1,
RecoverViewV1,
AssetsControlViewV1,
InfoView,
RebootView,
ShutdownView,
ViewerCurrentAssetView
RebootViewV1,
ShutdownViewV1,
ViewerCurrentAssetViewV1
)
from .views.v1_1 import (
AssetListViewV1_1,
Expand All @@ -22,8 +22,16 @@
AssetViewV1_2
)
from .views.v2 import (
AssetContentViewV2,
AssetsControlViewV2,
AssetListViewV2,
AssetViewV2,
BackupViewV2,
PlaylistOrderViewV2,
RecoverViewV2,
RebootViewV2,
ShutdownViewV2,
FileAssetViewV2
)

app_name = 'api'
Expand All @@ -33,12 +41,12 @@
path('v1/assets', AssetListViewV1.as_view(), name='asset_list_v1'),
path(
'v1/assets/order',
PlaylistOrderView.as_view(),
PlaylistOrderViewV1.as_view(),
name='playlist_order_v1',
),
path(
'v1/assets/control/<str:command>',
AssetsControlView.as_view(),
AssetsControlViewV1.as_view(),
name='assets_control_v1',
),
path(
Expand All @@ -48,18 +56,18 @@
),
path(
'v1/assets/<str:asset_id>/content',
AssetContentView.as_view(),
AssetContentViewV1.as_view(),
name='asset_content_v1',
),
path('v1/file_asset', FileAssetView.as_view(), name='file_asset_v1'),
path('v1/backup', BackupView.as_view(), name='backup_v1'),
path('v1/recover', RecoverView.as_view(), name='recover_v1'),
path('v1/file_asset', FileAssetViewV1.as_view(), name='file_asset_v1'),
path('v1/backup', BackupViewV1.as_view(), name='backup_v1'),
path('v1/recover', RecoverViewV1.as_view(), name='recover_v1'),
path('v1/info', InfoView.as_view(), name='info_v1'),
path('v1/reboot', RebootView.as_view(), name='reboot_v1'),
path('v1/shutdown', ShutdownView.as_view(), name='shutdown_v1'),
path('v1/reboot', RebootViewV1.as_view(), name='reboot_v1'),
path('v1/shutdown', ShutdownViewV1.as_view(), name='shutdown_v1'),
path(
'v1/viewer_current_asset',
ViewerCurrentAssetView.as_view(),
ViewerCurrentAssetViewV1.as_view(),
name='viewer_current_asset_v1',
),

Expand All @@ -81,9 +89,29 @@

# v2 endpoints
path('v2/assets', AssetListViewV2.as_view(), name='asset_list_v2'),
path(
'v2/assets/order',
PlaylistOrderViewV2.as_view(),
name='playlist_order_v2',
),
path(
'v2/assets/control/<str:command>',
AssetsControlViewV2.as_view(),
name='assets_control_v2',
),
path(
'v2/assets/<str:asset_id>',
AssetViewV2.as_view(),
name='asset_detail_v2'
),
path('v2/backup', BackupViewV2.as_view(), name='backup_v2'),
path('v2/recover', RecoverViewV2.as_view(), name='recover_v2'),
path('v2/reboot', RebootViewV2.as_view(), name='reboot_v2'),
path('v2/shutdown', ShutdownViewV2.as_view(), name='shutdown_v2'),
path('v2/file_asset', FileAssetViewV2.as_view(), name='file_asset_v2'),
path(
'v2/assets/<str:asset_id>/content',
AssetContentViewV2.as_view(),
name='asset_content_v2',
),
]
Loading

0 comments on commit 1897046

Please sign in to comment.