pre updating version control
This commit is contained in:
@@ -6,7 +6,9 @@ export const API_BASE_URL =
|
||||
export const API_ENDPOINTS = {
|
||||
geometries: `${API_BASE_URL}/geometries`,
|
||||
geometriesBatch: `${API_BASE_URL}/geometries/batch`,
|
||||
geometriesBatchCombined: `${API_BASE_URL}/geometries/batch/combined`,
|
||||
entities: `${API_BASE_URL}/entities`,
|
||||
entitiesBatch: `${API_BASE_URL}/entities/batch`,
|
||||
vectorTiles: `${API_BASE_URL}/tiles/{z}/{x}/{y}`,
|
||||
rasterTiles: `${API_BASE_URL}/raster-tiles/{z}/{x}/{y}`,
|
||||
vectorTilesMetadata: `${API_BASE_URL}/tiles/metadata/info`,
|
||||
|
||||
@@ -21,6 +21,43 @@ export type CreateEntityPayload = {
|
||||
status?: number | null;
|
||||
};
|
||||
|
||||
export type EntityBatchCreateChange =
|
||||
| ({
|
||||
action: "create";
|
||||
entity: CreateEntityPayload & { id?: string };
|
||||
})
|
||||
| ({
|
||||
action: "create";
|
||||
id?: string;
|
||||
} & CreateEntityPayload);
|
||||
|
||||
export type EntityBatchUpdateChange =
|
||||
| ({
|
||||
action: "update";
|
||||
id: string;
|
||||
entity: Partial<CreateEntityPayload> & { id?: string };
|
||||
})
|
||||
| ({
|
||||
action: "update";
|
||||
id: string;
|
||||
} & Partial<CreateEntityPayload>);
|
||||
|
||||
export type EntityBatchDeleteChange = {
|
||||
action: "delete";
|
||||
id: string;
|
||||
};
|
||||
|
||||
export type EntityBatchChange =
|
||||
| EntityBatchCreateChange
|
||||
| EntityBatchUpdateChange
|
||||
| EntityBatchDeleteChange;
|
||||
|
||||
export type EntityBatchSaveResponse = {
|
||||
success: boolean;
|
||||
applied: number;
|
||||
created_entity_ids: string[];
|
||||
};
|
||||
|
||||
export async function fetchEntities(query?: { q?: string }): Promise<Entity[]> {
|
||||
const params = new URLSearchParams();
|
||||
if (query?.q) {
|
||||
@@ -61,3 +98,11 @@ export async function updateEntity(id: string, payload: CreateEntityPayload): Pr
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
}
|
||||
|
||||
export async function saveEntityBatchChanges(changes: EntityBatchChange[]): Promise<EntityBatchSaveResponse> {
|
||||
return requestJson<EntityBatchSaveResponse>(API_ENDPOINTS.entitiesBatch, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ changes }),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { API_ENDPOINTS } from "@/api/config";
|
||||
import { EntityBatchChange } from "@/api/entities";
|
||||
import { requestJson } from "@/api/http";
|
||||
import { Change, FeatureCollection, Geometry } from "@/lib/useEditorState";
|
||||
|
||||
@@ -40,6 +41,14 @@ export type BatchSaveResponse = {
|
||||
applied: number;
|
||||
};
|
||||
|
||||
export type CombinedBatchSaveResponse = {
|
||||
success: boolean;
|
||||
applied: number;
|
||||
entity_applied: number;
|
||||
geometry_applied: number;
|
||||
created_entity_ids: string[];
|
||||
};
|
||||
|
||||
function buildBBoxQueryString(params: GeometriesBBoxQuery): string {
|
||||
const query = new URLSearchParams({
|
||||
minLng: String(params.minLng),
|
||||
@@ -72,6 +81,20 @@ export async function saveGeometryBatchChanges(changes: Change[]): Promise<Batch
|
||||
});
|
||||
}
|
||||
|
||||
export async function saveCombinedGeometryEntityBatchChanges(
|
||||
entityChanges: EntityBatchChange[],
|
||||
geometryChanges: Change[]
|
||||
): Promise<CombinedBatchSaveResponse> {
|
||||
return requestJson<CombinedBatchSaveResponse>(API_ENDPOINTS.geometriesBatchCombined, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
entity_changes: entityChanges,
|
||||
geometry_changes: geometryChanges,
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
export async function createGeometry(payload: GeometryCreatePayload): Promise<GeometryCreateResponse> {
|
||||
return requestJson<GeometryCreateResponse>(API_ENDPOINTS.geometries, {
|
||||
method: "POST",
|
||||
|
||||
Reference in New Issue
Block a user