From 6321bda648f1e78b114d4a4d284b31c13483f74b Mon Sep 17 00:00:00 2001 From: prafful Date: Tue, 26 Nov 2024 00:51:08 +0530 Subject: [PATCH 1/2] update api routes for the new camera plugins --- .../CameraFeed/CameraFeedWithBedPresets.tsx | 5 ++--- src/components/CameraFeed/ConfigureCamera.tsx | 17 ++++++++++++----- src/components/CameraFeed/routes.ts | 17 ++++++----------- .../ConsultationDetails/ConsultationFeedTab.tsx | 9 +++++---- 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/components/CameraFeed/CameraFeedWithBedPresets.tsx b/src/components/CameraFeed/CameraFeedWithBedPresets.tsx index be43fe3f810..84c28faffee 100644 --- a/src/components/CameraFeed/CameraFeedWithBedPresets.tsx +++ b/src/components/CameraFeed/CameraFeedWithBedPresets.tsx @@ -16,9 +16,8 @@ interface Props { export default function LocationFeedTile(props: Props) { const [preset, setPreset] = useState(); const { operate, key } = useOperateCamera(props.asset.id); - const { data, loading } = useQuery(FeedRoutes.listAssetPresets, { - pathParams: { asset_id: props.asset.id }, - query: { limit: 100 }, + const { data, loading } = useQuery(FeedRoutes.listCameraPresets, { + query: { asset_external_id: props.asset.id, limit: 100 }, }); return ( diff --git a/src/components/CameraFeed/ConfigureCamera.tsx b/src/components/CameraFeed/ConfigureCamera.tsx index f969ed2b0ca..0ed56037a86 100644 --- a/src/components/CameraFeed/ConfigureCamera.tsx +++ b/src/components/CameraFeed/ConfigureCamera.tsx @@ -101,8 +101,11 @@ export default function ConfigureCamera(props: Props) { const selectedUnlinkedBed = unlinkedBeds?.find((bed) => bed.id === query.bed); const cameraPresetsQuery = useQuery(FeedRoutes.listAssetBedPresets, { - pathParams: { assetbed_id: selectedAssetBed?.id ?? "" }, - query: { position: true, limit: 50 }, + query: { + assetbed_external_id: selectedAssetBed?.id ?? "", + position: true, + limit: 50, + }, prefetch: !!selectedAssetBed?.id, }); @@ -416,7 +419,7 @@ export default function ConfigureCamera(props: Props) { { const { res } = await request(FeedRoutes.createPreset, { - pathParams: { assetbed_id: selectedAssetBed.id }, + query: { assetbed_external_id: selectedAssetBed.id }, body: { name: presetName, position: createPreset!, @@ -522,9 +525,11 @@ export default function ConfigureCamera(props: Props) { FeedRoutes.deletePreset, { pathParams: { - assetbed_id: selectedAssetBed.id, id: preset.id, }, + query: { + assetbed_external_id: selectedAssetBed.id, + }, }, ); if (!res?.ok) { @@ -552,9 +557,11 @@ export default function ConfigureCamera(props: Props) { FeedRoutes.updatePreset, { pathParams: { - assetbed_id: selectedAssetBed.id, id: preset.id, }, + query: { + assetbed_external_id: selectedAssetBed.id, + }, body: { name: presetName || undefined, position: editPreset?.position, diff --git a/src/components/CameraFeed/routes.ts b/src/components/CameraFeed/routes.ts index e5a0ef72491..028b39784af 100644 --- a/src/components/CameraFeed/routes.ts +++ b/src/components/CameraFeed/routes.ts @@ -54,34 +54,29 @@ export const FeedRoutes = { }, listAssetBedPresets: { - path: "/api/v1/assetbed/{assetbed_id}/camera_presets/", + path: "/api/camera/assetbed/position_presets/", method: "GET", TRes: Type>(), }, - listAssetPresets: { - path: "/api/v1/asset/{asset_id}/camera_presets/", - method: "GET", - TRes: Type>(), - }, - listBedPresets: { - path: "/api/v1/bed/{bed_id}/camera_presets/", + listCameraPresets: { + path: "/api/camera/position_presets/", method: "GET", TRes: Type>(), }, createPreset: { - path: "/api/v1/assetbed/{assetbed_id}/camera_presets/", + path: "/api/camera/assetbed/position_presets/", method: "POST", TRes: Type(), TBody: Type>(), }, updatePreset: { - path: "/api/v1/assetbed/{assetbed_id}/camera_presets/{id}/", + path: "/api/camera/assetbed/position_presets/{id}/", method: "PATCH", TRes: Type(), TBody: Type>>(), }, deletePreset: { - path: "/api/v1/assetbed/{assetbed_id}/camera_presets/{id}/", + path: "/api/camera/assetbed/position_presets/{id}/", method: "DELETE", TRes: Type(), }, diff --git a/src/components/Facility/ConsultationDetails/ConsultationFeedTab.tsx b/src/components/Facility/ConsultationDetails/ConsultationFeedTab.tsx index 21c6f304cb5..936b9ee601a 100644 --- a/src/components/Facility/ConsultationDetails/ConsultationFeedTab.tsx +++ b/src/components/Facility/ConsultationDetails/ConsultationFeedTab.tsx @@ -58,9 +58,8 @@ export const ConsultationFeedTab = (props: ConsultationTabProps) => { const { key, operate } = useOperateCamera(asset?.id ?? ""); - const presetsQuery = useQuery(FeedRoutes.listBedPresets, { - pathParams: { bed_id: bed?.id ?? "" }, - query: { limit: 100 }, + const presetsQuery = useQuery(FeedRoutes.listCameraPresets, { + query: { bed_external_id: bed?.id ?? "", limit: 100 }, prefetch: !!bed, onResponse: ({ data }) => { if (!data) { @@ -115,9 +114,11 @@ export const ConsultationFeedTab = (props: ConsultationTabProps) => { const { position } = (data as { result: { position: PTZPayload } }).result; const { data: updated } = await request(FeedRoutes.updatePreset, { pathParams: { - assetbed_id: preset.asset_bed.id, id: preset.id, }, + query: { + assetbed_external_id: preset.asset_bed.id, + }, body: { position, }, From 70e6f626eb595ce75956b1c484a5e005c5d1442a Mon Sep 17 00:00:00 2001 From: rithviknishad Date: Tue, 26 Nov 2024 17:00:59 +0530 Subject: [PATCH 2/2] Changes as per https://github.com/ohcnetwork/care_camera_asset/pull/2 --- .../CameraFeed/CameraFeedWithBedPresets.tsx | 2 +- src/components/CameraFeed/ConfigureCamera.tsx | 38 ++++++-------- src/components/CameraFeed/routes.ts | 49 +++++++++---------- .../ConsultationFeedTab.tsx | 11 ++--- 4 files changed, 43 insertions(+), 57 deletions(-) diff --git a/src/components/CameraFeed/CameraFeedWithBedPresets.tsx b/src/components/CameraFeed/CameraFeedWithBedPresets.tsx index 84c28faffee..148b203fe82 100644 --- a/src/components/CameraFeed/CameraFeedWithBedPresets.tsx +++ b/src/components/CameraFeed/CameraFeedWithBedPresets.tsx @@ -16,7 +16,7 @@ interface Props { export default function LocationFeedTile(props: Props) { const [preset, setPreset] = useState(); const { operate, key } = useOperateCamera(props.asset.id); - const { data, loading } = useQuery(FeedRoutes.listCameraPresets, { + const { data, loading } = useQuery(FeedRoutes.positionPresets.list, { query: { asset_external_id: props.asset.id, limit: 100 }, }); diff --git a/src/components/CameraFeed/ConfigureCamera.tsx b/src/components/CameraFeed/ConfigureCamera.tsx index 0ed56037a86..2955e3b6ba9 100644 --- a/src/components/CameraFeed/ConfigureCamera.tsx +++ b/src/components/CameraFeed/ConfigureCamera.tsx @@ -100,10 +100,9 @@ export default function ConfigureCamera(props: Props) { ); const selectedUnlinkedBed = unlinkedBeds?.find((bed) => bed.id === query.bed); - const cameraPresetsQuery = useQuery(FeedRoutes.listAssetBedPresets, { + const cameraPresetsQuery = useQuery(FeedRoutes.positionPresets.list, { query: { assetbed_external_id: selectedAssetBed?.id ?? "", - position: true, limit: 50, }, prefetch: !!selectedAssetBed?.id, @@ -418,13 +417,18 @@ export default function ConfigureCamera(props: Props) { /> { - const { res } = await request(FeedRoutes.createPreset, { - query: { assetbed_external_id: selectedAssetBed.id }, - body: { - name: presetName, - position: createPreset!, + const { res } = await request( + FeedRoutes.positionPresets.create, + { + query: { + assetbed_external_id: selectedAssetBed.id, + }, + body: { + name: presetName, + position: createPreset!, + }, }, - }); + ); if (!res?.ok) { return; } @@ -522,14 +526,9 @@ export default function ConfigureCamera(props: Props) { border onClick={async () => { const { res } = await request( - FeedRoutes.deletePreset, + FeedRoutes.positionPresets.delete, { - pathParams: { - id: preset.id, - }, - query: { - assetbed_external_id: selectedAssetBed.id, - }, + pathParams: { id: preset.id }, }, ); if (!res?.ok) { @@ -554,14 +553,9 @@ export default function ConfigureCamera(props: Props) { label={t("save")} onClick={async () => { const { res } = await request( - FeedRoutes.updatePreset, + FeedRoutes.positionPresets.update, { - pathParams: { - id: preset.id, - }, - query: { - assetbed_external_id: selectedAssetBed.id, - }, + pathParams: { id: preset.id }, body: { name: presetName || undefined, position: editPreset?.position, diff --git a/src/components/CameraFeed/routes.ts b/src/components/CameraFeed/routes.ts index 028b39784af..e7195c51cd2 100644 --- a/src/components/CameraFeed/routes.ts +++ b/src/components/CameraFeed/routes.ts @@ -53,31 +53,28 @@ export const FeedRoutes = { TBody: Type<{ action: OperationAction }>(), }, - listAssetBedPresets: { - path: "/api/camera/assetbed/position_presets/", - method: "GET", - TRes: Type>(), - }, - listCameraPresets: { - path: "/api/camera/position_presets/", - method: "GET", - TRes: Type>(), - }, - createPreset: { - path: "/api/camera/assetbed/position_presets/", - method: "POST", - TRes: Type(), - TBody: Type>(), - }, - updatePreset: { - path: "/api/camera/assetbed/position_presets/{id}/", - method: "PATCH", - TRes: Type(), - TBody: Type>>(), - }, - deletePreset: { - path: "/api/camera/assetbed/position_presets/{id}/", - method: "DELETE", - TRes: Type(), + positionPresets: { + list: { + path: "/api/camera/position-presets/", + method: "GET", + TRes: Type>(), + }, + create: { + path: "/api/camera/position-presets/", + method: "POST", + TRes: Type(), + TBody: Type>(), + }, + update: { + path: "/api/camera/position-presets/{id}/", + method: "PATCH", + TRes: Type(), + TBody: Type>>(), + }, + delete: { + path: "/api/camera/position-presets/{id}/", + method: "DELETE", + TRes: Type(), + }, }, } as const; diff --git a/src/components/Facility/ConsultationDetails/ConsultationFeedTab.tsx b/src/components/Facility/ConsultationDetails/ConsultationFeedTab.tsx index 936b9ee601a..05603db75ae 100644 --- a/src/components/Facility/ConsultationDetails/ConsultationFeedTab.tsx +++ b/src/components/Facility/ConsultationDetails/ConsultationFeedTab.tsx @@ -58,7 +58,7 @@ export const ConsultationFeedTab = (props: ConsultationTabProps) => { const { key, operate } = useOperateCamera(asset?.id ?? ""); - const presetsQuery = useQuery(FeedRoutes.listCameraPresets, { + const presetsQuery = useQuery(FeedRoutes.positionPresets.list, { query: { bed_external_id: bed?.id ?? "", limit: 100 }, prefetch: !!bed, onResponse: ({ data }) => { @@ -112,13 +112,8 @@ export const ConsultationFeedTab = (props: ConsultationTabProps) => { const { data } = await operate({ type: "get_status" }); const { position } = (data as { result: { position: PTZPayload } }).result; - const { data: updated } = await request(FeedRoutes.updatePreset, { - pathParams: { - id: preset.id, - }, - query: { - assetbed_external_id: preset.asset_bed.id, - }, + const { data: updated } = await request(FeedRoutes.positionPresets.update, { + pathParams: { id: preset.id }, body: { position, },