reduce api | version control

This commit is contained in:
taDuc
2026-04-19 00:13:22 +07:00
parent c88a6497f7
commit bc98830871
9 changed files with 1141 additions and 449 deletions

View File

@@ -1,7 +1,6 @@
import { API_ENDPOINTS } from "@/api/config";
import { EntityBatchChange } from "@/api/entities";
import { requestJson } from "@/api/http";
import { Change, FeatureCollection, Geometry } from "@/lib/useEditorState";
import { FeatureCollection } from "@/lib/useEditorState";
export type GeometriesBBoxQuery = {
minLng: number;
@@ -12,43 +11,6 @@ export type GeometriesBBoxQuery = {
entity_id?: string;
};
export type GeometryCreatePayload = {
geometry: Geometry;
type?: string | null;
time_start?: number | null;
time_end?: number | null;
binding?: string[];
entity_id?: string | null;
entity_ids?: string[];
};
export type GeometryUpdatePayload = {
geometry: Geometry;
type?: string | null;
time_start?: number | null;
time_end?: number | null;
binding?: string[];
entity_id?: string | null;
entity_ids?: string[];
};
export type GeometryCreateResponse = {
id: string;
};
export type BatchSaveResponse = {
success: boolean;
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,47 +34,3 @@ export async function fetchGeometriesByBBox(params: GeometriesBBoxQuery): Promis
const url = `${API_ENDPOINTS.geometries}?${buildBBoxQueryString(params)}`;
return requestJson<FeatureCollection>(url);
}
export async function saveGeometryBatchChanges(changes: Change[]): Promise<BatchSaveResponse> {
return requestJson<BatchSaveResponse>(API_ENDPOINTS.geometriesBatch, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ changes }),
});
}
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",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload),
});
}
export async function updateGeometry(id: string | number, payload: GeometryUpdatePayload): Promise<{ success: boolean }> {
return requestJson<{ success: boolean }>(`${API_ENDPOINTS.geometries}/${id}`, {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload),
});
}
export async function deleteGeometry(id: string | number): Promise<{ success: boolean }> {
return requestJson<{ success: boolean }>(`${API_ENDPOINTS.geometries}/${id}`, {
method: "DELETE",
});
}