Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates api routes for camera plugin integrations #9209

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/components/CameraFeed/CameraFeedWithBedPresets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ interface Props {
export default function LocationFeedTile(props: Props) {
const [preset, setPreset] = useState<CameraPreset>();
const { operate, key } = useOperateCamera(props.asset.id);
rithviknishad marked this conversation as resolved.
Show resolved Hide resolved
const { data, loading } = useQuery(FeedRoutes.listAssetPresets, {
pathParams: { asset_id: props.asset.id },
query: { limit: 100 },
const { data, loading } = useQuery(FeedRoutes.positionPresets.list, {
query: { asset_external_id: props.asset.id, limit: 100 },
});

return (
Expand Down
39 changes: 20 additions & 19 deletions src/components/CameraFeed/ConfigureCamera.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,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 },
const cameraPresetsQuery = useQuery(FeedRoutes.positionPresets.list, {
query: {
assetbed_external_id: selectedAssetBed?.id ?? "",
limit: 50,
},
prefetch: !!selectedAssetBed?.id,
});

Expand Down Expand Up @@ -415,13 +417,18 @@ export default function ConfigureCamera(props: Props) {
/>
<Submit
onClick={async () => {
const { res } = await request(FeedRoutes.createPreset, {
pathParams: { assetbed_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;
}
Expand Down Expand Up @@ -519,12 +526,9 @@ export default function ConfigureCamera(props: Props) {
border
onClick={async () => {
const { res } = await request(
FeedRoutes.deletePreset,
FeedRoutes.positionPresets.delete,
{
pathParams: {
assetbed_id: selectedAssetBed.id,
id: preset.id,
},
pathParams: { id: preset.id },
},
);
if (!res?.ok) {
Expand All @@ -549,12 +553,9 @@ export default function ConfigureCamera(props: Props) {
label={t("save")}
onClick={async () => {
const { res } = await request(
FeedRoutes.updatePreset,
FeedRoutes.positionPresets.update,
{
pathParams: {
assetbed_id: selectedAssetBed.id,
id: preset.id,
},
pathParams: { id: preset.id },
body: {
name: presetName || undefined,
position: editPreset?.position,
Expand Down
54 changes: 23 additions & 31 deletions src/components/CameraFeed/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,36 +53,28 @@ export const FeedRoutes = {
TBody: Type<{ action: OperationAction }>(),
},

listAssetBedPresets: {
path: "/api/v1/assetbed/{assetbed_id}/camera_presets/",
method: "GET",
TRes: Type<PaginatedResponse<CameraPreset>>(),
},
listAssetPresets: {
path: "/api/v1/asset/{asset_id}/camera_presets/",
method: "GET",
TRes: Type<PaginatedResponse<CameraPreset>>(),
},
listBedPresets: {
path: "/api/v1/bed/{bed_id}/camera_presets/",
method: "GET",
TRes: Type<PaginatedResponse<CameraPreset>>(),
},
createPreset: {
path: "/api/v1/assetbed/{assetbed_id}/camera_presets/",
method: "POST",
TRes: Type<CameraPreset>(),
TBody: Type<WritableOnly<CameraPreset>>(),
},
updatePreset: {
path: "/api/v1/assetbed/{assetbed_id}/camera_presets/{id}/",
method: "PATCH",
TRes: Type<CameraPreset>(),
TBody: Type<Partial<WritableOnly<CameraPreset>>>(),
},
deletePreset: {
path: "/api/v1/assetbed/{assetbed_id}/camera_presets/{id}/",
method: "DELETE",
TRes: Type<CameraPreset>(),
positionPresets: {
list: {
path: "/api/camera/position-presets/",
method: "GET",
TRes: Type<PaginatedResponse<CameraPreset>>(),
},
create: {
path: "/api/camera/position-presets/",
method: "POST",
TRes: Type<CameraPreset>(),
TBody: Type<WritableOnly<CameraPreset>>(),
},
update: {
path: "/api/camera/position-presets/{id}/",
method: "PATCH",
TRes: Type<CameraPreset>(),
TBody: Type<Partial<WritableOnly<CameraPreset>>>(),
},
delete: {
path: "/api/camera/position-presets/{id}/",
method: "DELETE",
TRes: Type<CameraPreset>(),
},
},
} as const;
Original file line number Diff line number Diff line change
Expand Up @@ -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.positionPresets.list, {
query: { bed_external_id: bed?.id ?? "", limit: 100 },
prefetch: !!bed,
onResponse: ({ data }) => {
if (!data) {
Expand Down Expand Up @@ -113,11 +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: {
assetbed_id: preset.asset_bed.id,
id: preset.id,
},
const { data: updated } = await request(FeedRoutes.positionPresets.update, {
pathParams: { id: preset.id },
rithviknishad marked this conversation as resolved.
Show resolved Hide resolved
body: {
position,
},
Expand Down
Loading